UNPKG

@wuwei-labs/srsly

Version:
276 lines 12.1 kB
/** * 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, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { expectAddress, getAccountMetaFactory } from '../shared'; export const CLOSE_CONTRACT_DISCRIMINATOR = new Uint8Array([37, 244, 34, 168, 92, 202, 80, 106]); export function getCloseContractDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_CONTRACT_DISCRIMINATOR); } export function getCloseContractInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: CLOSE_CONTRACT_DISCRIMINATOR })); } export function getCloseContractInstructionDataDecoder() { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getCloseContractInstructionDataCodec() { return combineCodec(getCloseContractInstructionDataEncoder(), getCloseContractInstructionDataDecoder()); } export async function getCloseContractInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: true }, config: { value: input.config ?? null, isWritable: false }, mint: { value: input.mint ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, activeRental: { value: input.activeRental ?? null, isWritable: true }, queuedRental: { value: input.queuedRental ?? null, isWritable: true }, contractTokenAccount: { value: input.contractTokenAccount ?? null, isWritable: true, }, ownerDestination: { value: input.ownerDestination ?? null, isWritable: true, }, queuedBorrowerState: { value: input.queuedBorrowerState ?? null, isWritable: true, }, queuedBorrowerTokenAccount: { value: input.queuedBorrowerTokenAccount ?? null, isWritable: true, }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.config.value) { accounts.config.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))], }); } if (!accounts.contract.value) { accounts.contract.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([114, 101, 110, 116, 97, 108, 95, 99, 111, 110, 116, 114, 97, 99, 116])), getAddressEncoder().encode(expectAddress(accounts.fleet.value)), ], }); } if (!accounts.activeRental.value) { accounts.activeRental.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([114, 101, 110, 116, 97, 108, 95, 115, 116, 97, 116, 101])), getAddressEncoder().encode(expectAddress(accounts.contract.value)), getBytesEncoder().encode(new Uint8Array([97, 99, 116, 105, 118, 101])), ], }); } if (!accounts.queuedRental.value) { accounts.queuedRental.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([114, 101, 110, 116, 97, 108, 95, 115, 116, 97, 116, 101])), getAddressEncoder().encode(expectAddress(accounts.contract.value)), getBytesEncoder().encode(new Uint8Array([113, 117, 101, 117, 101, 100])), ], }); } if (!accounts.ownerDestination.value) { accounts.ownerDestination.value = await getProgramDerivedAddress({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', seeds: [ getAddressEncoder().encode(expectAddress(accounts.owner.value)), getBytesEncoder().encode(new Uint8Array([ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169, ])), getAddressEncoder().encode(expectAddress(accounts.mint.value)), ], }); } if (!accounts.rentalAuthority.value) { accounts.rentalAuthority.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([ 114, 101, 110, 116, 97, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121, ])), ], }); } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } if (!accounts.associatedTokenProgram.value) { accounts.associatedTokenProgram.value = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.owner), getAccountMeta(accounts.config), getAccountMeta(accounts.mint), getAccountMeta(accounts.contract), getAccountMeta(accounts.fleet), getAccountMeta(accounts.activeRental), getAccountMeta(accounts.queuedRental), getAccountMeta(accounts.contractTokenAccount), getAccountMeta(accounts.ownerDestination), getAccountMeta(accounts.queuedBorrowerState), getAccountMeta(accounts.queuedBorrowerTokenAccount), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), ], data: getCloseContractInstructionDataEncoder().encode({}), programAddress, }); } export function getCloseContractInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: true }, config: { value: input.config ?? null, isWritable: false }, mint: { value: input.mint ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, activeRental: { value: input.activeRental ?? null, isWritable: true }, queuedRental: { value: input.queuedRental ?? null, isWritable: true }, contractTokenAccount: { value: input.contractTokenAccount ?? null, isWritable: true, }, ownerDestination: { value: input.ownerDestination ?? null, isWritable: true, }, queuedBorrowerState: { value: input.queuedBorrowerState ?? null, isWritable: true, }, queuedBorrowerTokenAccount: { value: input.queuedBorrowerTokenAccount ?? null, isWritable: true, }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } if (!accounts.associatedTokenProgram.value) { accounts.associatedTokenProgram.value = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.owner), getAccountMeta(accounts.config), getAccountMeta(accounts.mint), getAccountMeta(accounts.contract), getAccountMeta(accounts.fleet), getAccountMeta(accounts.activeRental), getAccountMeta(accounts.queuedRental), getAccountMeta(accounts.contractTokenAccount), getAccountMeta(accounts.ownerDestination), getAccountMeta(accounts.queuedBorrowerState), getAccountMeta(accounts.queuedBorrowerTokenAccount), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), ], data: getCloseContractInstructionDataEncoder().encode({}), programAddress, }); } export function parseCloseContractInstruction(instruction) { if (instruction.accounts.length < 16) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SRSLY_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { owner: getNextAccount(), config: getNextAccount(), mint: getNextAccount(), contract: getNextAccount(), fleet: getNextAccount(), activeRental: getNextAccount(), queuedRental: getNextAccount(), contractTokenAccount: getNextAccount(), ownerDestination: getNextAccount(), queuedBorrowerState: getNextOptionalAccount(), queuedBorrowerTokenAccount: getNextOptionalAccount(), rentalAuthority: getNextAccount(), sageProgram: getNextAccount(), tokenProgram: getNextAccount(), associatedTokenProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getCloseContractInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=closeContract.js.map