@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
261 lines • 11.4 kB
JavaScript
;
/**
* 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.CREATE_CONTRACT_DISCRIMINATOR = void 0;
exports.getCreateContractDiscriminatorBytes = getCreateContractDiscriminatorBytes;
exports.getCreateContractInstructionDataEncoder = getCreateContractInstructionDataEncoder;
exports.getCreateContractInstructionDataDecoder = getCreateContractInstructionDataDecoder;
exports.getCreateContractInstructionDataCodec = getCreateContractInstructionDataCodec;
exports.getCreateContractInstructionAsync = getCreateContractInstructionAsync;
exports.getCreateContractInstruction = getCreateContractInstruction;
exports.parseCreateContractInstruction = parseCreateContractInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.CREATE_CONTRACT_DISCRIMINATOR = new Uint8Array([
244, 48, 244, 178, 216, 88, 122, 52,
]);
function getCreateContractDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.CREATE_CONTRACT_DISCRIMINATOR);
}
function getCreateContractInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
['rate', (0, kit_1.getU64Encoder)()],
['durationMin', (0, kit_1.getU64Encoder)()],
['durationMax', (0, kit_1.getU64Encoder)()],
['paymentsFeq', (0, kit_1.addEncoderSizePrefix)((0, kit_1.getUtf8Encoder)(), (0, kit_1.getU32Encoder)())],
['ownerKeyIndex', (0, kit_1.getU16Encoder)()],
]), (value) => ({ ...value, discriminator: exports.CREATE_CONTRACT_DISCRIMINATOR }));
}
function getCreateContractInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
['rate', (0, kit_1.getU64Decoder)()],
['durationMin', (0, kit_1.getU64Decoder)()],
['durationMax', (0, kit_1.getU64Decoder)()],
['paymentsFeq', (0, kit_1.addDecoderSizePrefix)((0, kit_1.getUtf8Decoder)(), (0, kit_1.getU32Decoder)())],
['ownerKeyIndex', (0, kit_1.getU16Decoder)()],
]);
}
function getCreateContractInstructionDataCodec() {
return (0, kit_1.combineCodec)(getCreateContractInstructionDataEncoder(), getCreateContractInstructionDataDecoder());
}
async function getCreateContractInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.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 (0, kit_1.getProgramDerivedAddress)({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
(0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.owner.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.contract.value) {
accounts.contract.value = await (0, kit_1.getProgramDerivedAddress)({
programAddress,
seeds: [
(0, kit_1.getBytesEncoder)().encode(new Uint8Array([
114, 101, 110, 116, 97, 108, 95, 99, 111, 110, 116, 114, 97, 99,
116,
])),
(0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.fleet.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.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 = (0, shared_1.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;
}
function getCreateContractInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.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 = (0, shared_1.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;
}
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