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)

363 lines 16.3 kB
"use strict"; /** * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ACCEPT_RENTAL_DISCRIMINATOR = void 0; exports.getAcceptRentalDiscriminatorBytes = getAcceptRentalDiscriminatorBytes; exports.getAcceptRentalInstructionDataEncoder = getAcceptRentalInstructionDataEncoder; exports.getAcceptRentalInstructionDataDecoder = getAcceptRentalInstructionDataDecoder; exports.getAcceptRentalInstructionDataCodec = getAcceptRentalInstructionDataCodec; exports.getAcceptRentalInstructionAsync = getAcceptRentalInstructionAsync; exports.getAcceptRentalInstruction = getAcceptRentalInstruction; exports.parseAcceptRentalInstruction = parseAcceptRentalInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.ACCEPT_RENTAL_DISCRIMINATOR = new Uint8Array([ 192, 221, 241, 212, 141, 161, 36, 146, ]); function getAcceptRentalDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.ACCEPT_RENTAL_DISCRIMINATOR); } function getAcceptRentalInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([ ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['amount', (0, kit_1.getU64Encoder)()], ['duration', (0, kit_1.getU64Encoder)()], ]), (value) => ({ ...value, discriminator: exports.ACCEPT_RENTAL_DISCRIMINATOR })); } function getAcceptRentalInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([ ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['amount', (0, kit_1.getU64Decoder)()], ['duration', (0, kit_1.getU64Decoder)()], ]); } function getAcceptRentalInstructionDataCodec() { return (0, kit_1.combineCodec)(getAcceptRentalInstructionDataEncoder(), getAcceptRentalInstructionDataDecoder()); } async function getAcceptRentalInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { mint: { value: input.mint ?? null, isWritable: false }, borrower: { value: input.borrower ?? null, isWritable: true }, borrowerProfile: { value: input.borrowerProfile ?? null, isWritable: false, }, borrowerProfileFaction: { value: input.borrowerProfileFaction ?? null, isWritable: false, }, borrowerTokenAccount: { value: input.borrowerTokenAccount ?? null, isWritable: true, }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: true }, rentalState: { value: input.rentalState ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, rentalTokenAccount: { value: input.rentalTokenAccount ?? null, isWritable: true, }, rentalThread: { value: input.rentalThread ?? null, isWritable: true }, feeTokenAccount: { value: input.feeTokenAccount ?? null, isWritable: true }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, antegenProgram: { value: input.antegenProgram ?? 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; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.mint.value) { accounts.mint.value = 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx'; } if (!accounts.borrowerTokenAccount.value) { accounts.borrowerTokenAccount.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', seeds: [ (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.borrower.value)), (0, kit_1.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, ])), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)), ], }); } if (!accounts.rentalState.value) { accounts.rentalState.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress, seeds: [ (0, kit_1.getBytesEncoder)().encode(new Uint8Array([ 114, 101, 110, 116, 97, 108, 95, 115, 116, 97, 116, 101, ])), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.contract.value)), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.borrower.value)), ], }); } if (!accounts.rentalAuthority.value) { accounts.rentalAuthority.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress, seeds: [ (0, kit_1.getBytesEncoder)().encode(new Uint8Array([ 114, 101, 110, 116, 97, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121, ])), ], }); } if (!accounts.rentalTokenAccount.value) { accounts.rentalTokenAccount.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', seeds: [ (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.rentalState.value)), (0, kit_1.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, ])), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)), ], }); } if (!accounts.rentalThread.value) { accounts.rentalThread.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress, seeds: [ (0, kit_1.getBytesEncoder)().encode(new Uint8Array([116, 104, 114, 101, 97, 100])), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.rentalAuthority.value)), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.rentalState.value)), ], }); } if (!accounts.feeTokenAccount.value) { accounts.feeTokenAccount.value = await (0, kit_1.getProgramDerivedAddress)({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', seeds: [ (0, kit_1.getBytesEncoder)().encode(new Uint8Array([ 200, 182, 122, 108, 74, 122, 176, 202, 84, 111, 116, 161, 175, 85, 111, 229, 188, 105, 205, 151, 154, 187, 178, 50, 133, 209, 48, 56, 107, 39, 184, 43, ])), (0, kit_1.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, ])), (0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)), ], }); } if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } if (!accounts.antegenProgram.value) { accounts.antegenProgram.value = 'AgThdyi1P5RkVeZD2rQahTvs8HePJoGFFxKtvok5s2J1'; } 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 = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.mint), getAccountMeta(accounts.borrower), getAccountMeta(accounts.borrowerProfile), getAccountMeta(accounts.borrowerProfileFaction), getAccountMeta(accounts.borrowerTokenAccount), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.rentalTokenAccount), getAccountMeta(accounts.rentalThread), getAccountMeta(accounts.feeTokenAccount), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.antegenProgram), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), ], programAddress, data: getAcceptRentalInstructionDataEncoder().encode(args), }; return instruction; } function getAcceptRentalInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { mint: { value: input.mint ?? null, isWritable: false }, borrower: { value: input.borrower ?? null, isWritable: true }, borrowerProfile: { value: input.borrowerProfile ?? null, isWritable: false, }, borrowerProfileFaction: { value: input.borrowerProfileFaction ?? null, isWritable: false, }, borrowerTokenAccount: { value: input.borrowerTokenAccount ?? null, isWritable: true, }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: true }, rentalState: { value: input.rentalState ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, rentalTokenAccount: { value: input.rentalTokenAccount ?? null, isWritable: true, }, rentalThread: { value: input.rentalThread ?? null, isWritable: true }, feeTokenAccount: { value: input.feeTokenAccount ?? null, isWritable: true }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, antegenProgram: { value: input.antegenProgram ?? 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; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.mint.value) { accounts.mint.value = 'ATLA5nAaVRfH6BNwD4SAyWp96EdQaAh6bBmGeTx956sx'; } if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } if (!accounts.antegenProgram.value) { accounts.antegenProgram.value = 'AgThdyi1P5RkVeZD2rQahTvs8HePJoGFFxKtvok5s2J1'; } 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 = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.mint), getAccountMeta(accounts.borrower), getAccountMeta(accounts.borrowerProfile), getAccountMeta(accounts.borrowerProfileFaction), getAccountMeta(accounts.borrowerTokenAccount), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.rentalTokenAccount), getAccountMeta(accounts.rentalThread), getAccountMeta(accounts.feeTokenAccount), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.antegenProgram), getAccountMeta(accounts.tokenProgram), getAccountMeta(accounts.associatedTokenProgram), getAccountMeta(accounts.systemProgram), ], programAddress, data: getAcceptRentalInstructionDataEncoder().encode(args), }; return instruction; } function parseAcceptRentalInstruction(instruction) { if (instruction.accounts.length < 20) { // 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(), borrower: getNextAccount(), borrowerProfile: getNextAccount(), borrowerProfileFaction: getNextAccount(), borrowerTokenAccount: getNextAccount(), fleet: getNextAccount(), gameId: getNextAccount(), starbase: getNextAccount(), starbasePlayer: getNextAccount(), contract: getNextAccount(), rentalState: getNextAccount(), rentalAuthority: getNextAccount(), rentalTokenAccount: getNextAccount(), rentalThread: getNextAccount(), feeTokenAccount: getNextAccount(), sageProgram: getNextAccount(), antegenProgram: getNextAccount(), tokenProgram: getNextAccount(), associatedTokenProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getAcceptRentalInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=acceptRental.js.map