@nosana/kit 0.1.7 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/.gitlab-ci.yml +41 -9
  2. package/.prettierignore +17 -0
  3. package/README.md +729 -59
  4. package/dist/config/defaultConfigs.d.ts +1 -1
  5. package/dist/config/defaultConfigs.js +2 -2
  6. package/dist/config/types.d.ts +1 -1
  7. package/dist/config/utils.d.ts +1 -1
  8. package/dist/config/utils.js +5 -5
  9. package/dist/errors/NosanaError.d.ts +1 -1
  10. package/dist/generated_clients/jobs/instructions/assign.d.ts +79 -0
  11. package/dist/generated_clients/jobs/instructions/assign.js +120 -0
  12. package/dist/generated_clients/jobs/instructions/extend.d.ts +9 -6
  13. package/dist/generated_clients/jobs/instructions/extend.js +4 -1
  14. package/dist/generated_clients/jobs/instructions/finish.d.ts +10 -10
  15. package/dist/generated_clients/jobs/instructions/finish.js +6 -6
  16. package/dist/generated_clients/jobs/instructions/index.d.ts +1 -0
  17. package/dist/generated_clients/jobs/instructions/index.js +1 -0
  18. package/dist/generated_clients/jobs/programs/nosanaJobs.d.ts +18 -15
  19. package/dist/generated_clients/jobs/programs/nosanaJobs.js +18 -14
  20. package/dist/generated_clients/staking/accounts/index.d.ts +9 -0
  21. package/dist/generated_clients/staking/accounts/index.js +9 -0
  22. package/dist/generated_clients/staking/accounts/settingsAccount.d.ts +29 -0
  23. package/dist/generated_clients/staking/accounts/settingsAccount.js +55 -0
  24. package/dist/generated_clients/staking/accounts/stakeAccount.d.ts +39 -0
  25. package/dist/generated_clients/staking/accounts/stakeAccount.js +65 -0
  26. package/dist/generated_clients/staking/errors/index.d.ts +8 -0
  27. package/dist/generated_clients/staking/errors/index.js +8 -0
  28. package/dist/generated_clients/staking/errors/nosanaStaking.d.ts +45 -0
  29. package/dist/generated_clients/staking/errors/nosanaStaking.js +62 -0
  30. package/dist/generated_clients/staking/index.d.ts +11 -0
  31. package/dist/generated_clients/staking/index.js +11 -0
  32. package/dist/generated_clients/staking/instructions/close.d.ts +48 -0
  33. package/dist/generated_clients/staking/instructions/close.js +81 -0
  34. package/dist/generated_clients/staking/instructions/extend.d.ts +43 -0
  35. package/dist/generated_clients/staking/instructions/extend.js +73 -0
  36. package/dist/generated_clients/staking/instructions/index.d.ts +17 -0
  37. package/dist/generated_clients/staking/instructions/index.js +17 -0
  38. package/dist/generated_clients/staking/instructions/init.d.ts +45 -0
  39. package/dist/generated_clients/staking/instructions/init.js +82 -0
  40. package/dist/generated_clients/staking/instructions/restake.d.ts +42 -0
  41. package/dist/generated_clients/staking/instructions/restake.js +70 -0
  42. package/dist/generated_clients/staking/instructions/slash.d.ts +55 -0
  43. package/dist/generated_clients/staking/instructions/slash.js +90 -0
  44. package/dist/generated_clients/staking/instructions/stake.d.ts +64 -0
  45. package/dist/generated_clients/staking/instructions/stake.js +106 -0
  46. package/dist/generated_clients/staking/instructions/topup.d.ts +52 -0
  47. package/dist/generated_clients/staking/instructions/topup.js +87 -0
  48. package/dist/generated_clients/staking/instructions/unstake.d.ts +42 -0
  49. package/dist/generated_clients/staking/instructions/unstake.js +70 -0
  50. package/dist/generated_clients/staking/instructions/updateSettings.d.ts +45 -0
  51. package/dist/generated_clients/staking/instructions/updateSettings.js +73 -0
  52. package/dist/generated_clients/staking/instructions/withdraw.d.ts +48 -0
  53. package/dist/generated_clients/staking/instructions/withdraw.js +81 -0
  54. package/dist/generated_clients/staking/programs/index.d.ts +8 -0
  55. package/dist/generated_clients/staking/programs/index.js +8 -0
  56. package/dist/generated_clients/staking/programs/nosanaStaking.d.ts +53 -0
  57. package/dist/generated_clients/staking/programs/nosanaStaking.js +71 -0
  58. package/dist/generated_clients/staking/shared/index.d.ts +49 -0
  59. package/dist/generated_clients/staking/shared/index.js +86 -0
  60. package/dist/index.d.ts +12 -4
  61. package/dist/index.js +18 -136
  62. package/dist/ipfs/IPFS.js +3 -0
  63. package/dist/programs/BaseProgram.d.ts +1 -1
  64. package/dist/programs/BaseProgram.js +3 -7
  65. package/dist/programs/JobsProgram.d.ts +37 -37
  66. package/dist/programs/JobsProgram.js +63 -67
  67. package/dist/programs/StakeProgram.d.ts +29 -0
  68. package/dist/programs/StakeProgram.js +91 -0
  69. package/dist/services/NosService.d.ts +48 -0
  70. package/dist/services/NosService.js +134 -0
  71. package/dist/{solana/SolanaUtils.d.ts → services/SolanaService.d.ts} +5 -5
  72. package/dist/{solana/SolanaUtils.js → services/SolanaService.js} +17 -7
  73. package/dist/utils/index.d.ts +2 -1
  74. package/dist/utils/index.js +2 -0
  75. package/dist/utils/walletConverter.d.ts +9 -0
  76. package/dist/utils/walletConverter.js +141 -0
  77. package/eslint.config.js +49 -0
  78. package/examples/node/README.md +115 -0
  79. package/examples/node/nos-service.ts +117 -0
  80. package/examples/node/package.json +3 -1
  81. package/examples/node/retrieve.ts +2 -2
  82. package/examples/node/stake-program.ts +84 -0
  83. package/package.json +11 -8
  84. package/scripts/generate-clients.ts +20 -7
  85. package/vitest.config.ts +31 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const INIT_DISCRIMINATOR = new Uint8Array([
12
+ 220, 59, 207, 236, 108, 250, 47, 100,
13
+ ]);
14
+ export function getInitDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(INIT_DISCRIMINATOR);
16
+ }
17
+ export function getInitInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: INIT_DISCRIMINATOR }));
19
+ }
20
+ export function getInitInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getInitInstructionDataCodec() {
26
+ return combineCodec(getInitInstructionDataEncoder(), getInitInstructionDataDecoder());
27
+ }
28
+ export function getInitInstruction(input, config) {
29
+ // Program address.
30
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
31
+ // Original accounts.
32
+ const originalAccounts = {
33
+ settings: { value: input.settings ?? null, isWritable: true },
34
+ authority: { value: input.authority ?? null, isWritable: true },
35
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
36
+ rent: { value: input.rent ?? null, isWritable: false },
37
+ };
38
+ const accounts = originalAccounts;
39
+ // Resolve default values.
40
+ if (!accounts.systemProgram.value) {
41
+ accounts.systemProgram.value =
42
+ '11111111111111111111111111111111';
43
+ }
44
+ if (!accounts.rent.value) {
45
+ accounts.rent.value =
46
+ 'SysvarRent111111111111111111111111111111111';
47
+ }
48
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
49
+ const instruction = {
50
+ accounts: [
51
+ getAccountMeta(accounts.settings),
52
+ getAccountMeta(accounts.authority),
53
+ getAccountMeta(accounts.systemProgram),
54
+ getAccountMeta(accounts.rent),
55
+ ],
56
+ programAddress,
57
+ data: getInitInstructionDataEncoder().encode({}),
58
+ };
59
+ return instruction;
60
+ }
61
+ export function parseInitInstruction(instruction) {
62
+ if (instruction.accounts.length < 4) {
63
+ // TODO: Coded error.
64
+ throw new Error('Not enough accounts');
65
+ }
66
+ let accountIndex = 0;
67
+ const getNextAccount = () => {
68
+ const accountMeta = instruction.accounts[accountIndex];
69
+ accountIndex += 1;
70
+ return accountMeta;
71
+ };
72
+ return {
73
+ programAddress: instruction.programAddress,
74
+ accounts: {
75
+ settings: getNextAccount(),
76
+ authority: getNextAccount(),
77
+ systemProgram: getNextAccount(),
78
+ rent: getNextAccount(),
79
+ },
80
+ data: getInitInstructionDataDecoder().decode(instruction.data),
81
+ };
82
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { type Address, type Codec, type Decoder, type Encoder, type IAccountMeta, type IAccountSignerMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const RESTAKE_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getRestakeDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type RestakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountVault extends string | IAccountMeta<string> = string, TAccountStake extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountVault extends string ? WritableAccount<TAccountVault> : TAccountVault,
14
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
15
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
16
+ ...TRemainingAccounts
17
+ ]>;
18
+ export type RestakeInstructionData = {
19
+ discriminator: ReadonlyUint8Array;
20
+ };
21
+ export type RestakeInstructionDataArgs = {};
22
+ export declare function getRestakeInstructionDataEncoder(): Encoder<RestakeInstructionDataArgs>;
23
+ export declare function getRestakeInstructionDataDecoder(): Decoder<RestakeInstructionData>;
24
+ export declare function getRestakeInstructionDataCodec(): Codec<RestakeInstructionDataArgs, RestakeInstructionData>;
25
+ export type RestakeInput<TAccountVault extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string> = {
26
+ vault: Address<TAccountVault>;
27
+ stake: Address<TAccountStake>;
28
+ authority: TransactionSigner<TAccountAuthority>;
29
+ };
30
+ export declare function getRestakeInstruction<TAccountVault extends string, TAccountStake extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: RestakeInput<TAccountVault, TAccountStake, TAccountAuthority>, config?: {
31
+ programAddress?: TProgramAddress;
32
+ }): RestakeInstruction<TProgramAddress, TAccountVault, TAccountStake, TAccountAuthority>;
33
+ export type ParsedRestakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
34
+ programAddress: Address<TProgram>;
35
+ accounts: {
36
+ vault: TAccountMetas[0];
37
+ stake: TAccountMetas[1];
38
+ authority: TAccountMetas[2];
39
+ };
40
+ data: RestakeInstructionData;
41
+ };
42
+ export declare function parseRestakeInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedRestakeInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const RESTAKE_DISCRIMINATOR = new Uint8Array([
12
+ 97, 161, 241, 167, 6, 32, 213, 53,
13
+ ]);
14
+ export function getRestakeDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(RESTAKE_DISCRIMINATOR);
16
+ }
17
+ export function getRestakeInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: RESTAKE_DISCRIMINATOR }));
19
+ }
20
+ export function getRestakeInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getRestakeInstructionDataCodec() {
26
+ return combineCodec(getRestakeInstructionDataEncoder(), getRestakeInstructionDataDecoder());
27
+ }
28
+ export function getRestakeInstruction(input, config) {
29
+ // Program address.
30
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
31
+ // Original accounts.
32
+ const originalAccounts = {
33
+ vault: { value: input.vault ?? null, isWritable: true },
34
+ stake: { value: input.stake ?? null, isWritable: true },
35
+ authority: { value: input.authority ?? null, isWritable: false },
36
+ };
37
+ const accounts = originalAccounts;
38
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
39
+ const instruction = {
40
+ accounts: [
41
+ getAccountMeta(accounts.vault),
42
+ getAccountMeta(accounts.stake),
43
+ getAccountMeta(accounts.authority),
44
+ ],
45
+ programAddress,
46
+ data: getRestakeInstructionDataEncoder().encode({}),
47
+ };
48
+ return instruction;
49
+ }
50
+ export function parseRestakeInstruction(instruction) {
51
+ if (instruction.accounts.length < 3) {
52
+ // TODO: Coded error.
53
+ throw new Error('Not enough accounts');
54
+ }
55
+ let accountIndex = 0;
56
+ const getNextAccount = () => {
57
+ const accountMeta = instruction.accounts[accountIndex];
58
+ accountIndex += 1;
59
+ return accountMeta;
60
+ };
61
+ return {
62
+ programAddress: instruction.programAddress,
63
+ accounts: {
64
+ vault: getNextAccount(),
65
+ stake: getNextAccount(),
66
+ authority: getNextAccount(),
67
+ },
68
+ data: getRestakeInstructionDataDecoder().decode(instruction.data),
69
+ };
70
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { type Address, type Codec, type Decoder, type Encoder, type IAccountMeta, type IAccountSignerMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const SLASH_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getSlashDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type SlashInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountVault extends string | IAccountMeta<string> = string, TAccountStake extends string | IAccountMeta<string> = string, TAccountTokenAccount extends string | IAccountMeta<string> = string, TAccountSettings extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TAccountTokenProgram extends string | IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountVault extends string ? WritableAccount<TAccountVault> : TAccountVault,
14
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
15
+ TAccountTokenAccount extends string ? WritableAccount<TAccountTokenAccount> : TAccountTokenAccount,
16
+ TAccountSettings extends string ? ReadonlyAccount<TAccountSettings> : TAccountSettings,
17
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
18
+ TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram,
19
+ ...TRemainingAccounts
20
+ ]>;
21
+ export type SlashInstructionData = {
22
+ discriminator: ReadonlyUint8Array;
23
+ amount: bigint;
24
+ };
25
+ export type SlashInstructionDataArgs = {
26
+ amount: number | bigint;
27
+ };
28
+ export declare function getSlashInstructionDataEncoder(): Encoder<SlashInstructionDataArgs>;
29
+ export declare function getSlashInstructionDataDecoder(): Decoder<SlashInstructionData>;
30
+ export declare function getSlashInstructionDataCodec(): Codec<SlashInstructionDataArgs, SlashInstructionData>;
31
+ export type SlashInput<TAccountVault extends string = string, TAccountStake extends string = string, TAccountTokenAccount extends string = string, TAccountSettings extends string = string, TAccountAuthority extends string = string, TAccountTokenProgram extends string = string> = {
32
+ vault: Address<TAccountVault>;
33
+ stake: Address<TAccountStake>;
34
+ tokenAccount: Address<TAccountTokenAccount>;
35
+ settings: Address<TAccountSettings>;
36
+ authority: TransactionSigner<TAccountAuthority>;
37
+ tokenProgram?: Address<TAccountTokenProgram>;
38
+ amount: SlashInstructionDataArgs['amount'];
39
+ };
40
+ export declare function getSlashInstruction<TAccountVault extends string, TAccountStake extends string, TAccountTokenAccount extends string, TAccountSettings extends string, TAccountAuthority extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: SlashInput<TAccountVault, TAccountStake, TAccountTokenAccount, TAccountSettings, TAccountAuthority, TAccountTokenProgram>, config?: {
41
+ programAddress?: TProgramAddress;
42
+ }): SlashInstruction<TProgramAddress, TAccountVault, TAccountStake, TAccountTokenAccount, TAccountSettings, TAccountAuthority, TAccountTokenProgram>;
43
+ export type ParsedSlashInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
44
+ programAddress: Address<TProgram>;
45
+ accounts: {
46
+ vault: TAccountMetas[0];
47
+ stake: TAccountMetas[1];
48
+ tokenAccount: TAccountMetas[2];
49
+ settings: TAccountMetas[3];
50
+ authority: TAccountMetas[4];
51
+ tokenProgram: TAccountMetas[5];
52
+ };
53
+ data: SlashInstructionData;
54
+ };
55
+ export declare function parseSlashInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedSlashInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const SLASH_DISCRIMINATOR = new Uint8Array([
12
+ 204, 141, 18, 161, 8, 177, 92, 142,
13
+ ]);
14
+ export function getSlashDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(SLASH_DISCRIMINATOR);
16
+ }
17
+ export function getSlashInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([
19
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
20
+ ['amount', getU64Encoder()],
21
+ ]), (value) => ({ ...value, discriminator: SLASH_DISCRIMINATOR }));
22
+ }
23
+ export function getSlashInstructionDataDecoder() {
24
+ return getStructDecoder([
25
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
26
+ ['amount', getU64Decoder()],
27
+ ]);
28
+ }
29
+ export function getSlashInstructionDataCodec() {
30
+ return combineCodec(getSlashInstructionDataEncoder(), getSlashInstructionDataDecoder());
31
+ }
32
+ export function getSlashInstruction(input, config) {
33
+ // Program address.
34
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
35
+ // Original accounts.
36
+ const originalAccounts = {
37
+ vault: { value: input.vault ?? null, isWritable: true },
38
+ stake: { value: input.stake ?? null, isWritable: true },
39
+ tokenAccount: { value: input.tokenAccount ?? null, isWritable: true },
40
+ settings: { value: input.settings ?? null, isWritable: false },
41
+ authority: { value: input.authority ?? null, isWritable: false },
42
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
43
+ };
44
+ const accounts = originalAccounts;
45
+ // Original args.
46
+ const args = { ...input };
47
+ // Resolve default values.
48
+ if (!accounts.tokenProgram.value) {
49
+ accounts.tokenProgram.value =
50
+ 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
51
+ }
52
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
53
+ const instruction = {
54
+ accounts: [
55
+ getAccountMeta(accounts.vault),
56
+ getAccountMeta(accounts.stake),
57
+ getAccountMeta(accounts.tokenAccount),
58
+ getAccountMeta(accounts.settings),
59
+ getAccountMeta(accounts.authority),
60
+ getAccountMeta(accounts.tokenProgram),
61
+ ],
62
+ programAddress,
63
+ data: getSlashInstructionDataEncoder().encode(args),
64
+ };
65
+ return instruction;
66
+ }
67
+ export function parseSlashInstruction(instruction) {
68
+ if (instruction.accounts.length < 6) {
69
+ // TODO: Coded error.
70
+ throw new Error('Not enough accounts');
71
+ }
72
+ let accountIndex = 0;
73
+ const getNextAccount = () => {
74
+ const accountMeta = instruction.accounts[accountIndex];
75
+ accountIndex += 1;
76
+ return accountMeta;
77
+ };
78
+ return {
79
+ programAddress: instruction.programAddress,
80
+ accounts: {
81
+ vault: getNextAccount(),
82
+ stake: getNextAccount(),
83
+ tokenAccount: getNextAccount(),
84
+ settings: getNextAccount(),
85
+ authority: getNextAccount(),
86
+ tokenProgram: getNextAccount(),
87
+ },
88
+ data: getSlashInstructionDataDecoder().decode(instruction.data),
89
+ };
90
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { type Address, type Codec, type Decoder, type Encoder, type IAccountMeta, type IAccountSignerMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type ReadonlyAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const STAKE_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getStakeDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type StakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMint extends string | IAccountMeta<string> = string, TAccountUser extends string | IAccountMeta<string> = string, TAccountVault extends string | IAccountMeta<string> = string, TAccountStake extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TAccountSystemProgram extends string | IAccountMeta<string> = '11111111111111111111111111111111', TAccountTokenProgram extends string | IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', TAccountRent extends string | IAccountMeta<string> = 'SysvarRent111111111111111111111111111111111', TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountMint extends string ? ReadonlyAccount<TAccountMint> : TAccountMint,
14
+ TAccountUser extends string ? WritableAccount<TAccountUser> : TAccountUser,
15
+ TAccountVault extends string ? WritableAccount<TAccountVault> : TAccountVault,
16
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
17
+ TAccountAuthority extends string ? WritableSignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
18
+ TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram,
19
+ TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram,
20
+ TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent,
21
+ ...TRemainingAccounts
22
+ ]>;
23
+ export type StakeInstructionData = {
24
+ discriminator: ReadonlyUint8Array;
25
+ amount: bigint;
26
+ duration: bigint;
27
+ };
28
+ export type StakeInstructionDataArgs = {
29
+ amount: number | bigint;
30
+ duration: number | bigint;
31
+ };
32
+ export declare function getStakeInstructionDataEncoder(): Encoder<StakeInstructionDataArgs>;
33
+ export declare function getStakeInstructionDataDecoder(): Decoder<StakeInstructionData>;
34
+ export declare function getStakeInstructionDataCodec(): Codec<StakeInstructionDataArgs, StakeInstructionData>;
35
+ export type StakeInput<TAccountMint extends string = string, TAccountUser extends string = string, TAccountVault extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountSystemProgram extends string = string, TAccountTokenProgram extends string = string, TAccountRent extends string = string> = {
36
+ mint: Address<TAccountMint>;
37
+ user: Address<TAccountUser>;
38
+ vault: Address<TAccountVault>;
39
+ stake: Address<TAccountStake>;
40
+ authority: TransactionSigner<TAccountAuthority>;
41
+ systemProgram?: Address<TAccountSystemProgram>;
42
+ tokenProgram?: Address<TAccountTokenProgram>;
43
+ rent?: Address<TAccountRent>;
44
+ amount: StakeInstructionDataArgs['amount'];
45
+ duration: StakeInstructionDataArgs['duration'];
46
+ };
47
+ export declare function getStakeInstruction<TAccountMint extends string, TAccountUser extends string, TAccountVault extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountSystemProgram extends string, TAccountTokenProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: StakeInput<TAccountMint, TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountSystemProgram, TAccountTokenProgram, TAccountRent>, config?: {
48
+ programAddress?: TProgramAddress;
49
+ }): StakeInstruction<TProgramAddress, TAccountMint, TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountSystemProgram, TAccountTokenProgram, TAccountRent>;
50
+ export type ParsedStakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
51
+ programAddress: Address<TProgram>;
52
+ accounts: {
53
+ mint: TAccountMetas[0];
54
+ user: TAccountMetas[1];
55
+ vault: TAccountMetas[2];
56
+ stake: TAccountMetas[3];
57
+ authority: TAccountMetas[4];
58
+ systemProgram: TAccountMetas[5];
59
+ tokenProgram: TAccountMetas[6];
60
+ rent: TAccountMetas[7];
61
+ };
62
+ data: StakeInstructionData;
63
+ };
64
+ export declare function parseStakeInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedStakeInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const STAKE_DISCRIMINATOR = new Uint8Array([
12
+ 206, 176, 202, 18, 200, 209, 179, 108,
13
+ ]);
14
+ export function getStakeDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(STAKE_DISCRIMINATOR);
16
+ }
17
+ export function getStakeInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([
19
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
20
+ ['amount', getU64Encoder()],
21
+ ['duration', getU128Encoder()],
22
+ ]), (value) => ({ ...value, discriminator: STAKE_DISCRIMINATOR }));
23
+ }
24
+ export function getStakeInstructionDataDecoder() {
25
+ return getStructDecoder([
26
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
27
+ ['amount', getU64Decoder()],
28
+ ['duration', getU128Decoder()],
29
+ ]);
30
+ }
31
+ export function getStakeInstructionDataCodec() {
32
+ return combineCodec(getStakeInstructionDataEncoder(), getStakeInstructionDataDecoder());
33
+ }
34
+ export function getStakeInstruction(input, config) {
35
+ // Program address.
36
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
37
+ // Original accounts.
38
+ const originalAccounts = {
39
+ mint: { value: input.mint ?? null, isWritable: false },
40
+ user: { value: input.user ?? null, isWritable: true },
41
+ vault: { value: input.vault ?? null, isWritable: true },
42
+ stake: { value: input.stake ?? null, isWritable: true },
43
+ authority: { value: input.authority ?? null, isWritable: true },
44
+ systemProgram: { value: input.systemProgram ?? null, isWritable: false },
45
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
46
+ rent: { value: input.rent ?? null, isWritable: false },
47
+ };
48
+ const accounts = originalAccounts;
49
+ // Original args.
50
+ const args = { ...input };
51
+ // Resolve default values.
52
+ if (!accounts.systemProgram.value) {
53
+ accounts.systemProgram.value =
54
+ '11111111111111111111111111111111';
55
+ }
56
+ if (!accounts.tokenProgram.value) {
57
+ accounts.tokenProgram.value =
58
+ 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
59
+ }
60
+ if (!accounts.rent.value) {
61
+ accounts.rent.value =
62
+ 'SysvarRent111111111111111111111111111111111';
63
+ }
64
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
65
+ const instruction = {
66
+ accounts: [
67
+ getAccountMeta(accounts.mint),
68
+ getAccountMeta(accounts.user),
69
+ getAccountMeta(accounts.vault),
70
+ getAccountMeta(accounts.stake),
71
+ getAccountMeta(accounts.authority),
72
+ getAccountMeta(accounts.systemProgram),
73
+ getAccountMeta(accounts.tokenProgram),
74
+ getAccountMeta(accounts.rent),
75
+ ],
76
+ programAddress,
77
+ data: getStakeInstructionDataEncoder().encode(args),
78
+ };
79
+ return instruction;
80
+ }
81
+ export function parseStakeInstruction(instruction) {
82
+ if (instruction.accounts.length < 8) {
83
+ // TODO: Coded error.
84
+ throw new Error('Not enough accounts');
85
+ }
86
+ let accountIndex = 0;
87
+ const getNextAccount = () => {
88
+ const accountMeta = instruction.accounts[accountIndex];
89
+ accountIndex += 1;
90
+ return accountMeta;
91
+ };
92
+ return {
93
+ programAddress: instruction.programAddress,
94
+ accounts: {
95
+ mint: getNextAccount(),
96
+ user: getNextAccount(),
97
+ vault: getNextAccount(),
98
+ stake: getNextAccount(),
99
+ authority: getNextAccount(),
100
+ systemProgram: getNextAccount(),
101
+ tokenProgram: getNextAccount(),
102
+ rent: getNextAccount(),
103
+ },
104
+ data: getStakeInstructionDataDecoder().decode(instruction.data),
105
+ };
106
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { type Address, type Codec, type Decoder, type Encoder, type IAccountMeta, type IAccountSignerMeta, type IInstruction, type IInstructionWithAccounts, type IInstructionWithData, type ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const TOPUP_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getTopupDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type TopupInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountUser extends string | IAccountMeta<string> = string, TAccountVault extends string | IAccountMeta<string> = string, TAccountStake extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TAccountTokenProgram extends string | IAccountMeta<string> = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountUser extends string ? WritableAccount<TAccountUser> : TAccountUser,
14
+ TAccountVault extends string ? WritableAccount<TAccountVault> : TAccountVault,
15
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
16
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
17
+ TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram,
18
+ ...TRemainingAccounts
19
+ ]>;
20
+ export type TopupInstructionData = {
21
+ discriminator: ReadonlyUint8Array;
22
+ amount: bigint;
23
+ };
24
+ export type TopupInstructionDataArgs = {
25
+ amount: number | bigint;
26
+ };
27
+ export declare function getTopupInstructionDataEncoder(): Encoder<TopupInstructionDataArgs>;
28
+ export declare function getTopupInstructionDataDecoder(): Decoder<TopupInstructionData>;
29
+ export declare function getTopupInstructionDataCodec(): Codec<TopupInstructionDataArgs, TopupInstructionData>;
30
+ export type TopupInput<TAccountUser extends string = string, TAccountVault extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountTokenProgram extends string = string> = {
31
+ user: Address<TAccountUser>;
32
+ vault: Address<TAccountVault>;
33
+ stake: Address<TAccountStake>;
34
+ authority: TransactionSigner<TAccountAuthority>;
35
+ tokenProgram?: Address<TAccountTokenProgram>;
36
+ amount: TopupInstructionDataArgs['amount'];
37
+ };
38
+ export declare function getTopupInstruction<TAccountUser extends string, TAccountVault extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: TopupInput<TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountTokenProgram>, config?: {
39
+ programAddress?: TProgramAddress;
40
+ }): TopupInstruction<TProgramAddress, TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountTokenProgram>;
41
+ export type ParsedTopupInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
42
+ programAddress: Address<TProgram>;
43
+ accounts: {
44
+ user: TAccountMetas[0];
45
+ vault: TAccountMetas[1];
46
+ stake: TAccountMetas[2];
47
+ authority: TAccountMetas[3];
48
+ tokenProgram: TAccountMetas[4];
49
+ };
50
+ data: TopupInstructionData;
51
+ };
52
+ export declare function parseTopupInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedTopupInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+ import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const TOPUP_DISCRIMINATOR = new Uint8Array([
12
+ 126, 42, 49, 78, 225, 151, 99, 77,
13
+ ]);
14
+ export function getTopupDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(TOPUP_DISCRIMINATOR);
16
+ }
17
+ export function getTopupInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([
19
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
20
+ ['amount', getU64Encoder()],
21
+ ]), (value) => ({ ...value, discriminator: TOPUP_DISCRIMINATOR }));
22
+ }
23
+ export function getTopupInstructionDataDecoder() {
24
+ return getStructDecoder([
25
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
26
+ ['amount', getU64Decoder()],
27
+ ]);
28
+ }
29
+ export function getTopupInstructionDataCodec() {
30
+ return combineCodec(getTopupInstructionDataEncoder(), getTopupInstructionDataDecoder());
31
+ }
32
+ export function getTopupInstruction(input, config) {
33
+ // Program address.
34
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
35
+ // Original accounts.
36
+ const originalAccounts = {
37
+ user: { value: input.user ?? null, isWritable: true },
38
+ vault: { value: input.vault ?? null, isWritable: true },
39
+ stake: { value: input.stake ?? null, isWritable: true },
40
+ authority: { value: input.authority ?? null, isWritable: false },
41
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
42
+ };
43
+ const accounts = originalAccounts;
44
+ // Original args.
45
+ const args = { ...input };
46
+ // Resolve default values.
47
+ if (!accounts.tokenProgram.value) {
48
+ accounts.tokenProgram.value =
49
+ 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
50
+ }
51
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
52
+ const instruction = {
53
+ accounts: [
54
+ getAccountMeta(accounts.user),
55
+ getAccountMeta(accounts.vault),
56
+ getAccountMeta(accounts.stake),
57
+ getAccountMeta(accounts.authority),
58
+ getAccountMeta(accounts.tokenProgram),
59
+ ],
60
+ programAddress,
61
+ data: getTopupInstructionDataEncoder().encode(args),
62
+ };
63
+ return instruction;
64
+ }
65
+ export function parseTopupInstruction(instruction) {
66
+ if (instruction.accounts.length < 5) {
67
+ // TODO: Coded error.
68
+ throw new Error('Not enough accounts');
69
+ }
70
+ let accountIndex = 0;
71
+ const getNextAccount = () => {
72
+ const accountMeta = instruction.accounts[accountIndex];
73
+ accountIndex += 1;
74
+ return accountMeta;
75
+ };
76
+ return {
77
+ programAddress: instruction.programAddress,
78
+ accounts: {
79
+ user: getNextAccount(),
80
+ vault: getNextAccount(),
81
+ stake: getNextAccount(),
82
+ authority: getNextAccount(),
83
+ tokenProgram: getNextAccount(),
84
+ },
85
+ data: getTopupInstructionDataDecoder().decode(instruction.data),
86
+ };
87
+ }