UNPKG

@wuwei-labs/srsly

Version:

[![npm version](https://img.shields.io/npm/v/ts-sdk-example.svg)](https://www.npmjs.com/package/ts-sdk-example)

251 lines 10.6 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 { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getUtf8Decoder, getUtf8Encoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { expectAddress, getAccountMetaFactory, } from '../shared'; export const CREATE_CONTRACT_DISCRIMINATOR = new Uint8Array([ 244, 48, 244, 178, 216, 88, 122, 52, ]); export function getCreateContractDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CREATE_CONTRACT_DISCRIMINATOR); } export function getCreateContractInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['rate', getU64Encoder()], ['durationMin', getU64Encoder()], ['durationMax', getU64Encoder()], ['paymentsFeq', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], ['ownerKeyIndex', getU16Encoder()], ]), (value) => ({ ...value, discriminator: CREATE_CONTRACT_DISCRIMINATOR })); } export function getCreateContractInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['rate', getU64Decoder()], ['durationMin', getU64Decoder()], ['durationMax', getU64Decoder()], ['paymentsFeq', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], ['ownerKeyIndex', getU16Decoder()], ]); } export function getCreateContractInstructionDataCodec() { return combineCodec(getCreateContractInstructionDataEncoder(), getCreateContractInstructionDataDecoder()); } export async function getCreateContractInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { mint: { value: input.mint ?? null, isWritable: false }, owner: { value: input.owner ?? null, isWritable: true }, ownerTokenAccount: { value: input.ownerTokenAccount ?? null, isWritable: true, }, fleet: { value: input.fleet ?? null, isWritable: true }, ownerProfile: { value: input.ownerProfile ?? null, isWritable: false }, gameId: { value: input.gameId ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.mint.value) { accounts.mint.value = 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx'; } if (!accounts.ownerTokenAccount.value) { accounts.ownerTokenAccount.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.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.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'; } if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.mint), getAccountMeta(accounts.owner), getAccountMeta(accounts.ownerTokenAccount), getAccountMeta(accounts.fleet), getAccountMeta(accounts.ownerProfile), getAccountMeta(accounts.gameId), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.sageProgram), ], programAddress, data: getCreateContractInstructionDataEncoder().encode(args), }; return instruction; } export function getCreateContractInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { mint: { value: input.mint ?? null, isWritable: false }, owner: { value: input.owner ?? null, isWritable: true }, ownerTokenAccount: { value: input.ownerTokenAccount ?? null, isWritable: true, }, fleet: { value: input.fleet ?? null, isWritable: true }, ownerProfile: { value: input.ownerProfile ?? null, isWritable: false }, gameId: { value: input.gameId ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isWritable: false, }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.mint.value) { accounts.mint.value = 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx'; } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } if (!accounts.associatedTokenProgram.value) { accounts.associatedTokenProgram.value = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.mint), getAccountMeta(accounts.owner), getAccountMeta(accounts.ownerTokenAccount), getAccountMeta(accounts.fleet), getAccountMeta(accounts.ownerProfile), getAccountMeta(accounts.gameId), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), getAccountMeta(accounts.sageProgram), ], programAddress, data: getCreateContractInstructionDataEncoder().encode(args), }; return instruction; } export function parseCreateContractInstruction(instruction) { if (instruction.accounts.length < 12) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { mint: getNextAccount(), owner: getNextAccount(), ownerTokenAccount: getNextAccount(), fleet: getNextAccount(), ownerProfile: getNextAccount(), gameId: getNextAccount(), contract: getNextAccount(), rentalAuthority: getNextAccount(), tokenProgram: getNextAccount(), associatedTokenProgram: getNextAccount(), systemProgram: getNextAccount(), sageProgram: getNextAccount(), }, data: getCreateContractInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=createContract.js.map