@nosana/kit 0.1.6 → 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 (86) 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 +3 -1
  7. package/dist/config/utils.d.ts +1 -1
  8. package/dist/config/utils.js +14 -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 +14 -4
  61. package/dist/index.js +20 -136
  62. package/dist/ipfs/IPFS.d.ts +33 -2
  63. package/dist/ipfs/IPFS.js +110 -5
  64. package/dist/programs/BaseProgram.d.ts +1 -1
  65. package/dist/programs/BaseProgram.js +3 -7
  66. package/dist/programs/JobsProgram.d.ts +37 -37
  67. package/dist/programs/JobsProgram.js +63 -67
  68. package/dist/programs/StakeProgram.d.ts +29 -0
  69. package/dist/programs/StakeProgram.js +91 -0
  70. package/dist/services/NosService.d.ts +48 -0
  71. package/dist/services/NosService.js +134 -0
  72. package/dist/{solana/SolanaUtils.d.ts → services/SolanaService.d.ts} +5 -5
  73. package/dist/{solana/SolanaUtils.js → services/SolanaService.js} +17 -7
  74. package/dist/utils/index.d.ts +2 -1
  75. package/dist/utils/index.js +2 -0
  76. package/dist/utils/walletConverter.d.ts +9 -0
  77. package/dist/utils/walletConverter.js +141 -0
  78. package/eslint.config.js +49 -0
  79. package/examples/node/README.md +115 -0
  80. package/examples/node/nos-service.ts +117 -0
  81. package/examples/node/package.json +3 -1
  82. package/examples/node/retrieve.ts +2 -2
  83. package/examples/node/stake-program.ts +84 -0
  84. package/package.json +13 -8
  85. package/scripts/generate-clients.ts +20 -7
  86. package/vitest.config.ts +31 -0
@@ -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
+ }
@@ -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 ReadonlyAccount, type ReadonlySignerAccount, type ReadonlyUint8Array, type TransactionSigner, type WritableAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const UNSTAKE_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getUnstakeDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type UnstakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountStake extends string | IAccountMeta<string> = string, TAccountReward extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
14
+ TAccountReward extends string ? ReadonlyAccount<TAccountReward> : TAccountReward,
15
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
16
+ ...TRemainingAccounts
17
+ ]>;
18
+ export type UnstakeInstructionData = {
19
+ discriminator: ReadonlyUint8Array;
20
+ };
21
+ export type UnstakeInstructionDataArgs = {};
22
+ export declare function getUnstakeInstructionDataEncoder(): Encoder<UnstakeInstructionDataArgs>;
23
+ export declare function getUnstakeInstructionDataDecoder(): Decoder<UnstakeInstructionData>;
24
+ export declare function getUnstakeInstructionDataCodec(): Codec<UnstakeInstructionDataArgs, UnstakeInstructionData>;
25
+ export type UnstakeInput<TAccountStake extends string = string, TAccountReward extends string = string, TAccountAuthority extends string = string> = {
26
+ stake: Address<TAccountStake>;
27
+ reward: Address<TAccountReward>;
28
+ authority: TransactionSigner<TAccountAuthority>;
29
+ };
30
+ export declare function getUnstakeInstruction<TAccountStake extends string, TAccountReward extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: UnstakeInput<TAccountStake, TAccountReward, TAccountAuthority>, config?: {
31
+ programAddress?: TProgramAddress;
32
+ }): UnstakeInstruction<TProgramAddress, TAccountStake, TAccountReward, TAccountAuthority>;
33
+ export type ParsedUnstakeInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
34
+ programAddress: Address<TProgram>;
35
+ accounts: {
36
+ stake: TAccountMetas[0];
37
+ reward: TAccountMetas[1];
38
+ authority: TAccountMetas[2];
39
+ };
40
+ data: UnstakeInstructionData;
41
+ };
42
+ export declare function parseUnstakeInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedUnstakeInstruction<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 UNSTAKE_DISCRIMINATOR = new Uint8Array([
12
+ 90, 95, 107, 42, 205, 124, 50, 225,
13
+ ]);
14
+ export function getUnstakeDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(UNSTAKE_DISCRIMINATOR);
16
+ }
17
+ export function getUnstakeInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: UNSTAKE_DISCRIMINATOR }));
19
+ }
20
+ export function getUnstakeInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getUnstakeInstructionDataCodec() {
26
+ return combineCodec(getUnstakeInstructionDataEncoder(), getUnstakeInstructionDataDecoder());
27
+ }
28
+ export function getUnstakeInstruction(input, config) {
29
+ // Program address.
30
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
31
+ // Original accounts.
32
+ const originalAccounts = {
33
+ stake: { value: input.stake ?? null, isWritable: true },
34
+ reward: { value: input.reward ?? null, isWritable: false },
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.stake),
42
+ getAccountMeta(accounts.reward),
43
+ getAccountMeta(accounts.authority),
44
+ ],
45
+ programAddress,
46
+ data: getUnstakeInstructionDataEncoder().encode({}),
47
+ };
48
+ return instruction;
49
+ }
50
+ export function parseUnstakeInstruction(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
+ stake: getNextAccount(),
65
+ reward: getNextAccount(),
66
+ authority: getNextAccount(),
67
+ },
68
+ data: getUnstakeInstructionDataDecoder().decode(instruction.data),
69
+ };
70
+ }
@@ -0,0 +1,45 @@
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 UPDATE_SETTINGS_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getUpdateSettingsDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type UpdateSettingsInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountNewAuthority extends string | IAccountMeta<string> = string, TAccountTokenAccount extends string | IAccountMeta<string> = string, TAccountSettings extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountNewAuthority extends string ? ReadonlyAccount<TAccountNewAuthority> : TAccountNewAuthority,
14
+ TAccountTokenAccount extends string ? ReadonlyAccount<TAccountTokenAccount> : TAccountTokenAccount,
15
+ TAccountSettings extends string ? WritableAccount<TAccountSettings> : TAccountSettings,
16
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
17
+ ...TRemainingAccounts
18
+ ]>;
19
+ export type UpdateSettingsInstructionData = {
20
+ discriminator: ReadonlyUint8Array;
21
+ };
22
+ export type UpdateSettingsInstructionDataArgs = {};
23
+ export declare function getUpdateSettingsInstructionDataEncoder(): Encoder<UpdateSettingsInstructionDataArgs>;
24
+ export declare function getUpdateSettingsInstructionDataDecoder(): Decoder<UpdateSettingsInstructionData>;
25
+ export declare function getUpdateSettingsInstructionDataCodec(): Codec<UpdateSettingsInstructionDataArgs, UpdateSettingsInstructionData>;
26
+ export type UpdateSettingsInput<TAccountNewAuthority extends string = string, TAccountTokenAccount extends string = string, TAccountSettings extends string = string, TAccountAuthority extends string = string> = {
27
+ newAuthority: Address<TAccountNewAuthority>;
28
+ tokenAccount: Address<TAccountTokenAccount>;
29
+ settings: Address<TAccountSettings>;
30
+ authority: TransactionSigner<TAccountAuthority>;
31
+ };
32
+ export declare function getUpdateSettingsInstruction<TAccountNewAuthority extends string, TAccountTokenAccount extends string, TAccountSettings extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: UpdateSettingsInput<TAccountNewAuthority, TAccountTokenAccount, TAccountSettings, TAccountAuthority>, config?: {
33
+ programAddress?: TProgramAddress;
34
+ }): UpdateSettingsInstruction<TProgramAddress, TAccountNewAuthority, TAccountTokenAccount, TAccountSettings, TAccountAuthority>;
35
+ export type ParsedUpdateSettingsInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
36
+ programAddress: Address<TProgram>;
37
+ accounts: {
38
+ newAuthority: TAccountMetas[0];
39
+ tokenAccount: TAccountMetas[1];
40
+ settings: TAccountMetas[2];
41
+ authority: TAccountMetas[3];
42
+ };
43
+ data: UpdateSettingsInstructionData;
44
+ };
45
+ export declare function parseUpdateSettingsInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedUpdateSettingsInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,73 @@
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 UPDATE_SETTINGS_DISCRIMINATOR = new Uint8Array([
12
+ 81, 166, 51, 213, 158, 84, 157, 108,
13
+ ]);
14
+ export function getUpdateSettingsDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_SETTINGS_DISCRIMINATOR);
16
+ }
17
+ export function getUpdateSettingsInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: UPDATE_SETTINGS_DISCRIMINATOR }));
19
+ }
20
+ export function getUpdateSettingsInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getUpdateSettingsInstructionDataCodec() {
26
+ return combineCodec(getUpdateSettingsInstructionDataEncoder(), getUpdateSettingsInstructionDataDecoder());
27
+ }
28
+ export function getUpdateSettingsInstruction(input, config) {
29
+ // Program address.
30
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
31
+ // Original accounts.
32
+ const originalAccounts = {
33
+ newAuthority: { value: input.newAuthority ?? null, isWritable: false },
34
+ tokenAccount: { value: input.tokenAccount ?? null, isWritable: false },
35
+ settings: { value: input.settings ?? null, isWritable: true },
36
+ authority: { value: input.authority ?? null, isWritable: false },
37
+ };
38
+ const accounts = originalAccounts;
39
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
40
+ const instruction = {
41
+ accounts: [
42
+ getAccountMeta(accounts.newAuthority),
43
+ getAccountMeta(accounts.tokenAccount),
44
+ getAccountMeta(accounts.settings),
45
+ getAccountMeta(accounts.authority),
46
+ ],
47
+ programAddress,
48
+ data: getUpdateSettingsInstructionDataEncoder().encode({}),
49
+ };
50
+ return instruction;
51
+ }
52
+ export function parseUpdateSettingsInstruction(instruction) {
53
+ if (instruction.accounts.length < 4) {
54
+ // TODO: Coded error.
55
+ throw new Error('Not enough accounts');
56
+ }
57
+ let accountIndex = 0;
58
+ const getNextAccount = () => {
59
+ const accountMeta = instruction.accounts[accountIndex];
60
+ accountIndex += 1;
61
+ return accountMeta;
62
+ };
63
+ return {
64
+ programAddress: instruction.programAddress,
65
+ accounts: {
66
+ newAuthority: getNextAccount(),
67
+ tokenAccount: getNextAccount(),
68
+ settings: getNextAccount(),
69
+ authority: getNextAccount(),
70
+ },
71
+ data: getUpdateSettingsInstructionDataDecoder().decode(instruction.data),
72
+ };
73
+ }
@@ -0,0 +1,48 @@
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 WITHDRAW_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getWithdrawDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type WithdrawInstruction<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 ? WritableSignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
17
+ TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram,
18
+ ...TRemainingAccounts
19
+ ]>;
20
+ export type WithdrawInstructionData = {
21
+ discriminator: ReadonlyUint8Array;
22
+ };
23
+ export type WithdrawInstructionDataArgs = {};
24
+ export declare function getWithdrawInstructionDataEncoder(): Encoder<WithdrawInstructionDataArgs>;
25
+ export declare function getWithdrawInstructionDataDecoder(): Decoder<WithdrawInstructionData>;
26
+ export declare function getWithdrawInstructionDataCodec(): Codec<WithdrawInstructionDataArgs, WithdrawInstructionData>;
27
+ export type WithdrawInput<TAccountUser extends string = string, TAccountVault extends string = string, TAccountStake extends string = string, TAccountAuthority extends string = string, TAccountTokenProgram extends string = string> = {
28
+ user: Address<TAccountUser>;
29
+ vault: Address<TAccountVault>;
30
+ stake: Address<TAccountStake>;
31
+ authority: TransactionSigner<TAccountAuthority>;
32
+ tokenProgram?: Address<TAccountTokenProgram>;
33
+ };
34
+ export declare function getWithdrawInstruction<TAccountUser extends string, TAccountVault extends string, TAccountStake extends string, TAccountAuthority extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: WithdrawInput<TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountTokenProgram>, config?: {
35
+ programAddress?: TProgramAddress;
36
+ }): WithdrawInstruction<TProgramAddress, TAccountUser, TAccountVault, TAccountStake, TAccountAuthority, TAccountTokenProgram>;
37
+ export type ParsedWithdrawInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
38
+ programAddress: Address<TProgram>;
39
+ accounts: {
40
+ user: TAccountMetas[0];
41
+ vault: TAccountMetas[1];
42
+ stake: TAccountMetas[2];
43
+ authority: TAccountMetas[3];
44
+ tokenProgram: TAccountMetas[4];
45
+ };
46
+ data: WithdrawInstructionData;
47
+ };
48
+ export declare function parseWithdrawInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedWithdrawInstruction<TProgram, TAccountMetas>;
@@ -0,0 +1,81 @@
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 WITHDRAW_DISCRIMINATOR = new Uint8Array([
12
+ 183, 18, 70, 156, 148, 109, 161, 34,
13
+ ]);
14
+ export function getWithdrawDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(WITHDRAW_DISCRIMINATOR);
16
+ }
17
+ export function getWithdrawInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: WITHDRAW_DISCRIMINATOR }));
19
+ }
20
+ export function getWithdrawInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getWithdrawInstructionDataCodec() {
26
+ return combineCodec(getWithdrawInstructionDataEncoder(), getWithdrawInstructionDataDecoder());
27
+ }
28
+ export function getWithdrawInstruction(input, config) {
29
+ // Program address.
30
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
31
+ // Original accounts.
32
+ const originalAccounts = {
33
+ user: { value: input.user ?? null, isWritable: true },
34
+ vault: { value: input.vault ?? null, isWritable: true },
35
+ stake: { value: input.stake ?? null, isWritable: true },
36
+ authority: { value: input.authority ?? null, isWritable: true },
37
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
38
+ };
39
+ const accounts = originalAccounts;
40
+ // Resolve default values.
41
+ if (!accounts.tokenProgram.value) {
42
+ accounts.tokenProgram.value =
43
+ 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
44
+ }
45
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
46
+ const instruction = {
47
+ accounts: [
48
+ getAccountMeta(accounts.user),
49
+ getAccountMeta(accounts.vault),
50
+ getAccountMeta(accounts.stake),
51
+ getAccountMeta(accounts.authority),
52
+ getAccountMeta(accounts.tokenProgram),
53
+ ],
54
+ programAddress,
55
+ data: getWithdrawInstructionDataEncoder().encode({}),
56
+ };
57
+ return instruction;
58
+ }
59
+ export function parseWithdrawInstruction(instruction) {
60
+ if (instruction.accounts.length < 5) {
61
+ // TODO: Coded error.
62
+ throw new Error('Not enough accounts');
63
+ }
64
+ let accountIndex = 0;
65
+ const getNextAccount = () => {
66
+ const accountMeta = instruction.accounts[accountIndex];
67
+ accountIndex += 1;
68
+ return accountMeta;
69
+ };
70
+ return {
71
+ programAddress: instruction.programAddress,
72
+ accounts: {
73
+ user: getNextAccount(),
74
+ vault: getNextAccount(),
75
+ stake: getNextAccount(),
76
+ authority: getNextAccount(),
77
+ tokenProgram: getNextAccount(),
78
+ },
79
+ data: getWithdrawInstructionDataDecoder().decode(instruction.data),
80
+ };
81
+ }
@@ -0,0 +1,8 @@
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
+ export * from './nosanaStaking';
@@ -0,0 +1,8 @@
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
+ export * from './nosanaStaking';
@@ -0,0 +1,53 @@
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 ReadonlyUint8Array } from '@solana/kit';
9
+ import { type ParsedCloseInstruction, type ParsedExtendInstruction, type ParsedInitInstruction, type ParsedRestakeInstruction, type ParsedSlashInstruction, type ParsedStakeInstruction, type ParsedTopupInstruction, type ParsedUnstakeInstruction, type ParsedUpdateSettingsInstruction, type ParsedWithdrawInstruction } from '../instructions';
10
+ export declare const NOSANA_STAKING_PROGRAM_ADDRESS: Address<"nosScmHY2uR24Zh751PmGj9ww9QRNHewh9H59AfrTJE">;
11
+ export declare enum NosanaStakingAccount {
12
+ SettingsAccount = 0,
13
+ StakeAccount = 1
14
+ }
15
+ export declare function identifyNosanaStakingAccount(account: {
16
+ data: ReadonlyUint8Array;
17
+ } | ReadonlyUint8Array): NosanaStakingAccount;
18
+ export declare enum NosanaStakingInstruction {
19
+ Init = 0,
20
+ Stake = 1,
21
+ Unstake = 2,
22
+ Restake = 3,
23
+ Topup = 4,
24
+ Extend = 5,
25
+ Close = 6,
26
+ Withdraw = 7,
27
+ Slash = 8,
28
+ UpdateSettings = 9
29
+ }
30
+ export declare function identifyNosanaStakingInstruction(instruction: {
31
+ data: ReadonlyUint8Array;
32
+ } | ReadonlyUint8Array): NosanaStakingInstruction;
33
+ export type ParsedNosanaStakingInstruction<TProgram extends string = 'nosScmHY2uR24Zh751PmGj9ww9QRNHewh9H59AfrTJE'> = ({
34
+ instructionType: NosanaStakingInstruction.Init;
35
+ } & ParsedInitInstruction<TProgram>) | ({
36
+ instructionType: NosanaStakingInstruction.Stake;
37
+ } & ParsedStakeInstruction<TProgram>) | ({
38
+ instructionType: NosanaStakingInstruction.Unstake;
39
+ } & ParsedUnstakeInstruction<TProgram>) | ({
40
+ instructionType: NosanaStakingInstruction.Restake;
41
+ } & ParsedRestakeInstruction<TProgram>) | ({
42
+ instructionType: NosanaStakingInstruction.Topup;
43
+ } & ParsedTopupInstruction<TProgram>) | ({
44
+ instructionType: NosanaStakingInstruction.Extend;
45
+ } & ParsedExtendInstruction<TProgram>) | ({
46
+ instructionType: NosanaStakingInstruction.Close;
47
+ } & ParsedCloseInstruction<TProgram>) | ({
48
+ instructionType: NosanaStakingInstruction.Withdraw;
49
+ } & ParsedWithdrawInstruction<TProgram>) | ({
50
+ instructionType: NosanaStakingInstruction.Slash;
51
+ } & ParsedSlashInstruction<TProgram>) | ({
52
+ instructionType: NosanaStakingInstruction.UpdateSettings;
53
+ } & ParsedUpdateSettingsInstruction<TProgram>);
@@ -0,0 +1,71 @@
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 { containsBytes, fixEncoderSize, getBytesEncoder, } from '@solana/kit';
9
+ export const NOSANA_STAKING_PROGRAM_ADDRESS = 'nosScmHY2uR24Zh751PmGj9ww9QRNHewh9H59AfrTJE';
10
+ export var NosanaStakingAccount;
11
+ (function (NosanaStakingAccount) {
12
+ NosanaStakingAccount[NosanaStakingAccount["SettingsAccount"] = 0] = "SettingsAccount";
13
+ NosanaStakingAccount[NosanaStakingAccount["StakeAccount"] = 1] = "StakeAccount";
14
+ })(NosanaStakingAccount || (NosanaStakingAccount = {}));
15
+ export function identifyNosanaStakingAccount(account) {
16
+ const data = 'data' in account ? account.data : account;
17
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([63, 89, 203, 155, 76, 237, 115, 58])), 0)) {
18
+ return NosanaStakingAccount.SettingsAccount;
19
+ }
20
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([80, 158, 67, 124, 50, 189, 192, 255])), 0)) {
21
+ return NosanaStakingAccount.StakeAccount;
22
+ }
23
+ throw new Error('The provided account could not be identified as a nosanaStaking account.');
24
+ }
25
+ export var NosanaStakingInstruction;
26
+ (function (NosanaStakingInstruction) {
27
+ NosanaStakingInstruction[NosanaStakingInstruction["Init"] = 0] = "Init";
28
+ NosanaStakingInstruction[NosanaStakingInstruction["Stake"] = 1] = "Stake";
29
+ NosanaStakingInstruction[NosanaStakingInstruction["Unstake"] = 2] = "Unstake";
30
+ NosanaStakingInstruction[NosanaStakingInstruction["Restake"] = 3] = "Restake";
31
+ NosanaStakingInstruction[NosanaStakingInstruction["Topup"] = 4] = "Topup";
32
+ NosanaStakingInstruction[NosanaStakingInstruction["Extend"] = 5] = "Extend";
33
+ NosanaStakingInstruction[NosanaStakingInstruction["Close"] = 6] = "Close";
34
+ NosanaStakingInstruction[NosanaStakingInstruction["Withdraw"] = 7] = "Withdraw";
35
+ NosanaStakingInstruction[NosanaStakingInstruction["Slash"] = 8] = "Slash";
36
+ NosanaStakingInstruction[NosanaStakingInstruction["UpdateSettings"] = 9] = "UpdateSettings";
37
+ })(NosanaStakingInstruction || (NosanaStakingInstruction = {}));
38
+ export function identifyNosanaStakingInstruction(instruction) {
39
+ const data = 'data' in instruction ? instruction.data : instruction;
40
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([220, 59, 207, 236, 108, 250, 47, 100])), 0)) {
41
+ return NosanaStakingInstruction.Init;
42
+ }
43
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([206, 176, 202, 18, 200, 209, 179, 108])), 0)) {
44
+ return NosanaStakingInstruction.Stake;
45
+ }
46
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([90, 95, 107, 42, 205, 124, 50, 225])), 0)) {
47
+ return NosanaStakingInstruction.Unstake;
48
+ }
49
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([97, 161, 241, 167, 6, 32, 213, 53])), 0)) {
50
+ return NosanaStakingInstruction.Restake;
51
+ }
52
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([126, 42, 49, 78, 225, 151, 99, 77])), 0)) {
53
+ return NosanaStakingInstruction.Topup;
54
+ }
55
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([228, 127, 0, 1, 227, 154, 54, 168])), 0)) {
56
+ return NosanaStakingInstruction.Extend;
57
+ }
58
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([98, 165, 201, 177, 108, 65, 206, 96])), 0)) {
59
+ return NosanaStakingInstruction.Close;
60
+ }
61
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([183, 18, 70, 156, 148, 109, 161, 34])), 0)) {
62
+ return NosanaStakingInstruction.Withdraw;
63
+ }
64
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([204, 141, 18, 161, 8, 177, 92, 142])), 0)) {
65
+ return NosanaStakingInstruction.Slash;
66
+ }
67
+ if (containsBytes(data, fixEncoderSize(getBytesEncoder(), 8).encode(new Uint8Array([81, 166, 51, 213, 158, 84, 157, 108])), 0)) {
68
+ return NosanaStakingInstruction.UpdateSettings;
69
+ }
70
+ throw new Error('The provided instruction could not be identified as a nosanaStaking instruction.');
71
+ }
@@ -0,0 +1,49 @@
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 IAccountMeta, type IAccountSignerMeta, type ProgramDerivedAddress, type TransactionSigner } from '@solana/kit';
9
+ /**
10
+ * Asserts that the given value is not null or undefined.
11
+ * @internal
12
+ */
13
+ export declare function expectSome<T>(value: T | null | undefined): T;
14
+ /**
15
+ * Asserts that the given value is a PublicKey.
16
+ * @internal
17
+ */
18
+ export declare function expectAddress<T extends string = string>(value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined): Address<T>;
19
+ /**
20
+ * Asserts that the given value is a PDA.
21
+ * @internal
22
+ */
23
+ export declare function expectProgramDerivedAddress<T extends string = string>(value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined): ProgramDerivedAddress<T>;
24
+ /**
25
+ * Asserts that the given value is a TransactionSigner.
26
+ * @internal
27
+ */
28
+ export declare function expectTransactionSigner<T extends string = string>(value: Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null | undefined): TransactionSigner<T>;
29
+ /**
30
+ * Defines an instruction account to resolve.
31
+ * @internal
32
+ */
33
+ export type ResolvedAccount<T extends string = string, U extends Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null = Address<T> | ProgramDerivedAddress<T> | TransactionSigner<T> | null> = {
34
+ isWritable: boolean;
35
+ value: U;
36
+ };
37
+ /**
38
+ * Defines an instruction that stores additional bytes on-chain.
39
+ * @internal
40
+ */
41
+ export type IInstructionWithByteDelta = {
42
+ byteDelta: number;
43
+ };
44
+ /**
45
+ * Get account metas and signers from resolved accounts.
46
+ * @internal
47
+ */
48
+ export declare function getAccountMetaFactory(programAddress: Address, optionalAccountStrategy: 'omitted' | 'programId'): (account: ResolvedAccount) => IAccountMeta | IAccountSignerMeta | undefined;
49
+ export declare function isTransactionSigner<TAddress extends string = string>(value: Address<TAddress> | ProgramDerivedAddress<TAddress> | TransactionSigner<TAddress>): value is TransactionSigner<TAddress>;