micro-sol-signer
Version:
Create, sign & decode Solana transactions with minimum deps
282 lines • 8.1 kB
JavaScript
import * as P from 'micro-packed';
import * as idl from "./index.js";
import TokenIDL from "./token.js";
// Basic
const assertType = (_value) => { };
assertType(1);
assertType(1);
assertType(1);
const args = [
{
kind: 'instructionArgumentNode',
name: 'discriminator',
type: {
kind: 'numberTypeNode',
format: 'u8',
endian: 'le',
},
docs: [],
defaultValue: { kind: 'numberValueNode', number: 12 },
defaultValueStrategy: 'omitted',
},
{
kind: 'instructionArgumentNode',
name: 'amount',
type: {
kind: 'numberTypeNode',
format: 'u64',
endian: 'le',
},
defaultValue: { kind: 'numberValueNode', number: 12 },
defaultValueStrategy: 'optional',
docs: ['The amount of tokens to transfer.'],
},
{
kind: 'instructionArgumentNode',
name: 'decimals',
type: {
kind: 'numberTypeNode',
format: 'u8',
endian: 'le',
},
docs: ['Expected number of base 10 digits to the right of the decimal place.'],
},
];
assertType(1);
const accounts = [
{
kind: 'instructionAccountNode',
name: 'mint',
isWritable: true,
isSigner: false,
isOptional: false,
docs: ['The mint account.'],
},
{
kind: 'instructionAccountNode',
name: 'rent',
isWritable: false,
isSigner: false,
isOptional: false,
docs: ['Rent sysvar.'],
defaultValue: {
kind: 'publicKeyValueNode',
publicKey: 'SysvarRent111111111111111111111111111111111',
},
},
{
kind: 'instructionAccountNode',
name: 'payer',
isWritable: true,
isSigner: true,
isOptional: false,
docs: ['Funding account (must be a system account).'],
defaultValue: { kind: 'payerValueNode' },
},
];
const instruction = {
kind: 'instructionNode',
accounts: [
{
kind: 'instructionAccountNode',
name: 'payer',
isWritable: true,
isSigner: true,
isOptional: false,
docs: ['Funding account (must be a system account).'],
defaultValue: { kind: 'payerValueNode' },
},
{
kind: 'instructionAccountNode',
name: 'ata',
isWritable: true,
isSigner: false,
isOptional: false,
docs: ['Associated token account address to be created.'],
defaultValue: {
kind: 'pdaValueNode',
pda: {
kind: 'pdaLinkNode',
name: 'associatedToken',
},
seeds: [
{
kind: 'pdaSeedValueNode',
name: 'owner',
value: {
kind: 'accountValueNode',
name: 'owner',
},
},
{
kind: 'pdaSeedValueNode',
name: 'tokenProgram',
value: {
kind: 'accountValueNode',
name: 'tokenProgram',
},
},
{
kind: 'pdaSeedValueNode',
name: 'mint',
value: {
kind: 'accountValueNode',
name: 'mint',
},
},
],
},
},
{
kind: 'instructionAccountNode',
name: 'owner',
isWritable: false,
isSigner: false,
isOptional: false,
docs: ['Wallet address for the new associated token account.'],
},
{
kind: 'instructionAccountNode',
name: 'mint',
isWritable: false,
isSigner: false,
isOptional: false,
docs: ['The token mint for the new associated token account.'],
},
{
kind: 'instructionAccountNode',
name: 'systemProgram',
isWritable: false,
isSigner: false,
isOptional: false,
docs: ['System program.'],
defaultValue: {
kind: 'publicKeyValueNode',
publicKey: '11111111111111111111111111111111',
},
},
{
kind: 'instructionAccountNode',
name: 'tokenProgram',
isWritable: false,
isSigner: false,
isOptional: false,
docs: ['SPL Token program.'],
defaultValue: {
kind: 'publicKeyValueNode',
publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
},
},
],
arguments: [
{
kind: 'instructionArgumentNode',
name: 'discriminator',
type: {
kind: 'numberTypeNode',
format: 'u8',
endian: 'le',
},
docs: [],
defaultValue: { kind: 'numberValueNode', number: 0 },
defaultValueStrategy: 'omitted',
},
],
discriminators: [
{
kind: 'fieldDiscriminatorNode',
name: 'discriminator',
offset: 0,
},
],
name: 'createAssociatedToken',
docs: [
'Creates an associated token account for the given wallet address and',
'token mint Returns an error if the account exists.',
],
optionalAccountStrategy: 'programId',
};
assertType(1);
let b = 1(1);
b;
let a = 1;
a({
source: '7o36UsWR1JQLpZ9PE2gn9L4SQ69CNNiWAXd4Jt7rqz9Z',
mint: 'DShWnroshVbeUp28oopA3Pu7oFPDBtC1DBmPECXXAQ9n',
destination: 'Hozo7TadHq6PMMiGLGNvgk79Hvj5VTAM7Ny2bamQ2m8q',
authority: '3ECJhLBQ9DAuKBKNjQGLEk3YqoFcF1YvhdayQ2C96eXF',
amount: 123n,
decimals: 10,
});
let a2 = 1;
a2({
owner: '1',
mint: '1',
amount: 1n,
closeAuthority: '1',
delegate: '1',
delegatedAmount: 1n,
isNative: undefined,
state: { TAG: 'initialized' },
});
const t33 = idl.defineProgram(TokenIDL['program']);
t33.instructions.encoders.transferChecked({
source: '7o36UsWR1JQLpZ9PE2gn9L4SQ69CNNiWAXd4Jt7rqz9Z',
mint: 'DShWnroshVbeUp28oopA3Pu7oFPDBtC1DBmPECXXAQ9n',
destination: 'Hozo7TadHq6PMMiGLGNvgk79Hvj5VTAM7Ny2bamQ2m8q',
authority: '3ECJhLBQ9DAuKBKNjQGLEk3YqoFcF1YvhdayQ2C96eXF',
amount: 123n,
decimals: 10,
});
let a3 = idl.defineIDL(TokenIDL);
a3.token.additionalPrograms.associatedToken.pdas.associatedToken({
owner: '1',
tokenProgram: '1',
mint: '1',
});
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
assertType(1);
// PDAs
const testpdas = [
{
kind: 'pdaNode',
name: 'associatedToken',
seeds: [
{
kind: 'variablePdaSeedNode',
name: 'owner',
docs: ['The wallet address of the associated token account.'],
type: {
kind: 'publicKeyTypeNode',
},
},
{
kind: 'variablePdaSeedNode',
name: 'tokenProgram',
docs: ['The address of the token program to use.'],
type: {
kind: 'publicKeyTypeNode',
},
},
{
kind: 'variablePdaSeedNode',
name: 'mint',
docs: ['The mint address of the associated token account.'],
type: {
kind: 'publicKeyTypeNode',
},
},
],
},
];
assertType(idl.parsePDAs('1', testpdas));
//# sourceMappingURL=_type_test.js.map