@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,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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
9
+ export const SETTINGS_ACCOUNT_DISCRIMINATOR = new Uint8Array([
10
+ 63, 89, 203, 155, 76, 237, 115, 58,
11
+ ]);
12
+ export function getSettingsAccountDiscriminatorBytes() {
13
+ return fixEncoderSize(getBytesEncoder(), 8).encode(SETTINGS_ACCOUNT_DISCRIMINATOR);
14
+ }
15
+ export function getSettingsAccountEncoder() {
16
+ return transformEncoder(getStructEncoder([
17
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
18
+ ['authority', getAddressEncoder()],
19
+ ['tokenAccount', getAddressEncoder()],
20
+ ]), (value) => ({ ...value, discriminator: SETTINGS_ACCOUNT_DISCRIMINATOR }));
21
+ }
22
+ export function getSettingsAccountDecoder() {
23
+ return getStructDecoder([
24
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
25
+ ['authority', getAddressDecoder()],
26
+ ['tokenAccount', getAddressDecoder()],
27
+ ]);
28
+ }
29
+ export function getSettingsAccountCodec() {
30
+ return combineCodec(getSettingsAccountEncoder(), getSettingsAccountDecoder());
31
+ }
32
+ export function decodeSettingsAccount(encodedAccount) {
33
+ return decodeAccount(encodedAccount, getSettingsAccountDecoder());
34
+ }
35
+ export async function fetchSettingsAccount(rpc, address, config) {
36
+ const maybeAccount = await fetchMaybeSettingsAccount(rpc, address, config);
37
+ assertAccountExists(maybeAccount);
38
+ return maybeAccount;
39
+ }
40
+ export async function fetchMaybeSettingsAccount(rpc, address, config) {
41
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
42
+ return decodeSettingsAccount(maybeAccount);
43
+ }
44
+ export async function fetchAllSettingsAccount(rpc, addresses, config) {
45
+ const maybeAccounts = await fetchAllMaybeSettingsAccount(rpc, addresses, config);
46
+ assertAccountsExist(maybeAccounts);
47
+ return maybeAccounts;
48
+ }
49
+ export async function fetchAllMaybeSettingsAccount(rpc, addresses, config) {
50
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
51
+ return maybeAccounts.map((maybeAccount) => decodeSettingsAccount(maybeAccount));
52
+ }
53
+ export function getSettingsAccountSize() {
54
+ return 72;
55
+ }
@@ -0,0 +1,39 @@
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 { fetchEncodedAccount, fetchEncodedAccounts, type Account, type Address, type Codec, type Decoder, type EncodedAccount, type Encoder, type FetchAccountConfig, type FetchAccountsConfig, type MaybeAccount, type MaybeEncodedAccount, type ReadonlyUint8Array } from '@solana/kit';
9
+ export declare const STAKE_ACCOUNT_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
10
+ export declare function getStakeAccountDiscriminatorBytes(): ReadonlyUint8Array;
11
+ export type StakeAccount = {
12
+ discriminator: ReadonlyUint8Array;
13
+ amount: bigint;
14
+ authority: Address;
15
+ duration: bigint;
16
+ timeUnstake: bigint;
17
+ vault: Address;
18
+ vaultBump: number;
19
+ xnos: bigint;
20
+ };
21
+ export type StakeAccountArgs = {
22
+ amount: number | bigint;
23
+ authority: Address;
24
+ duration: number | bigint;
25
+ timeUnstake: number | bigint;
26
+ vault: Address;
27
+ vaultBump: number;
28
+ xnos: number | bigint;
29
+ };
30
+ export declare function getStakeAccountEncoder(): Encoder<StakeAccountArgs>;
31
+ export declare function getStakeAccountDecoder(): Decoder<StakeAccount>;
32
+ export declare function getStakeAccountCodec(): Codec<StakeAccountArgs, StakeAccount>;
33
+ export declare function decodeStakeAccount<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<StakeAccount, TAddress>;
34
+ export declare function decodeStakeAccount<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<StakeAccount, TAddress>;
35
+ export declare function fetchStakeAccount<TAddress extends string = string>(rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig): Promise<Account<StakeAccount, TAddress>>;
36
+ export declare function fetchMaybeStakeAccount<TAddress extends string = string>(rpc: Parameters<typeof fetchEncodedAccount>[0], address: Address<TAddress>, config?: FetchAccountConfig): Promise<MaybeAccount<StakeAccount, TAddress>>;
37
+ export declare function fetchAllStakeAccount(rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig): Promise<Account<StakeAccount>[]>;
38
+ export declare function fetchAllMaybeStakeAccount(rpc: Parameters<typeof fetchEncodedAccounts>[0], addresses: Array<Address>, config?: FetchAccountsConfig): Promise<MaybeAccount<StakeAccount>[]>;
39
+ export declare function getStakeAccountSize(): number;
@@ -0,0 +1,65 @@
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 { assertAccountExists, assertAccountsExist, combineCodec, decodeAccount, fetchEncodedAccount, fetchEncodedAccounts, fixDecoderSize, fixEncoderSize, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getStructDecoder, getStructEncoder, getU128Decoder, getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from '@solana/kit';
9
+ export const STAKE_ACCOUNT_DISCRIMINATOR = new Uint8Array([
10
+ 80, 158, 67, 124, 50, 189, 192, 255,
11
+ ]);
12
+ export function getStakeAccountDiscriminatorBytes() {
13
+ return fixEncoderSize(getBytesEncoder(), 8).encode(STAKE_ACCOUNT_DISCRIMINATOR);
14
+ }
15
+ export function getStakeAccountEncoder() {
16
+ return transformEncoder(getStructEncoder([
17
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
18
+ ['amount', getU64Encoder()],
19
+ ['authority', getAddressEncoder()],
20
+ ['duration', getU64Encoder()],
21
+ ['timeUnstake', getI64Encoder()],
22
+ ['vault', getAddressEncoder()],
23
+ ['vaultBump', getU8Encoder()],
24
+ ['xnos', getU128Encoder()],
25
+ ]), (value) => ({ ...value, discriminator: STAKE_ACCOUNT_DISCRIMINATOR }));
26
+ }
27
+ export function getStakeAccountDecoder() {
28
+ return getStructDecoder([
29
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
30
+ ['amount', getU64Decoder()],
31
+ ['authority', getAddressDecoder()],
32
+ ['duration', getU64Decoder()],
33
+ ['timeUnstake', getI64Decoder()],
34
+ ['vault', getAddressDecoder()],
35
+ ['vaultBump', getU8Decoder()],
36
+ ['xnos', getU128Decoder()],
37
+ ]);
38
+ }
39
+ export function getStakeAccountCodec() {
40
+ return combineCodec(getStakeAccountEncoder(), getStakeAccountDecoder());
41
+ }
42
+ export function decodeStakeAccount(encodedAccount) {
43
+ return decodeAccount(encodedAccount, getStakeAccountDecoder());
44
+ }
45
+ export async function fetchStakeAccount(rpc, address, config) {
46
+ const maybeAccount = await fetchMaybeStakeAccount(rpc, address, config);
47
+ assertAccountExists(maybeAccount);
48
+ return maybeAccount;
49
+ }
50
+ export async function fetchMaybeStakeAccount(rpc, address, config) {
51
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
52
+ return decodeStakeAccount(maybeAccount);
53
+ }
54
+ export async function fetchAllStakeAccount(rpc, addresses, config) {
55
+ const maybeAccounts = await fetchAllMaybeStakeAccount(rpc, addresses, config);
56
+ assertAccountsExist(maybeAccounts);
57
+ return maybeAccounts;
58
+ }
59
+ export async function fetchAllMaybeStakeAccount(rpc, addresses, config) {
60
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
61
+ return maybeAccounts.map((maybeAccount) => decodeStakeAccount(maybeAccount));
62
+ }
63
+ export function getStakeAccountSize() {
64
+ return 113;
65
+ }
@@ -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,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 SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, type SolanaError } from '@solana/kit';
9
+ /** AmountNotEnough: This amount is not enough. */
10
+ export declare const NOSANA_STAKING_ERROR__AMOUNT_NOT_ENOUGH = 6000;
11
+ /** AlreadyInitialized: This stake is already running. */
12
+ export declare const NOSANA_STAKING_ERROR__ALREADY_INITIALIZED = 6001;
13
+ /** AlreadyClaimed: This stake is already claimed. */
14
+ export declare const NOSANA_STAKING_ERROR__ALREADY_CLAIMED = 6002;
15
+ /** AlreadyStaked: This stake is already staked. */
16
+ export declare const NOSANA_STAKING_ERROR__ALREADY_STAKED = 6003;
17
+ /** AlreadyUnstaked: This stake is already unstaked. */
18
+ export declare const NOSANA_STAKING_ERROR__ALREADY_UNSTAKED = 6004;
19
+ /** NotUnstaked: This stake is not yet unstaked. */
20
+ export declare const NOSANA_STAKING_ERROR__NOT_UNSTAKED = 6005;
21
+ /** Locked: This stake is still locked. */
22
+ export declare const NOSANA_STAKING_ERROR__LOCKED = 6006;
23
+ /** DurationTooShort: This stake duration is not long enough. */
24
+ export declare const NOSANA_STAKING_ERROR__DURATION_TOO_SHORT = 6007;
25
+ /** DurationTooLong: This stake duration is too long. */
26
+ export declare const NOSANA_STAKING_ERROR__DURATION_TOO_LONG = 6008;
27
+ /** DoesNotExist: This stake account does not exist. */
28
+ export declare const NOSANA_STAKING_ERROR__DOES_NOT_EXIST = 6009;
29
+ /** Decreased: This stake is not allowed to decrease. */
30
+ export declare const NOSANA_STAKING_ERROR__DECREASED = 6010;
31
+ /** HasReward: This stake still has a reward account. */
32
+ export declare const NOSANA_STAKING_ERROR__HAS_REWARD = 6011;
33
+ /** InvalidStakeAccount: This stake does not belong to the authority. */
34
+ export declare const NOSANA_STAKING_ERROR__INVALID_STAKE_ACCOUNT = 6012;
35
+ export type NosanaStakingError = typeof NOSANA_STAKING_ERROR__ALREADY_CLAIMED | typeof NOSANA_STAKING_ERROR__ALREADY_INITIALIZED | typeof NOSANA_STAKING_ERROR__ALREADY_STAKED | typeof NOSANA_STAKING_ERROR__ALREADY_UNSTAKED | typeof NOSANA_STAKING_ERROR__AMOUNT_NOT_ENOUGH | typeof NOSANA_STAKING_ERROR__DECREASED | typeof NOSANA_STAKING_ERROR__DOES_NOT_EXIST | typeof NOSANA_STAKING_ERROR__DURATION_TOO_LONG | typeof NOSANA_STAKING_ERROR__DURATION_TOO_SHORT | typeof NOSANA_STAKING_ERROR__HAS_REWARD | typeof NOSANA_STAKING_ERROR__INVALID_STAKE_ACCOUNT | typeof NOSANA_STAKING_ERROR__LOCKED | typeof NOSANA_STAKING_ERROR__NOT_UNSTAKED;
36
+ export declare function getNosanaStakingErrorMessage(code: NosanaStakingError): string;
37
+ export declare function isNosanaStakingError<TProgramErrorCode extends NosanaStakingError>(error: unknown, transactionMessage: {
38
+ instructions: Record<number, {
39
+ programAddress: Address;
40
+ }>;
41
+ }, code?: TProgramErrorCode): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & Readonly<{
42
+ context: Readonly<{
43
+ code: TProgramErrorCode;
44
+ }>;
45
+ }>;
@@ -0,0 +1,62 @@
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 { isProgramError, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ /** AmountNotEnough: This amount is not enough. */
11
+ export const NOSANA_STAKING_ERROR__AMOUNT_NOT_ENOUGH = 0x1770; // 6000
12
+ /** AlreadyInitialized: This stake is already running. */
13
+ export const NOSANA_STAKING_ERROR__ALREADY_INITIALIZED = 0x1771; // 6001
14
+ /** AlreadyClaimed: This stake is already claimed. */
15
+ export const NOSANA_STAKING_ERROR__ALREADY_CLAIMED = 0x1772; // 6002
16
+ /** AlreadyStaked: This stake is already staked. */
17
+ export const NOSANA_STAKING_ERROR__ALREADY_STAKED = 0x1773; // 6003
18
+ /** AlreadyUnstaked: This stake is already unstaked. */
19
+ export const NOSANA_STAKING_ERROR__ALREADY_UNSTAKED = 0x1774; // 6004
20
+ /** NotUnstaked: This stake is not yet unstaked. */
21
+ export const NOSANA_STAKING_ERROR__NOT_UNSTAKED = 0x1775; // 6005
22
+ /** Locked: This stake is still locked. */
23
+ export const NOSANA_STAKING_ERROR__LOCKED = 0x1776; // 6006
24
+ /** DurationTooShort: This stake duration is not long enough. */
25
+ export const NOSANA_STAKING_ERROR__DURATION_TOO_SHORT = 0x1777; // 6007
26
+ /** DurationTooLong: This stake duration is too long. */
27
+ export const NOSANA_STAKING_ERROR__DURATION_TOO_LONG = 0x1778; // 6008
28
+ /** DoesNotExist: This stake account does not exist. */
29
+ export const NOSANA_STAKING_ERROR__DOES_NOT_EXIST = 0x1779; // 6009
30
+ /** Decreased: This stake is not allowed to decrease. */
31
+ export const NOSANA_STAKING_ERROR__DECREASED = 0x177a; // 6010
32
+ /** HasReward: This stake still has a reward account. */
33
+ export const NOSANA_STAKING_ERROR__HAS_REWARD = 0x177b; // 6011
34
+ /** InvalidStakeAccount: This stake does not belong to the authority. */
35
+ export const NOSANA_STAKING_ERROR__INVALID_STAKE_ACCOUNT = 0x177c; // 6012
36
+ let nosanaStakingErrorMessages;
37
+ if (process.env.NODE_ENV !== 'production') {
38
+ nosanaStakingErrorMessages = {
39
+ [NOSANA_STAKING_ERROR__ALREADY_CLAIMED]: `This stake is already claimed.`,
40
+ [NOSANA_STAKING_ERROR__ALREADY_INITIALIZED]: `This stake is already running.`,
41
+ [NOSANA_STAKING_ERROR__ALREADY_STAKED]: `This stake is already staked.`,
42
+ [NOSANA_STAKING_ERROR__ALREADY_UNSTAKED]: `This stake is already unstaked.`,
43
+ [NOSANA_STAKING_ERROR__AMOUNT_NOT_ENOUGH]: `This amount is not enough.`,
44
+ [NOSANA_STAKING_ERROR__DECREASED]: `This stake is not allowed to decrease.`,
45
+ [NOSANA_STAKING_ERROR__DOES_NOT_EXIST]: `This stake account does not exist.`,
46
+ [NOSANA_STAKING_ERROR__DURATION_TOO_LONG]: `This stake duration is too long.`,
47
+ [NOSANA_STAKING_ERROR__DURATION_TOO_SHORT]: `This stake duration is not long enough.`,
48
+ [NOSANA_STAKING_ERROR__HAS_REWARD]: `This stake still has a reward account.`,
49
+ [NOSANA_STAKING_ERROR__INVALID_STAKE_ACCOUNT]: `This stake does not belong to the authority.`,
50
+ [NOSANA_STAKING_ERROR__LOCKED]: `This stake is still locked.`,
51
+ [NOSANA_STAKING_ERROR__NOT_UNSTAKED]: `This stake is not yet unstaked.`,
52
+ };
53
+ }
54
+ export function getNosanaStakingErrorMessage(code) {
55
+ if (process.env.NODE_ENV !== 'production') {
56
+ return nosanaStakingErrorMessages[code];
57
+ }
58
+ return 'Error message not available in production bundles.';
59
+ }
60
+ export function isNosanaStakingError(error, transactionMessage, code) {
61
+ return isProgramError(error, transactionMessage, NOSANA_STAKING_PROGRAM_ADDRESS, code);
62
+ }
@@ -0,0 +1,11 @@
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 './accounts';
9
+ export * from './errors';
10
+ export * from './instructions';
11
+ export * from './programs';
@@ -0,0 +1,11 @@
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 './accounts';
9
+ export * from './errors';
10
+ export * from './instructions';
11
+ export * from './programs';
@@ -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 CLOSE_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getCloseDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type CloseInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountUser extends string | IAccountMeta<string> = string, TAccountStake extends string | IAccountMeta<string> = string, TAccountVault 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
+ TAccountStake extends string ? WritableAccount<TAccountStake> : TAccountStake,
15
+ TAccountVault extends string ? WritableAccount<TAccountVault> : TAccountVault,
16
+ TAccountAuthority extends string ? WritableSignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
17
+ TAccountTokenProgram extends string ? ReadonlyAccount<TAccountTokenProgram> : TAccountTokenProgram,
18
+ ...TRemainingAccounts
19
+ ]>;
20
+ export type CloseInstructionData = {
21
+ discriminator: ReadonlyUint8Array;
22
+ };
23
+ export type CloseInstructionDataArgs = {};
24
+ export declare function getCloseInstructionDataEncoder(): Encoder<CloseInstructionDataArgs>;
25
+ export declare function getCloseInstructionDataDecoder(): Decoder<CloseInstructionData>;
26
+ export declare function getCloseInstructionDataCodec(): Codec<CloseInstructionDataArgs, CloseInstructionData>;
27
+ export type CloseInput<TAccountUser extends string = string, TAccountStake extends string = string, TAccountVault extends string = string, TAccountAuthority extends string = string, TAccountTokenProgram extends string = string> = {
28
+ user: Address<TAccountUser>;
29
+ stake: Address<TAccountStake>;
30
+ vault: Address<TAccountVault>;
31
+ authority: TransactionSigner<TAccountAuthority>;
32
+ tokenProgram?: Address<TAccountTokenProgram>;
33
+ };
34
+ export declare function getCloseInstruction<TAccountUser extends string, TAccountStake extends string, TAccountVault extends string, TAccountAuthority extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: CloseInput<TAccountUser, TAccountStake, TAccountVault, TAccountAuthority, TAccountTokenProgram>, config?: {
35
+ programAddress?: TProgramAddress;
36
+ }): CloseInstruction<TProgramAddress, TAccountUser, TAccountStake, TAccountVault, TAccountAuthority, TAccountTokenProgram>;
37
+ export type ParsedCloseInstruction<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
+ stake: TAccountMetas[1];
42
+ vault: TAccountMetas[2];
43
+ authority: TAccountMetas[3];
44
+ tokenProgram: TAccountMetas[4];
45
+ };
46
+ data: CloseInstructionData;
47
+ };
48
+ export declare function parseCloseInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedCloseInstruction<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 CLOSE_DISCRIMINATOR = new Uint8Array([
12
+ 98, 165, 201, 177, 108, 65, 206, 96,
13
+ ]);
14
+ export function getCloseDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_DISCRIMINATOR);
16
+ }
17
+ export function getCloseInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_DISCRIMINATOR }));
19
+ }
20
+ export function getCloseInstructionDataDecoder() {
21
+ return getStructDecoder([
22
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
23
+ ]);
24
+ }
25
+ export function getCloseInstructionDataCodec() {
26
+ return combineCodec(getCloseInstructionDataEncoder(), getCloseInstructionDataDecoder());
27
+ }
28
+ export function getCloseInstruction(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
+ stake: { value: input.stake ?? null, isWritable: true },
35
+ vault: { value: input.vault ?? 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.stake),
50
+ getAccountMeta(accounts.vault),
51
+ getAccountMeta(accounts.authority),
52
+ getAccountMeta(accounts.tokenProgram),
53
+ ],
54
+ programAddress,
55
+ data: getCloseInstructionDataEncoder().encode({}),
56
+ };
57
+ return instruction;
58
+ }
59
+ export function parseCloseInstruction(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
+ stake: getNextAccount(),
75
+ vault: getNextAccount(),
76
+ authority: getNextAccount(),
77
+ tokenProgram: getNextAccount(),
78
+ },
79
+ data: getCloseInstructionDataDecoder().decode(instruction.data),
80
+ };
81
+ }
@@ -0,0 +1,43 @@
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 EXTEND_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getExtendDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type ExtendInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountStake 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
+ TAccountAuthority extends string ? ReadonlySignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
15
+ ...TRemainingAccounts
16
+ ]>;
17
+ export type ExtendInstructionData = {
18
+ discriminator: ReadonlyUint8Array;
19
+ duration: bigint;
20
+ };
21
+ export type ExtendInstructionDataArgs = {
22
+ duration: number | bigint;
23
+ };
24
+ export declare function getExtendInstructionDataEncoder(): Encoder<ExtendInstructionDataArgs>;
25
+ export declare function getExtendInstructionDataDecoder(): Decoder<ExtendInstructionData>;
26
+ export declare function getExtendInstructionDataCodec(): Codec<ExtendInstructionDataArgs, ExtendInstructionData>;
27
+ export type ExtendInput<TAccountStake extends string = string, TAccountAuthority extends string = string> = {
28
+ stake: Address<TAccountStake>;
29
+ authority: TransactionSigner<TAccountAuthority>;
30
+ duration: ExtendInstructionDataArgs['duration'];
31
+ };
32
+ export declare function getExtendInstruction<TAccountStake extends string, TAccountAuthority extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: ExtendInput<TAccountStake, TAccountAuthority>, config?: {
33
+ programAddress?: TProgramAddress;
34
+ }): ExtendInstruction<TProgramAddress, TAccountStake, TAccountAuthority>;
35
+ export type ParsedExtendInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
36
+ programAddress: Address<TProgram>;
37
+ accounts: {
38
+ stake: TAccountMetas[0];
39
+ authority: TAccountMetas[1];
40
+ };
41
+ data: ExtendInstructionData;
42
+ };
43
+ export declare function parseExtendInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedExtendInstruction<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, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ import { getAccountMetaFactory } from '../shared';
11
+ export const EXTEND_DISCRIMINATOR = new Uint8Array([
12
+ 228, 127, 0, 1, 227, 154, 54, 168,
13
+ ]);
14
+ export function getExtendDiscriminatorBytes() {
15
+ return fixEncoderSize(getBytesEncoder(), 8).encode(EXTEND_DISCRIMINATOR);
16
+ }
17
+ export function getExtendInstructionDataEncoder() {
18
+ return transformEncoder(getStructEncoder([
19
+ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
20
+ ['duration', getU64Encoder()],
21
+ ]), (value) => ({ ...value, discriminator: EXTEND_DISCRIMINATOR }));
22
+ }
23
+ export function getExtendInstructionDataDecoder() {
24
+ return getStructDecoder([
25
+ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
26
+ ['duration', getU64Decoder()],
27
+ ]);
28
+ }
29
+ export function getExtendInstructionDataCodec() {
30
+ return combineCodec(getExtendInstructionDataEncoder(), getExtendInstructionDataDecoder());
31
+ }
32
+ export function getExtendInstruction(input, config) {
33
+ // Program address.
34
+ const programAddress = config?.programAddress ?? NOSANA_STAKING_PROGRAM_ADDRESS;
35
+ // Original accounts.
36
+ const originalAccounts = {
37
+ stake: { value: input.stake ?? null, isWritable: true },
38
+ authority: { value: input.authority ?? null, isWritable: false },
39
+ };
40
+ const accounts = originalAccounts;
41
+ // Original args.
42
+ const args = { ...input };
43
+ const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
44
+ const instruction = {
45
+ accounts: [
46
+ getAccountMeta(accounts.stake),
47
+ getAccountMeta(accounts.authority),
48
+ ],
49
+ programAddress,
50
+ data: getExtendInstructionDataEncoder().encode(args),
51
+ };
52
+ return instruction;
53
+ }
54
+ export function parseExtendInstruction(instruction) {
55
+ if (instruction.accounts.length < 2) {
56
+ // TODO: Coded error.
57
+ throw new Error('Not enough accounts');
58
+ }
59
+ let accountIndex = 0;
60
+ const getNextAccount = () => {
61
+ const accountMeta = instruction.accounts[accountIndex];
62
+ accountIndex += 1;
63
+ return accountMeta;
64
+ };
65
+ return {
66
+ programAddress: instruction.programAddress,
67
+ accounts: {
68
+ stake: getNextAccount(),
69
+ authority: getNextAccount(),
70
+ },
71
+ data: getExtendInstructionDataDecoder().decode(instruction.data),
72
+ };
73
+ }
@@ -0,0 +1,17 @@
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 './close';
9
+ export * from './extend';
10
+ export * from './init';
11
+ export * from './restake';
12
+ export * from './slash';
13
+ export * from './stake';
14
+ export * from './topup';
15
+ export * from './unstake';
16
+ export * from './updateSettings';
17
+ export * from './withdraw';
@@ -0,0 +1,17 @@
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 './close';
9
+ export * from './extend';
10
+ export * from './init';
11
+ export * from './restake';
12
+ export * from './slash';
13
+ export * from './stake';
14
+ export * from './topup';
15
+ export * from './unstake';
16
+ export * from './updateSettings';
17
+ export * from './withdraw';
@@ -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 ReadonlyUint8Array, type TransactionSigner, type WritableAccount, type WritableSignerAccount } from '@solana/kit';
9
+ import { NOSANA_STAKING_PROGRAM_ADDRESS } from '../programs';
10
+ export declare const INIT_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
11
+ export declare function getInitDiscriminatorBytes(): ReadonlyUint8Array;
12
+ export type InitInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountSettings extends string | IAccountMeta<string> = string, TAccountAuthority extends string | IAccountMeta<string> = string, TAccountSystemProgram extends string | IAccountMeta<string> = '11111111111111111111111111111111', TAccountRent extends string | IAccountMeta<string> = 'SysvarRent111111111111111111111111111111111', TRemainingAccounts extends readonly IAccountMeta<string>[] = []> = IInstruction<TProgram> & IInstructionWithData<Uint8Array> & IInstructionWithAccounts<[
13
+ TAccountSettings extends string ? WritableAccount<TAccountSettings> : TAccountSettings,
14
+ TAccountAuthority extends string ? WritableSignerAccount<TAccountAuthority> & IAccountSignerMeta<TAccountAuthority> : TAccountAuthority,
15
+ TAccountSystemProgram extends string ? ReadonlyAccount<TAccountSystemProgram> : TAccountSystemProgram,
16
+ TAccountRent extends string ? ReadonlyAccount<TAccountRent> : TAccountRent,
17
+ ...TRemainingAccounts
18
+ ]>;
19
+ export type InitInstructionData = {
20
+ discriminator: ReadonlyUint8Array;
21
+ };
22
+ export type InitInstructionDataArgs = {};
23
+ export declare function getInitInstructionDataEncoder(): Encoder<InitInstructionDataArgs>;
24
+ export declare function getInitInstructionDataDecoder(): Decoder<InitInstructionData>;
25
+ export declare function getInitInstructionDataCodec(): Codec<InitInstructionDataArgs, InitInstructionData>;
26
+ export type InitInput<TAccountSettings extends string = string, TAccountAuthority extends string = string, TAccountSystemProgram extends string = string, TAccountRent extends string = string> = {
27
+ settings: Address<TAccountSettings>;
28
+ authority: TransactionSigner<TAccountAuthority>;
29
+ systemProgram?: Address<TAccountSystemProgram>;
30
+ rent?: Address<TAccountRent>;
31
+ };
32
+ export declare function getInitInstruction<TAccountSettings extends string, TAccountAuthority extends string, TAccountSystemProgram extends string, TAccountRent extends string, TProgramAddress extends Address = typeof NOSANA_STAKING_PROGRAM_ADDRESS>(input: InitInput<TAccountSettings, TAccountAuthority, TAccountSystemProgram, TAccountRent>, config?: {
33
+ programAddress?: TProgramAddress;
34
+ }): InitInstruction<TProgramAddress, TAccountSettings, TAccountAuthority, TAccountSystemProgram, TAccountRent>;
35
+ export type ParsedInitInstruction<TProgram extends string = typeof NOSANA_STAKING_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[]> = {
36
+ programAddress: Address<TProgram>;
37
+ accounts: {
38
+ settings: TAccountMetas[0];
39
+ authority: TAccountMetas[1];
40
+ systemProgram: TAccountMetas[2];
41
+ rent: TAccountMetas[3];
42
+ };
43
+ data: InitInstructionData;
44
+ };
45
+ export declare function parseInitInstruction<TProgram extends string, TAccountMetas extends readonly IAccountMeta[]>(instruction: IInstruction<TProgram> & IInstructionWithAccounts<TAccountMetas> & IInstructionWithData<Uint8Array>): ParsedInitInstruction<TProgram, TAccountMetas>;