/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU64Decoder, getU64Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, SolanaError, transformEncoder, type AccountMeta, type AccountSignerMeta, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type Instruction, type InstructionWithAccounts, type InstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, } from '@solana/kit'; import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, type ResolvedInstructionAccount, } from '@solana/program-client-core'; import { SAGE_PROGRAM_ADDRESS } from '../programs'; export const TRADE_ENCOUNTER_DISCRIMINATOR = new Uint8Array([ 55, 127, 211, 101, 20, 130, 101, 140, ]); export function getTradeEncounterDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode( TRADE_ENCOUNTER_DISCRIMINATOR, ); } export type TradeEncounterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountProfileSigner extends string | AccountMeta = string, TAccountProfileProfile extends string | AccountMeta = string, TAccountProfileCertificate extends string | AccountMeta = string, TAccountProfileProgram extends string | AccountMeta = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u', TAccountCharacter extends string | AccountMeta = string, TAccountGame extends string | AccountMeta = string, TAccountFleet extends string | AccountMeta = string, TAccountEncounterMarket extends string | AccountMeta = string, TAccountTreasury extends string | AccountMeta = string, TAccountSystemProgram extends string | AccountMeta = '11111111111111111111111111111111', TAccountFactionStanding extends string | AccountMeta = string, TAccountFactionConfig extends string | AccountMeta = string, TAccountFactionEpochMeter extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ TAccountProfileSigner extends string ? ReadonlySignerAccount & AccountSignerMeta : TAccountProfileSigner, TAccountProfileProfile extends string ? WritableAccount : TAccountProfileProfile, TAccountProfileCertificate extends string ? ReadonlyAccount : TAccountProfileCertificate, TAccountProfileProgram extends string ? ReadonlyAccount : TAccountProfileProgram, TAccountCharacter extends string ? WritableAccount : TAccountCharacter, TAccountGame extends string ? ReadonlyAccount : TAccountGame, TAccountFleet extends string ? WritableAccount : TAccountFleet, TAccountEncounterMarket extends string ? WritableAccount : TAccountEncounterMarket, TAccountTreasury extends string ? WritableAccount : TAccountTreasury, TAccountSystemProgram extends string ? ReadonlyAccount : TAccountSystemProgram, TAccountFactionStanding extends string ? WritableAccount : TAccountFactionStanding, TAccountFactionConfig extends string ? ReadonlyAccount : TAccountFactionConfig, TAccountFactionEpochMeter extends string ? WritableAccount : TAccountFactionEpochMeter, ...TRemainingAccounts, ] >; export type TradeEncounterInstructionData = { discriminator: ReadonlyUint8Array; /** Index into the signer profile's key set (proves SCAN authority over the character/fleet). */ keyIndex: number; /** Which `LiveOffer` of the market to fill. */ offerIndex: number; /** Requested units. Bounded by the offer's remaining qty, then capped by stock (buy) or holdings (sell). */ quantity: bigint; /** `true` = player buys from the NPC (Ask leg); `false` = player sells to the NPC (Bid/faucet leg). */ playerBuys: boolean; }; export type TradeEncounterInstructionDataArgs = { /** Index into the signer profile's key set (proves SCAN authority over the character/fleet). */ keyIndex: number; /** Which `LiveOffer` of the market to fill. */ offerIndex: number; /** Requested units. Bounded by the offer's remaining qty, then capped by stock (buy) or holdings (sell). */ quantity: number | bigint; /** `true` = player buys from the NPC (Ask leg); `false` = player sells to the NPC (Bid/faucet leg). */ playerBuys: boolean; }; export function getTradeEncounterInstructionDataEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['keyIndex', getU16Encoder()], ['offerIndex', getU16Encoder()], ['quantity', getU64Encoder()], ['playerBuys', getBooleanEncoder()], ]), (value) => ({ ...value, discriminator: TRADE_ENCOUNTER_DISCRIMINATOR }), ); } export function getTradeEncounterInstructionDataDecoder(): FixedSizeDecoder { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['keyIndex', getU16Decoder()], ['offerIndex', getU16Decoder()], ['quantity', getU64Decoder()], ['playerBuys', getBooleanDecoder()], ]); } export function getTradeEncounterInstructionDataCodec(): FixedSizeCodec< TradeEncounterInstructionDataArgs, TradeEncounterInstructionData > { return combineCodec( getTradeEncounterInstructionDataEncoder(), getTradeEncounterInstructionDataDecoder(), ); } export type TradeEncounterAsyncInput< TAccountProfileSigner extends string = string, TAccountProfileProfile extends string = string, TAccountProfileCertificate extends string = string, TAccountProfileProgram extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountFleet extends string = string, TAccountEncounterMarket extends string = string, TAccountTreasury extends string = string, TAccountSystemProgram extends string = string, TAccountFactionStanding extends string = string, TAccountFactionConfig extends string = string, TAccountFactionEpochMeter extends string = string, > = { profileSigner: TransactionSigner; profileProfile: Address; profileCertificate?: Address; profileProgram?: Address; character?: Address; game: Address; /** The trading fleet — crew normalized at validation; cargo is delivered to / taken from its hold. */ fleet: Address; /** The player's open market (game-scoped; owner re-checked in the handler). Offer qtys decrement here. */ encounterMarket: Address; /** The treasury this market settles against (bound match re-checked in the handler). Value moves here. */ treasury: Address; systemProgram?: Address; /** The signer's `(game, profile, faction)` standing PDA (created via `InitFactionStanding`); credited here. */ factionStanding?: Address; /** Per-game reputation dials (`[FactionConfig, game]`): supplies `standing_bps` + the decay/DR/cap. */ factionConfig?: Address; /** Per-faction aggregate emission meter (`[FactionEpochMeter, game, faction]`): the anti-sybil cap. */ factionEpochMeter?: Address; keyIndex: TradeEncounterInstructionDataArgs['keyIndex']; offerIndex: TradeEncounterInstructionDataArgs['offerIndex']; quantity: TradeEncounterInstructionDataArgs['quantity']; playerBuys: TradeEncounterInstructionDataArgs['playerBuys']; }; export async function getTradeEncounterInstructionAsync< TAccountProfileSigner extends string, TAccountProfileProfile extends string, TAccountProfileCertificate extends string, TAccountProfileProgram extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountFleet extends string, TAccountEncounterMarket extends string, TAccountTreasury extends string, TAccountSystemProgram extends string, TAccountFactionStanding extends string, TAccountFactionConfig extends string, TAccountFactionEpochMeter extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: TradeEncounterAsyncInput< TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter >, config?: { programAddress?: TProgramAddress }, ): Promise< TradeEncounterInstruction< TProgramAddress, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter > > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileSigner: { value: input.profileSigner ?? null, isWritable: false }, profileProfile: { value: input.profileProfile ?? null, isWritable: true }, profileCertificate: { value: input.profileCertificate ?? null, isWritable: false, }, profileProgram: { value: input.profileProgram ?? null, isWritable: false }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, fleet: { value: input.fleet ?? null, isWritable: true }, encounterMarket: { value: input.encounterMarket ?? null, isWritable: true }, treasury: { value: input.treasury ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, factionStanding: { value: input.factionStanding ?? null, isWritable: true }, factionConfig: { value: input.factionConfig ?? null, isWritable: false }, factionEpochMeter: { value: input.factionEpochMeter ?? null, isWritable: true, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileProgram.value) { accounts.profileProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } if (!accounts.character.value) { accounts.character.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode( new Uint8Array([67, 104, 97, 114, 97, 99, 116, 101, 114]), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount( 'profileProfile', accounts.profileProfile.value, ), ), getAddressEncoder().encode( getAddressFromResolvedInstructionAccount('game', accounts.game.value), ), ], }); } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('profileSigner', accounts.profileSigner), getAccountMeta('profileProfile', accounts.profileProfile), getAccountMeta('profileCertificate', accounts.profileCertificate), getAccountMeta('profileProgram', accounts.profileProgram), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('fleet', accounts.fleet), getAccountMeta('encounterMarket', accounts.encounterMarket), getAccountMeta('treasury', accounts.treasury), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta('factionStanding', accounts.factionStanding), getAccountMeta('factionConfig', accounts.factionConfig), getAccountMeta('factionEpochMeter', accounts.factionEpochMeter), ], data: getTradeEncounterInstructionDataEncoder().encode( args as TradeEncounterInstructionDataArgs, ), programAddress, } as TradeEncounterInstruction< TProgramAddress, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter >); } export type TradeEncounterInput< TAccountProfileSigner extends string = string, TAccountProfileProfile extends string = string, TAccountProfileCertificate extends string = string, TAccountProfileProgram extends string = string, TAccountCharacter extends string = string, TAccountGame extends string = string, TAccountFleet extends string = string, TAccountEncounterMarket extends string = string, TAccountTreasury extends string = string, TAccountSystemProgram extends string = string, TAccountFactionStanding extends string = string, TAccountFactionConfig extends string = string, TAccountFactionEpochMeter extends string = string, > = { profileSigner: TransactionSigner; profileProfile: Address; profileCertificate?: Address; profileProgram?: Address; character: Address; game: Address; /** The trading fleet — crew normalized at validation; cargo is delivered to / taken from its hold. */ fleet: Address; /** The player's open market (game-scoped; owner re-checked in the handler). Offer qtys decrement here. */ encounterMarket: Address; /** The treasury this market settles against (bound match re-checked in the handler). Value moves here. */ treasury: Address; systemProgram?: Address; /** The signer's `(game, profile, faction)` standing PDA (created via `InitFactionStanding`); credited here. */ factionStanding?: Address; /** Per-game reputation dials (`[FactionConfig, game]`): supplies `standing_bps` + the decay/DR/cap. */ factionConfig?: Address; /** Per-faction aggregate emission meter (`[FactionEpochMeter, game, faction]`): the anti-sybil cap. */ factionEpochMeter?: Address; keyIndex: TradeEncounterInstructionDataArgs['keyIndex']; offerIndex: TradeEncounterInstructionDataArgs['offerIndex']; quantity: TradeEncounterInstructionDataArgs['quantity']; playerBuys: TradeEncounterInstructionDataArgs['playerBuys']; }; export function getTradeEncounterInstruction< TAccountProfileSigner extends string, TAccountProfileProfile extends string, TAccountProfileCertificate extends string, TAccountProfileProgram extends string, TAccountCharacter extends string, TAccountGame extends string, TAccountFleet extends string, TAccountEncounterMarket extends string, TAccountTreasury extends string, TAccountSystemProgram extends string, TAccountFactionStanding extends string, TAccountFactionConfig extends string, TAccountFactionEpochMeter extends string, TProgramAddress extends Address = typeof SAGE_PROGRAM_ADDRESS, >( input: TradeEncounterInput< TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter >, config?: { programAddress?: TProgramAddress }, ): TradeEncounterInstruction< TProgramAddress, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter > { // Program address. const programAddress = config?.programAddress ?? SAGE_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { profileSigner: { value: input.profileSigner ?? null, isWritable: false }, profileProfile: { value: input.profileProfile ?? null, isWritable: true }, profileCertificate: { value: input.profileCertificate ?? null, isWritable: false, }, profileProgram: { value: input.profileProgram ?? null, isWritable: false }, character: { value: input.character ?? null, isWritable: true }, game: { value: input.game ?? null, isWritable: false }, fleet: { value: input.fleet ?? null, isWritable: true }, encounterMarket: { value: input.encounterMarket ?? null, isWritable: true }, treasury: { value: input.treasury ?? null, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, factionStanding: { value: input.factionStanding ?? null, isWritable: true }, factionConfig: { value: input.factionConfig ?? null, isWritable: false }, factionEpochMeter: { value: input.factionEpochMeter ?? null, isWritable: true, }, }; const accounts = originalAccounts as Record< keyof typeof originalAccounts, ResolvedInstructionAccount >; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.profileProgram.value) { accounts.profileProgram.value = 'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u' as Address<'C4PRoFNroxxzdgeCoM31LJjYRg7kT6ymogSTAT99iD1u'>; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta('profileSigner', accounts.profileSigner), getAccountMeta('profileProfile', accounts.profileProfile), getAccountMeta('profileCertificate', accounts.profileCertificate), getAccountMeta('profileProgram', accounts.profileProgram), getAccountMeta('character', accounts.character), getAccountMeta('game', accounts.game), getAccountMeta('fleet', accounts.fleet), getAccountMeta('encounterMarket', accounts.encounterMarket), getAccountMeta('treasury', accounts.treasury), getAccountMeta('systemProgram', accounts.systemProgram), getAccountMeta('factionStanding', accounts.factionStanding), getAccountMeta('factionConfig', accounts.factionConfig), getAccountMeta('factionEpochMeter', accounts.factionEpochMeter), ], data: getTradeEncounterInstructionDataEncoder().encode( args as TradeEncounterInstructionDataArgs, ), programAddress, } as TradeEncounterInstruction< TProgramAddress, TAccountProfileSigner, TAccountProfileProfile, TAccountProfileCertificate, TAccountProfileProgram, TAccountCharacter, TAccountGame, TAccountFleet, TAccountEncounterMarket, TAccountTreasury, TAccountSystemProgram, TAccountFactionStanding, TAccountFactionConfig, TAccountFactionEpochMeter >); } export type ParsedTradeEncounterInstruction< TProgram extends string = typeof SAGE_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > = { programAddress: Address; accounts: { profileSigner: TAccountMetas[0]; profileProfile: TAccountMetas[1]; profileCertificate?: TAccountMetas[2] | undefined; profileProgram: TAccountMetas[3]; character: TAccountMetas[4]; game: TAccountMetas[5]; /** The trading fleet — crew normalized at validation; cargo is delivered to / taken from its hold. */ fleet: TAccountMetas[6]; /** The player's open market (game-scoped; owner re-checked in the handler). Offer qtys decrement here. */ encounterMarket: TAccountMetas[7]; /** The treasury this market settles against (bound match re-checked in the handler). Value moves here. */ treasury: TAccountMetas[8]; systemProgram: TAccountMetas[9]; /** The signer's `(game, profile, faction)` standing PDA (created via `InitFactionStanding`); credited here. */ factionStanding?: TAccountMetas[10] | undefined; /** Per-game reputation dials (`[FactionConfig, game]`): supplies `standing_bps` + the decay/DR/cap. */ factionConfig?: TAccountMetas[11] | undefined; /** Per-faction aggregate emission meter (`[FactionEpochMeter, game, faction]`): the anti-sybil cap. */ factionEpochMeter?: TAccountMetas[12] | undefined; }; data: TradeEncounterInstructionData; }; export function parseTradeEncounterInstruction< TProgram extends string, TAccountMetas extends readonly AccountMeta[], >( instruction: Instruction & InstructionWithAccounts & InstructionWithData, ): ParsedTradeEncounterInstruction { if (instruction.accounts.length < 13) { throw new SolanaError( SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 13, }, ); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SAGE_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { profileSigner: getNextAccount(), profileProfile: getNextAccount(), profileCertificate: getNextOptionalAccount(), profileProgram: getNextAccount(), character: getNextAccount(), game: getNextAccount(), fleet: getNextAccount(), encounterMarket: getNextAccount(), treasury: getNextAccount(), systemProgram: getNextAccount(), factionStanding: getNextOptionalAccount(), factionConfig: getNextOptionalAccount(), factionEpochMeter: getNextOptionalAccount(), }, data: getTradeEncounterInstructionDataDecoder().decode(instruction.data), }; }