@solana-program/system 0.12.0 → 0.12.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.
- package/README.md +7 -9
- package/dist/src/index.js +103 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +98 -8
- package/dist/src/index.mjs.map +1 -1
- package/dist/types/generated/instructions/advanceNonceAccount.d.ts +1 -1
- package/dist/types/generated/instructions/advanceNonceAccount.d.ts.map +1 -1
- package/dist/types/generated/instructions/allocate.d.ts +1 -1
- package/dist/types/generated/instructions/allocate.d.ts.map +1 -1
- package/dist/types/generated/instructions/allocateWithSeed.d.ts +1 -1
- package/dist/types/generated/instructions/allocateWithSeed.d.ts.map +1 -1
- package/dist/types/generated/instructions/assign.d.ts +1 -1
- package/dist/types/generated/instructions/assign.d.ts.map +1 -1
- package/dist/types/generated/instructions/assignWithSeed.d.ts +1 -1
- package/dist/types/generated/instructions/assignWithSeed.d.ts.map +1 -1
- package/dist/types/generated/instructions/authorizeNonceAccount.d.ts +1 -1
- package/dist/types/generated/instructions/authorizeNonceAccount.d.ts.map +1 -1
- package/dist/types/generated/instructions/createAccount.d.ts +1 -1
- package/dist/types/generated/instructions/createAccount.d.ts.map +1 -1
- package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts +53 -0
- package/dist/types/generated/instructions/createAccountAllowPrefund.d.ts.map +1 -0
- package/dist/types/generated/instructions/createAccountWithSeed.d.ts +1 -1
- package/dist/types/generated/instructions/createAccountWithSeed.d.ts.map +1 -1
- package/dist/types/generated/instructions/index.d.ts +1 -0
- package/dist/types/generated/instructions/index.d.ts.map +1 -1
- package/dist/types/generated/instructions/initializeNonceAccount.d.ts +1 -1
- package/dist/types/generated/instructions/initializeNonceAccount.d.ts.map +1 -1
- package/dist/types/generated/instructions/transferSol.d.ts +1 -1
- package/dist/types/generated/instructions/transferSol.d.ts.map +1 -1
- package/dist/types/generated/instructions/transferSolWithSeed.d.ts +1 -1
- package/dist/types/generated/instructions/transferSolWithSeed.d.ts.map +1 -1
- package/dist/types/generated/instructions/upgradeNonceAccount.d.ts +1 -1
- package/dist/types/generated/instructions/upgradeNonceAccount.d.ts.map +1 -1
- package/dist/types/generated/instructions/withdrawNonceAccount.d.ts +1 -1
- package/dist/types/generated/instructions/withdrawNonceAccount.d.ts.map +1 -1
- package/dist/types/generated/programs/system.d.ts +8 -4
- package/dist/types/generated/programs/system.d.ts.map +1 -1
- package/package.json +31 -28
- package/src/generated/accounts/index.ts +9 -0
- package/src/generated/accounts/nonce.ts +139 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/system.ts +77 -0
- package/src/generated/index.ts +13 -0
- package/src/generated/instructions/advanceNonceAccount.ts +186 -0
- package/src/generated/instructions/allocate.ts +148 -0
- package/src/generated/instructions/allocateWithSeed.ts +189 -0
- package/src/generated/instructions/assign.ts +145 -0
- package/src/generated/instructions/assignWithSeed.ts +177 -0
- package/src/generated/instructions/authorizeNonceAccount.ts +169 -0
- package/src/generated/instructions/createAccount.ts +184 -0
- package/src/generated/instructions/createAccountAllowPrefund.ts +212 -0
- package/src/generated/instructions/createAccountWithSeed.ts +221 -0
- package/src/generated/instructions/index.ts +22 -0
- package/src/generated/instructions/initializeNonceAccount.ts +202 -0
- package/src/generated/instructions/transferSol.ts +157 -0
- package/src/generated/instructions/transferSolWithSeed.ts +191 -0
- package/src/generated/instructions/upgradeNonceAccount.ts +135 -0
- package/src/generated/instructions/withdrawNonceAccount.ts +235 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/system.ts +378 -0
- package/src/generated/types/index.ts +10 -0
- package/src/generated/types/nonceState.ts +37 -0
- package/src/generated/types/nonceVersion.ts +37 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana-program/system",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "JavaScript client for the System program",
|
|
5
|
+
"homepage": "https://github.com/solana-program/system#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/solana-program/system/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/solana-program/system.git"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"./dist/src",
|
|
16
|
+
"./dist/types",
|
|
17
|
+
"./src/"
|
|
18
|
+
],
|
|
19
|
+
"type": "commonjs",
|
|
5
20
|
"sideEffects": false,
|
|
6
|
-
"module": "./dist/src/index.mjs",
|
|
7
21
|
"main": "./dist/src/index.js",
|
|
22
|
+
"module": "./dist/src/index.mjs",
|
|
8
23
|
"types": "./dist/types/index.d.ts",
|
|
9
|
-
"type": "commonjs",
|
|
10
24
|
"exports": {
|
|
11
25
|
".": {
|
|
12
26
|
"types": "./dist/types/index.d.ts",
|
|
@@ -14,47 +28,36 @@
|
|
|
14
28
|
"require": "./dist/src/index.js"
|
|
15
29
|
}
|
|
16
30
|
},
|
|
17
|
-
"files": [
|
|
18
|
-
"./dist/src",
|
|
19
|
-
"./dist/types"
|
|
20
|
-
],
|
|
21
31
|
"publishConfig": {
|
|
22
32
|
"access": "public",
|
|
23
33
|
"registry": "https://registry.npmjs.org"
|
|
24
34
|
},
|
|
25
|
-
"license": "Apache-2.0",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/solana-program/system.git"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/solana-program/system/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/solana-program/system#readme",
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"@solana/kit": "^6.1.0"
|
|
36
|
-
},
|
|
37
35
|
"devDependencies": {
|
|
38
|
-
"@solana
|
|
39
|
-
"@solana/kit
|
|
40
|
-
"@solana/kit": "^
|
|
36
|
+
"@solana-config/oxc": "^0.1.1",
|
|
37
|
+
"@solana/kit": "^6.4.0",
|
|
38
|
+
"@solana/kit-plugin-litesvm": "^0.10.0",
|
|
39
|
+
"@solana/kit-plugin-signer": "^0.10.0",
|
|
41
40
|
"@types/node": "^24",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"oxfmt": "^0.48.0",
|
|
42
|
+
"oxlint": "^1.63.0",
|
|
43
|
+
"oxlint-tsgolint": "^0.23.0",
|
|
44
44
|
"rimraf": "^6.1.2",
|
|
45
45
|
"tsup": "^8.1.2",
|
|
46
46
|
"typedoc": "^0.28.15",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"vitest": "^4.0.15"
|
|
49
49
|
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@solana/kit": "^6.4.0"
|
|
52
|
+
},
|
|
50
53
|
"scripts": {
|
|
51
54
|
"build": "rimraf dist && tsup && tsc -p ./tsconfig.declarations.json",
|
|
52
55
|
"build:docs": "typedoc",
|
|
53
56
|
"dev": "vitest",
|
|
54
57
|
"test": "vitest run",
|
|
55
|
-
"lint": "
|
|
56
|
-
"lint:fix": "
|
|
57
|
-
"format": "
|
|
58
|
-
"format:fix": "
|
|
58
|
+
"lint": "oxlint",
|
|
59
|
+
"lint:fix": "oxlint --fix",
|
|
60
|
+
"format": "oxfmt --check",
|
|
61
|
+
"format:fix": "oxfmt"
|
|
59
62
|
}
|
|
60
63
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
|
|
9
|
+
import {
|
|
10
|
+
assertAccountExists,
|
|
11
|
+
assertAccountsExist,
|
|
12
|
+
combineCodec,
|
|
13
|
+
decodeAccount,
|
|
14
|
+
fetchEncodedAccount,
|
|
15
|
+
fetchEncodedAccounts,
|
|
16
|
+
getAddressDecoder,
|
|
17
|
+
getAddressEncoder,
|
|
18
|
+
getStructDecoder,
|
|
19
|
+
getStructEncoder,
|
|
20
|
+
getU64Decoder,
|
|
21
|
+
getU64Encoder,
|
|
22
|
+
type Account,
|
|
23
|
+
type Address,
|
|
24
|
+
type EncodedAccount,
|
|
25
|
+
type FetchAccountConfig,
|
|
26
|
+
type FetchAccountsConfig,
|
|
27
|
+
type FixedSizeCodec,
|
|
28
|
+
type FixedSizeDecoder,
|
|
29
|
+
type FixedSizeEncoder,
|
|
30
|
+
type MaybeAccount,
|
|
31
|
+
type MaybeEncodedAccount,
|
|
32
|
+
} from '@solana/kit';
|
|
33
|
+
import {
|
|
34
|
+
getNonceStateDecoder,
|
|
35
|
+
getNonceStateEncoder,
|
|
36
|
+
getNonceVersionDecoder,
|
|
37
|
+
getNonceVersionEncoder,
|
|
38
|
+
type NonceState,
|
|
39
|
+
type NonceStateArgs,
|
|
40
|
+
type NonceVersion,
|
|
41
|
+
type NonceVersionArgs,
|
|
42
|
+
} from '../types';
|
|
43
|
+
|
|
44
|
+
export type Nonce = {
|
|
45
|
+
version: NonceVersion;
|
|
46
|
+
state: NonceState;
|
|
47
|
+
authority: Address;
|
|
48
|
+
blockhash: Address;
|
|
49
|
+
lamportsPerSignature: bigint;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type NonceArgs = {
|
|
53
|
+
version: NonceVersionArgs;
|
|
54
|
+
state: NonceStateArgs;
|
|
55
|
+
authority: Address;
|
|
56
|
+
blockhash: Address;
|
|
57
|
+
lamportsPerSignature: number | bigint;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Gets the encoder for {@link NonceArgs} account data. */
|
|
61
|
+
export function getNonceEncoder(): FixedSizeEncoder<NonceArgs> {
|
|
62
|
+
return getStructEncoder([
|
|
63
|
+
['version', getNonceVersionEncoder()],
|
|
64
|
+
['state', getNonceStateEncoder()],
|
|
65
|
+
['authority', getAddressEncoder()],
|
|
66
|
+
['blockhash', getAddressEncoder()],
|
|
67
|
+
['lamportsPerSignature', getU64Encoder()],
|
|
68
|
+
]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Gets the decoder for {@link Nonce} account data. */
|
|
72
|
+
export function getNonceDecoder(): FixedSizeDecoder<Nonce> {
|
|
73
|
+
return getStructDecoder([
|
|
74
|
+
['version', getNonceVersionDecoder()],
|
|
75
|
+
['state', getNonceStateDecoder()],
|
|
76
|
+
['authority', getAddressDecoder()],
|
|
77
|
+
['blockhash', getAddressDecoder()],
|
|
78
|
+
['lamportsPerSignature', getU64Decoder()],
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Gets the codec for {@link Nonce} account data. */
|
|
83
|
+
export function getNonceCodec(): FixedSizeCodec<NonceArgs, Nonce> {
|
|
84
|
+
return combineCodec(getNonceEncoder(), getNonceDecoder());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function decodeNonce<TAddress extends string = string>(
|
|
88
|
+
encodedAccount: EncodedAccount<TAddress>,
|
|
89
|
+
): Account<Nonce, TAddress>;
|
|
90
|
+
export function decodeNonce<TAddress extends string = string>(
|
|
91
|
+
encodedAccount: MaybeEncodedAccount<TAddress>,
|
|
92
|
+
): MaybeAccount<Nonce, TAddress>;
|
|
93
|
+
export function decodeNonce<TAddress extends string = string>(
|
|
94
|
+
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>,
|
|
95
|
+
): Account<Nonce, TAddress> | MaybeAccount<Nonce, TAddress> {
|
|
96
|
+
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, getNonceDecoder());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function fetchNonce<TAddress extends string = string>(
|
|
100
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
101
|
+
address: Address<TAddress>,
|
|
102
|
+
config?: FetchAccountConfig,
|
|
103
|
+
): Promise<Account<Nonce, TAddress>> {
|
|
104
|
+
const maybeAccount = await fetchMaybeNonce(rpc, address, config);
|
|
105
|
+
assertAccountExists(maybeAccount);
|
|
106
|
+
return maybeAccount;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function fetchMaybeNonce<TAddress extends string = string>(
|
|
110
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
111
|
+
address: Address<TAddress>,
|
|
112
|
+
config?: FetchAccountConfig,
|
|
113
|
+
): Promise<MaybeAccount<Nonce, TAddress>> {
|
|
114
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
115
|
+
return decodeNonce(maybeAccount);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function fetchAllNonce(
|
|
119
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
120
|
+
addresses: Array<Address>,
|
|
121
|
+
config?: FetchAccountsConfig,
|
|
122
|
+
): Promise<Account<Nonce>[]> {
|
|
123
|
+
const maybeAccounts = await fetchAllMaybeNonce(rpc, addresses, config);
|
|
124
|
+
assertAccountsExist(maybeAccounts);
|
|
125
|
+
return maybeAccounts;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export async function fetchAllMaybeNonce(
|
|
129
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
130
|
+
addresses: Array<Address>,
|
|
131
|
+
config?: FetchAccountsConfig,
|
|
132
|
+
): Promise<MaybeAccount<Nonce>[]> {
|
|
133
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
134
|
+
return maybeAccounts.map(maybeAccount => decodeNonce(maybeAccount));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function getNonceSize(): number {
|
|
138
|
+
return 80;
|
|
139
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
9
|
+
import {
|
|
10
|
+
isProgramError,
|
|
11
|
+
type Address,
|
|
12
|
+
type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM,
|
|
13
|
+
type SolanaError,
|
|
14
|
+
} from '@solana/kit';
|
|
15
|
+
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
|
|
16
|
+
|
|
17
|
+
/** AccountAlreadyInUse: an account with the same address already exists */
|
|
18
|
+
export const SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE = 0x0; // 0
|
|
19
|
+
/** ResultWithNegativeLamports: account does not have enough SOL to perform the operation */
|
|
20
|
+
export const SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS = 0x1; // 1
|
|
21
|
+
/** InvalidProgramId: cannot assign account to this program id */
|
|
22
|
+
export const SYSTEM_ERROR__INVALID_PROGRAM_ID = 0x2; // 2
|
|
23
|
+
/** InvalidAccountDataLength: cannot allocate account data of this length */
|
|
24
|
+
export const SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH = 0x3; // 3
|
|
25
|
+
/** MaxSeedLengthExceeded: length of requested seed is too long */
|
|
26
|
+
export const SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED = 0x4; // 4
|
|
27
|
+
/** AddressWithSeedMismatch: provided address does not match addressed derived from seed */
|
|
28
|
+
export const SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH = 0x5; // 5
|
|
29
|
+
/** NonceNoRecentBlockhashes: advancing stored nonce requires a populated RecentBlockhashes sysvar */
|
|
30
|
+
export const SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES = 0x6; // 6
|
|
31
|
+
/** NonceBlockhashNotExpired: stored nonce is still in recent_blockhashes */
|
|
32
|
+
export const SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED = 0x7; // 7
|
|
33
|
+
/** NonceUnexpectedBlockhashValue: specified nonce does not match stored nonce */
|
|
34
|
+
export const SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE = 0x8; // 8
|
|
35
|
+
|
|
36
|
+
export type SystemError =
|
|
37
|
+
| typeof SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE
|
|
38
|
+
| typeof SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH
|
|
39
|
+
| typeof SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH
|
|
40
|
+
| typeof SYSTEM_ERROR__INVALID_PROGRAM_ID
|
|
41
|
+
| typeof SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED
|
|
42
|
+
| typeof SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED
|
|
43
|
+
| typeof SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES
|
|
44
|
+
| typeof SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE
|
|
45
|
+
| typeof SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS;
|
|
46
|
+
|
|
47
|
+
let systemErrorMessages: Record<SystemError, string> | undefined;
|
|
48
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
49
|
+
systemErrorMessages = {
|
|
50
|
+
[SYSTEM_ERROR__ACCOUNT_ALREADY_IN_USE]: `an account with the same address already exists`,
|
|
51
|
+
[SYSTEM_ERROR__ADDRESS_WITH_SEED_MISMATCH]: `provided address does not match addressed derived from seed`,
|
|
52
|
+
[SYSTEM_ERROR__INVALID_ACCOUNT_DATA_LENGTH]: `cannot allocate account data of this length`,
|
|
53
|
+
[SYSTEM_ERROR__INVALID_PROGRAM_ID]: `cannot assign account to this program id`,
|
|
54
|
+
[SYSTEM_ERROR__MAX_SEED_LENGTH_EXCEEDED]: `length of requested seed is too long`,
|
|
55
|
+
[SYSTEM_ERROR__NONCE_BLOCKHASH_NOT_EXPIRED]: `stored nonce is still in recent_blockhashes`,
|
|
56
|
+
[SYSTEM_ERROR__NONCE_NO_RECENT_BLOCKHASHES]: `advancing stored nonce requires a populated RecentBlockhashes sysvar`,
|
|
57
|
+
[SYSTEM_ERROR__NONCE_UNEXPECTED_BLOCKHASH_VALUE]: `specified nonce does not match stored nonce`,
|
|
58
|
+
[SYSTEM_ERROR__RESULT_WITH_NEGATIVE_LAMPORTS]: `account does not have enough SOL to perform the operation`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getSystemErrorMessage(code: SystemError): string {
|
|
63
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
64
|
+
return (systemErrorMessages as Record<SystemError, string>)[code];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return 'Error message not available in production bundles.';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isSystemError<TProgramErrorCode extends SystemError>(
|
|
71
|
+
error: unknown,
|
|
72
|
+
transactionMessage: { instructions: Record<number, { programAddress: Address }> },
|
|
73
|
+
code?: TProgramErrorCode,
|
|
74
|
+
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
|
|
75
|
+
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
76
|
+
return isProgramError<TProgramErrorCode>(error, transactionMessage, SYSTEM_PROGRAM_ADDRESS, code);
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
|
|
9
|
+
export * from './accounts';
|
|
10
|
+
export * from './errors';
|
|
11
|
+
export * from './instructions';
|
|
12
|
+
export * from './programs';
|
|
13
|
+
export * from './types';
|
|
@@ -0,0 +1,186 @@
|
|
|
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
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
getStructDecoder,
|
|
12
|
+
getStructEncoder,
|
|
13
|
+
getU32Decoder,
|
|
14
|
+
getU32Encoder,
|
|
15
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
16
|
+
SolanaError,
|
|
17
|
+
transformEncoder,
|
|
18
|
+
type AccountMeta,
|
|
19
|
+
type AccountSignerMeta,
|
|
20
|
+
type Address,
|
|
21
|
+
type FixedSizeCodec,
|
|
22
|
+
type FixedSizeDecoder,
|
|
23
|
+
type FixedSizeEncoder,
|
|
24
|
+
type Instruction,
|
|
25
|
+
type InstructionWithAccounts,
|
|
26
|
+
type InstructionWithData,
|
|
27
|
+
type ReadonlyAccount,
|
|
28
|
+
type ReadonlySignerAccount,
|
|
29
|
+
type ReadonlyUint8Array,
|
|
30
|
+
type TransactionSigner,
|
|
31
|
+
type WritableAccount,
|
|
32
|
+
} from '@solana/kit';
|
|
33
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
|
|
34
|
+
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
|
|
35
|
+
|
|
36
|
+
export const ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR = 4;
|
|
37
|
+
|
|
38
|
+
export function getAdvanceNonceAccountDiscriminatorBytes(): ReadonlyUint8Array {
|
|
39
|
+
return getU32Encoder().encode(ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type AdvanceNonceAccountInstruction<
|
|
43
|
+
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
44
|
+
TAccountNonceAccount extends string | AccountMeta<string> = string,
|
|
45
|
+
TAccountRecentBlockhashesSysvar extends string | AccountMeta<string> =
|
|
46
|
+
'SysvarRecentB1ockHashes11111111111111111111',
|
|
47
|
+
TAccountNonceAuthority extends string | AccountMeta<string> = string,
|
|
48
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
49
|
+
> = Instruction<TProgram> &
|
|
50
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
51
|
+
InstructionWithAccounts<
|
|
52
|
+
[
|
|
53
|
+
TAccountNonceAccount extends string ? WritableAccount<TAccountNonceAccount> : TAccountNonceAccount,
|
|
54
|
+
TAccountRecentBlockhashesSysvar extends string
|
|
55
|
+
? ReadonlyAccount<TAccountRecentBlockhashesSysvar>
|
|
56
|
+
: TAccountRecentBlockhashesSysvar,
|
|
57
|
+
TAccountNonceAuthority extends string
|
|
58
|
+
? ReadonlySignerAccount<TAccountNonceAuthority> & AccountSignerMeta<TAccountNonceAuthority>
|
|
59
|
+
: TAccountNonceAuthority,
|
|
60
|
+
...TRemainingAccounts,
|
|
61
|
+
]
|
|
62
|
+
>;
|
|
63
|
+
|
|
64
|
+
export type AdvanceNonceAccountInstructionData = { discriminator: number };
|
|
65
|
+
|
|
66
|
+
export type AdvanceNonceAccountInstructionDataArgs = {};
|
|
67
|
+
|
|
68
|
+
export function getAdvanceNonceAccountInstructionDataEncoder(): FixedSizeEncoder<AdvanceNonceAccountInstructionDataArgs> {
|
|
69
|
+
return transformEncoder(getStructEncoder([['discriminator', getU32Encoder()]]), value => ({
|
|
70
|
+
...value,
|
|
71
|
+
discriminator: ADVANCE_NONCE_ACCOUNT_DISCRIMINATOR,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function getAdvanceNonceAccountInstructionDataDecoder(): FixedSizeDecoder<AdvanceNonceAccountInstructionData> {
|
|
76
|
+
return getStructDecoder([['discriminator', getU32Decoder()]]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getAdvanceNonceAccountInstructionDataCodec(): FixedSizeCodec<
|
|
80
|
+
AdvanceNonceAccountInstructionDataArgs,
|
|
81
|
+
AdvanceNonceAccountInstructionData
|
|
82
|
+
> {
|
|
83
|
+
return combineCodec(getAdvanceNonceAccountInstructionDataEncoder(), getAdvanceNonceAccountInstructionDataDecoder());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type AdvanceNonceAccountInput<
|
|
87
|
+
TAccountNonceAccount extends string = string,
|
|
88
|
+
TAccountRecentBlockhashesSysvar extends string = string,
|
|
89
|
+
TAccountNonceAuthority extends string = string,
|
|
90
|
+
> = {
|
|
91
|
+
nonceAccount: Address<TAccountNonceAccount>;
|
|
92
|
+
recentBlockhashesSysvar?: Address<TAccountRecentBlockhashesSysvar>;
|
|
93
|
+
nonceAuthority: TransactionSigner<TAccountNonceAuthority>;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export function getAdvanceNonceAccountInstruction<
|
|
97
|
+
TAccountNonceAccount extends string,
|
|
98
|
+
TAccountRecentBlockhashesSysvar extends string,
|
|
99
|
+
TAccountNonceAuthority extends string,
|
|
100
|
+
TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
101
|
+
>(
|
|
102
|
+
input: AdvanceNonceAccountInput<TAccountNonceAccount, TAccountRecentBlockhashesSysvar, TAccountNonceAuthority>,
|
|
103
|
+
config?: { programAddress?: TProgramAddress },
|
|
104
|
+
): AdvanceNonceAccountInstruction<
|
|
105
|
+
TProgramAddress,
|
|
106
|
+
TAccountNonceAccount,
|
|
107
|
+
TAccountRecentBlockhashesSysvar,
|
|
108
|
+
TAccountNonceAuthority
|
|
109
|
+
> {
|
|
110
|
+
// Program address.
|
|
111
|
+
const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
|
|
112
|
+
|
|
113
|
+
// Original accounts.
|
|
114
|
+
const originalAccounts = {
|
|
115
|
+
nonceAccount: { value: input.nonceAccount ?? null, isWritable: true },
|
|
116
|
+
recentBlockhashesSysvar: { value: input.recentBlockhashesSysvar ?? null, isWritable: false },
|
|
117
|
+
nonceAuthority: { value: input.nonceAuthority ?? null, isWritable: false },
|
|
118
|
+
};
|
|
119
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
120
|
+
|
|
121
|
+
// Resolve default values.
|
|
122
|
+
if (!accounts.recentBlockhashesSysvar.value) {
|
|
123
|
+
accounts.recentBlockhashesSysvar.value =
|
|
124
|
+
'SysvarRecentB1ockHashes11111111111111111111' as Address<'SysvarRecentB1ockHashes11111111111111111111'>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
|
|
128
|
+
return Object.freeze({
|
|
129
|
+
accounts: [
|
|
130
|
+
getAccountMeta('nonceAccount', accounts.nonceAccount),
|
|
131
|
+
getAccountMeta('recentBlockhashesSysvar', accounts.recentBlockhashesSysvar),
|
|
132
|
+
getAccountMeta('nonceAuthority', accounts.nonceAuthority),
|
|
133
|
+
],
|
|
134
|
+
data: getAdvanceNonceAccountInstructionDataEncoder().encode({}),
|
|
135
|
+
programAddress,
|
|
136
|
+
} as AdvanceNonceAccountInstruction<
|
|
137
|
+
TProgramAddress,
|
|
138
|
+
TAccountNonceAccount,
|
|
139
|
+
TAccountRecentBlockhashesSysvar,
|
|
140
|
+
TAccountNonceAuthority
|
|
141
|
+
>);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type ParsedAdvanceNonceAccountInstruction<
|
|
145
|
+
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
146
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
147
|
+
> = {
|
|
148
|
+
programAddress: Address<TProgram>;
|
|
149
|
+
accounts: {
|
|
150
|
+
nonceAccount: TAccountMetas[0];
|
|
151
|
+
recentBlockhashesSysvar: TAccountMetas[1];
|
|
152
|
+
nonceAuthority: TAccountMetas[2];
|
|
153
|
+
};
|
|
154
|
+
data: AdvanceNonceAccountInstructionData;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export function parseAdvanceNonceAccountInstruction<
|
|
158
|
+
TProgram extends string,
|
|
159
|
+
TAccountMetas extends readonly AccountMeta[],
|
|
160
|
+
>(
|
|
161
|
+
instruction: Instruction<TProgram> &
|
|
162
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
163
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
164
|
+
): ParsedAdvanceNonceAccountInstruction<TProgram, TAccountMetas> {
|
|
165
|
+
if (instruction.accounts.length < 3) {
|
|
166
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
167
|
+
actualAccountMetas: instruction.accounts.length,
|
|
168
|
+
expectedAccountMetas: 3,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
let accountIndex = 0;
|
|
172
|
+
const getNextAccount = () => {
|
|
173
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
174
|
+
accountIndex += 1;
|
|
175
|
+
return accountMeta;
|
|
176
|
+
};
|
|
177
|
+
return {
|
|
178
|
+
programAddress: instruction.programAddress,
|
|
179
|
+
accounts: {
|
|
180
|
+
nonceAccount: getNextAccount(),
|
|
181
|
+
recentBlockhashesSysvar: getNextAccount(),
|
|
182
|
+
nonceAuthority: getNextAccount(),
|
|
183
|
+
},
|
|
184
|
+
data: getAdvanceNonceAccountInstructionDataDecoder().decode(instruction.data),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
|
|
9
|
+
import {
|
|
10
|
+
combineCodec,
|
|
11
|
+
getStructDecoder,
|
|
12
|
+
getStructEncoder,
|
|
13
|
+
getU32Decoder,
|
|
14
|
+
getU32Encoder,
|
|
15
|
+
getU64Decoder,
|
|
16
|
+
getU64Encoder,
|
|
17
|
+
SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
|
|
18
|
+
SolanaError,
|
|
19
|
+
transformEncoder,
|
|
20
|
+
type AccountMeta,
|
|
21
|
+
type AccountSignerMeta,
|
|
22
|
+
type Address,
|
|
23
|
+
type FixedSizeCodec,
|
|
24
|
+
type FixedSizeDecoder,
|
|
25
|
+
type FixedSizeEncoder,
|
|
26
|
+
type Instruction,
|
|
27
|
+
type InstructionWithAccounts,
|
|
28
|
+
type InstructionWithData,
|
|
29
|
+
type ReadonlyUint8Array,
|
|
30
|
+
type TransactionSigner,
|
|
31
|
+
type WritableSignerAccount,
|
|
32
|
+
} from '@solana/kit';
|
|
33
|
+
import { getAccountMetaFactory, type ResolvedInstructionAccount } from '@solana/kit/program-client-core';
|
|
34
|
+
import { SYSTEM_PROGRAM_ADDRESS } from '../programs';
|
|
35
|
+
|
|
36
|
+
export const ALLOCATE_DISCRIMINATOR = 8;
|
|
37
|
+
|
|
38
|
+
export function getAllocateDiscriminatorBytes(): ReadonlyUint8Array {
|
|
39
|
+
return getU32Encoder().encode(ALLOCATE_DISCRIMINATOR);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type AllocateInstruction<
|
|
43
|
+
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
44
|
+
TAccountNewAccount extends string | AccountMeta<string> = string,
|
|
45
|
+
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
|
|
46
|
+
> = Instruction<TProgram> &
|
|
47
|
+
InstructionWithData<ReadonlyUint8Array> &
|
|
48
|
+
InstructionWithAccounts<
|
|
49
|
+
[
|
|
50
|
+
TAccountNewAccount extends string
|
|
51
|
+
? WritableSignerAccount<TAccountNewAccount> & AccountSignerMeta<TAccountNewAccount>
|
|
52
|
+
: TAccountNewAccount,
|
|
53
|
+
...TRemainingAccounts,
|
|
54
|
+
]
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
export type AllocateInstructionData = { discriminator: number; space: bigint };
|
|
58
|
+
|
|
59
|
+
export type AllocateInstructionDataArgs = { space: number | bigint };
|
|
60
|
+
|
|
61
|
+
export function getAllocateInstructionDataEncoder(): FixedSizeEncoder<AllocateInstructionDataArgs> {
|
|
62
|
+
return transformEncoder(
|
|
63
|
+
getStructEncoder([
|
|
64
|
+
['discriminator', getU32Encoder()],
|
|
65
|
+
['space', getU64Encoder()],
|
|
66
|
+
]),
|
|
67
|
+
value => ({ ...value, discriminator: ALLOCATE_DISCRIMINATOR }),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function getAllocateInstructionDataDecoder(): FixedSizeDecoder<AllocateInstructionData> {
|
|
72
|
+
return getStructDecoder([
|
|
73
|
+
['discriminator', getU32Decoder()],
|
|
74
|
+
['space', getU64Decoder()],
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getAllocateInstructionDataCodec(): FixedSizeCodec<
|
|
79
|
+
AllocateInstructionDataArgs,
|
|
80
|
+
AllocateInstructionData
|
|
81
|
+
> {
|
|
82
|
+
return combineCodec(getAllocateInstructionDataEncoder(), getAllocateInstructionDataDecoder());
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type AllocateInput<TAccountNewAccount extends string = string> = {
|
|
86
|
+
newAccount: TransactionSigner<TAccountNewAccount>;
|
|
87
|
+
space: AllocateInstructionDataArgs['space'];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function getAllocateInstruction<
|
|
91
|
+
TAccountNewAccount extends string,
|
|
92
|
+
TProgramAddress extends Address = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
93
|
+
>(
|
|
94
|
+
input: AllocateInput<TAccountNewAccount>,
|
|
95
|
+
config?: { programAddress?: TProgramAddress },
|
|
96
|
+
): AllocateInstruction<TProgramAddress, TAccountNewAccount> {
|
|
97
|
+
// Program address.
|
|
98
|
+
const programAddress = config?.programAddress ?? SYSTEM_PROGRAM_ADDRESS;
|
|
99
|
+
|
|
100
|
+
// Original accounts.
|
|
101
|
+
const originalAccounts = { newAccount: { value: input.newAccount ?? null, isWritable: true } };
|
|
102
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedInstructionAccount>;
|
|
103
|
+
|
|
104
|
+
// Original args.
|
|
105
|
+
const args = { ...input };
|
|
106
|
+
|
|
107
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, 'omitted');
|
|
108
|
+
return Object.freeze({
|
|
109
|
+
accounts: [getAccountMeta('newAccount', accounts.newAccount)],
|
|
110
|
+
data: getAllocateInstructionDataEncoder().encode(args as AllocateInstructionDataArgs),
|
|
111
|
+
programAddress,
|
|
112
|
+
} as AllocateInstruction<TProgramAddress, TAccountNewAccount>);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type ParsedAllocateInstruction<
|
|
116
|
+
TProgram extends string = typeof SYSTEM_PROGRAM_ADDRESS,
|
|
117
|
+
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
|
|
118
|
+
> = {
|
|
119
|
+
programAddress: Address<TProgram>;
|
|
120
|
+
accounts: {
|
|
121
|
+
newAccount: TAccountMetas[0];
|
|
122
|
+
};
|
|
123
|
+
data: AllocateInstructionData;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export function parseAllocateInstruction<TProgram extends string, TAccountMetas extends readonly AccountMeta[]>(
|
|
127
|
+
instruction: Instruction<TProgram> &
|
|
128
|
+
InstructionWithAccounts<TAccountMetas> &
|
|
129
|
+
InstructionWithData<ReadonlyUint8Array>,
|
|
130
|
+
): ParsedAllocateInstruction<TProgram, TAccountMetas> {
|
|
131
|
+
if (instruction.accounts.length < 1) {
|
|
132
|
+
throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, {
|
|
133
|
+
actualAccountMetas: instruction.accounts.length,
|
|
134
|
+
expectedAccountMetas: 1,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
let accountIndex = 0;
|
|
138
|
+
const getNextAccount = () => {
|
|
139
|
+
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
|
|
140
|
+
accountIndex += 1;
|
|
141
|
+
return accountMeta;
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
programAddress: instruction.programAddress,
|
|
145
|
+
accounts: { newAccount: getNextAccount() },
|
|
146
|
+
data: getAllocateInstructionDataDecoder().decode(instruction.data),
|
|
147
|
+
};
|
|
148
|
+
}
|