Skip to content

Commit 60b3884

Browse files
Set admin for config, in restaking and vault (#152)
Co-authored-by: Coach Chuck <[email protected]>
1 parent 8073a8b commit 60b3884

File tree

38 files changed

+1527
-38
lines changed

38 files changed

+1527
-38
lines changed

clients/js/restaking_client/errors/jitoRestaking.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export const JITO_RESTAKING_ERROR__VAULT_OVERFLOW = 0x7db; // 2011
6464
export const JITO_RESTAKING_ERROR__SLASHER_OVERFLOW = 0x7dc; // 2012
6565
/** InvalidEpochLength: InvalidEpochLength */
6666
export const JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH = 0x7dd; // 2013
67+
/** ConfigAdminInvalid: ConfigAdminInvalid */
68+
export const JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID = 0x7de; // 2014
6769
/** ArithmeticOverflow: ArithmeticOverflow */
6870
export const JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW = 0xbb8; // 3000
6971
/** ArithmeticUnderflow: ArithmeticUnderflow */
@@ -74,6 +76,7 @@ export const JITO_RESTAKING_ERROR__DIVISION_BY_ZERO = 0xbba; // 3002
7476
export type JitoRestakingError =
7577
| typeof JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW
7678
| typeof JITO_RESTAKING_ERROR__ARITHMETIC_UNDERFLOW
79+
| typeof JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID
7780
| typeof JITO_RESTAKING_ERROR__DIVISION_BY_ZERO
7881
| typeof JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH
7982
| typeof JITO_RESTAKING_ERROR__NCN_ADMIN_INVALID
@@ -106,6 +109,7 @@ if (process.env.NODE_ENV !== 'production') {
106109
jitoRestakingErrorMessages = {
107110
[JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW]: `ArithmeticOverflow`,
108111
[JITO_RESTAKING_ERROR__ARITHMETIC_UNDERFLOW]: `ArithmeticUnderflow`,
112+
[JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID]: `ConfigAdminInvalid`,
109113
[JITO_RESTAKING_ERROR__DIVISION_BY_ZERO]: `DivisionByZero`,
110114
[JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH]: `InvalidEpochLength`,
111115
[JITO_RESTAKING_ERROR__NCN_ADMIN_INVALID]: `NcnAdminInvalid`,

clients/js/restaking_client/instructions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from './operatorSetAdmin';
2727
export * from './operatorSetFee';
2828
export * from './operatorSetSecondaryAdmin';
2929
export * from './operatorWarmupNcn';
30+
export * from './setConfigAdmin';
3031
export * from './warmupNcnVaultSlasherTicket';
3132
export * from './warmupNcnVaultTicket';
3233
export * from './warmupOperatorVaultTicket';
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/**
2+
* This code was AUTOGENERATED using the kinobi library.
3+
* Please DO NOT EDIT THIS FILE, instead use visitors
4+
* to add features, then rerun kinobi to update it.
5+
*
6+
* @see https://github.com/kinobi-so/kinobi
7+
*/
8+
9+
import {
10+
combineCodec,
11+
getStructDecoder,
12+
getStructEncoder,
13+
getU8Decoder,
14+
getU8Encoder,
15+
transformEncoder,
16+
type Address,
17+
type Codec,
18+
type Decoder,
19+
type Encoder,
20+
type IAccountMeta,
21+
type IAccountSignerMeta,
22+
type IInstruction,
23+
type IInstructionWithAccounts,
24+
type IInstructionWithData,
25+
type ReadonlySignerAccount,
26+
type TransactionSigner,
27+
type WritableAccount,
28+
} from '@solana/web3.js';
29+
import { JITO_RESTAKING_PROGRAM_ADDRESS } from '../programs';
30+
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
31+
32+
export const SET_CONFIG_ADMIN_DISCRIMINATOR = 24;
33+
34+
export function getSetConfigAdminDiscriminatorBytes() {
35+
return getU8Encoder().encode(SET_CONFIG_ADMIN_DISCRIMINATOR);
36+
}
37+
38+
export type SetConfigAdminInstruction<
39+
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS,
40+
TAccountConfig extends string | IAccountMeta<string> = string,
41+
TAccountOldAdmin extends string | IAccountMeta<string> = string,
42+
TAccountNewAdmin extends string | IAccountMeta<string> = string,
43+
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
44+
> = IInstruction<TProgram> &
45+
IInstructionWithData<Uint8Array> &
46+
IInstructionWithAccounts<
47+
[
48+
TAccountConfig extends string
49+
? WritableAccount<TAccountConfig>
50+
: TAccountConfig,
51+
TAccountOldAdmin extends string
52+
? ReadonlySignerAccount<TAccountOldAdmin> &
53+
IAccountSignerMeta<TAccountOldAdmin>
54+
: TAccountOldAdmin,
55+
TAccountNewAdmin extends string
56+
? ReadonlySignerAccount<TAccountNewAdmin> &
57+
IAccountSignerMeta<TAccountNewAdmin>
58+
: TAccountNewAdmin,
59+
...TRemainingAccounts,
60+
]
61+
>;
62+
63+
export type SetConfigAdminInstructionData = { discriminator: number };
64+
65+
export type SetConfigAdminInstructionDataArgs = {};
66+
67+
export function getSetConfigAdminInstructionDataEncoder(): Encoder<SetConfigAdminInstructionDataArgs> {
68+
return transformEncoder(
69+
getStructEncoder([['discriminator', getU8Encoder()]]),
70+
(value) => ({ ...value, discriminator: SET_CONFIG_ADMIN_DISCRIMINATOR })
71+
);
72+
}
73+
74+
export function getSetConfigAdminInstructionDataDecoder(): Decoder<SetConfigAdminInstructionData> {
75+
return getStructDecoder([['discriminator', getU8Decoder()]]);
76+
}
77+
78+
export function getSetConfigAdminInstructionDataCodec(): Codec<
79+
SetConfigAdminInstructionDataArgs,
80+
SetConfigAdminInstructionData
81+
> {
82+
return combineCodec(
83+
getSetConfigAdminInstructionDataEncoder(),
84+
getSetConfigAdminInstructionDataDecoder()
85+
);
86+
}
87+
88+
export type SetConfigAdminInput<
89+
TAccountConfig extends string = string,
90+
TAccountOldAdmin extends string = string,
91+
TAccountNewAdmin extends string = string,
92+
> = {
93+
config: Address<TAccountConfig>;
94+
oldAdmin: TransactionSigner<TAccountOldAdmin>;
95+
newAdmin: TransactionSigner<TAccountNewAdmin>;
96+
};
97+
98+
export function getSetConfigAdminInstruction<
99+
TAccountConfig extends string,
100+
TAccountOldAdmin extends string,
101+
TAccountNewAdmin extends string,
102+
>(
103+
input: SetConfigAdminInput<TAccountConfig, TAccountOldAdmin, TAccountNewAdmin>
104+
): SetConfigAdminInstruction<
105+
typeof JITO_RESTAKING_PROGRAM_ADDRESS,
106+
TAccountConfig,
107+
TAccountOldAdmin,
108+
TAccountNewAdmin
109+
> {
110+
// Program address.
111+
const programAddress = JITO_RESTAKING_PROGRAM_ADDRESS;
112+
113+
// Original accounts.
114+
const originalAccounts = {
115+
config: { value: input.config ?? null, isWritable: true },
116+
oldAdmin: { value: input.oldAdmin ?? null, isWritable: false },
117+
newAdmin: { value: input.newAdmin ?? null, isWritable: false },
118+
};
119+
const accounts = originalAccounts as Record<
120+
keyof typeof originalAccounts,
121+
ResolvedAccount
122+
>;
123+
124+
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
125+
const instruction = {
126+
accounts: [
127+
getAccountMeta(accounts.config),
128+
getAccountMeta(accounts.oldAdmin),
129+
getAccountMeta(accounts.newAdmin),
130+
],
131+
programAddress,
132+
data: getSetConfigAdminInstructionDataEncoder().encode({}),
133+
} as SetConfigAdminInstruction<
134+
typeof JITO_RESTAKING_PROGRAM_ADDRESS,
135+
TAccountConfig,
136+
TAccountOldAdmin,
137+
TAccountNewAdmin
138+
>;
139+
140+
return instruction;
141+
}
142+
143+
export type ParsedSetConfigAdminInstruction<
144+
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS,
145+
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
146+
> = {
147+
programAddress: Address<TProgram>;
148+
accounts: {
149+
config: TAccountMetas[0];
150+
oldAdmin: TAccountMetas[1];
151+
newAdmin: TAccountMetas[2];
152+
};
153+
data: SetConfigAdminInstructionData;
154+
};
155+
156+
export function parseSetConfigAdminInstruction<
157+
TProgram extends string,
158+
TAccountMetas extends readonly IAccountMeta[],
159+
>(
160+
instruction: IInstruction<TProgram> &
161+
IInstructionWithAccounts<TAccountMetas> &
162+
IInstructionWithData<Uint8Array>
163+
): ParsedSetConfigAdminInstruction<TProgram, TAccountMetas> {
164+
if (instruction.accounts.length < 3) {
165+
// TODO: Coded error.
166+
throw new Error('Not enough accounts');
167+
}
168+
let accountIndex = 0;
169+
const getNextAccount = () => {
170+
const accountMeta = instruction.accounts![accountIndex]!;
171+
accountIndex += 1;
172+
return accountMeta;
173+
};
174+
return {
175+
programAddress: instruction.programAddress,
176+
accounts: {
177+
config: getNextAccount(),
178+
oldAdmin: getNextAccount(),
179+
newAdmin: getNextAccount(),
180+
},
181+
data: getSetConfigAdminInstructionDataDecoder().decode(instruction.data),
182+
};
183+
}

clients/js/restaking_client/programs/jitoRestaking.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
type ParsedOperatorSetFeeInstruction,
3535
type ParsedOperatorSetSecondaryAdminInstruction,
3636
type ParsedOperatorWarmupNcnInstruction,
37+
type ParsedSetConfigAdminInstruction,
3738
type ParsedWarmupNcnVaultSlasherTicketInstruction,
3839
type ParsedWarmupNcnVaultTicketInstruction,
3940
type ParsedWarmupOperatorVaultTicketInstruction,
@@ -77,6 +78,7 @@ export enum JitoRestakingInstruction {
7778
OperatorSetFee,
7879
NcnDelegateTokenAccount,
7980
OperatorDelegateTokenAccount,
81+
SetConfigAdmin,
8082
}
8183

8284
export function identifyJitoRestakingInstruction(
@@ -155,6 +157,9 @@ export function identifyJitoRestakingInstruction(
155157
if (containsBytes(data, getU8Encoder().encode(23), 0)) {
156158
return JitoRestakingInstruction.OperatorDelegateTokenAccount;
157159
}
160+
if (containsBytes(data, getU8Encoder().encode(24), 0)) {
161+
return JitoRestakingInstruction.SetConfigAdmin;
162+
}
158163
throw new Error(
159164
'The provided instruction could not be identified as a jitoRestaking instruction.'
160165
);
@@ -234,4 +239,7 @@ export type ParsedJitoRestakingInstruction<
234239
} & ParsedNcnDelegateTokenAccountInstruction<TProgram>)
235240
| ({
236241
instructionType: JitoRestakingInstruction.OperatorDelegateTokenAccount;
237-
} & ParsedOperatorDelegateTokenAccountInstruction<TProgram>);
242+
} & ParsedOperatorDelegateTokenAccountInstruction<TProgram>)
243+
| ({
244+
instructionType: JitoRestakingInstruction.SetConfigAdmin;
245+
} & ParsedSetConfigAdminInstruction<TProgram>);

clients/js/vault_client/errors/jitoVault.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export const JITO_VAULT_ERROR__VAULT_SLASHER_ADMIN_INVALID = 0x3f2; // 1010
4040
export const JITO_VAULT_ERROR__VAULT_NCN_ADMIN_INVALID = 0x3f3; // 1011
4141
/** VaultFeeAdminInvalid: VaultFeeAdminInvalid */
4242
export const JITO_VAULT_ERROR__VAULT_FEE_ADMIN_INVALID = 0x3f4; // 1012
43-
/** VaultConfigAdminInvalid: VaultConfigAdminInvalid */
44-
export const JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID = 0x3f5; // 1013
45-
/** VaultConfigFeeAdminInvalid: VaultConfigFeeAdminInvalid */
46-
export const JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID = 0x3f6; // 1014
43+
/** ConfigAdminInvalid: ConfigAdminInvalid */
44+
export const JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID = 0x3f5; // 1013
45+
/** ConfigFeeAdminInvalid: ConfigFeeAdminInvalid */
46+
export const JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID = 0x3f6; // 1014
4747
/** VaultFeeCapExceeded: VaultFeeCapExceeded */
4848
export const JITO_VAULT_ERROR__VAULT_FEE_CAP_EXCEEDED = 0x3f7; // 1015
4949
/** VaultFeeChangeTooSoon: VaultFeeChangeTooSoon */
@@ -140,6 +140,8 @@ export const JITO_VAULT_ERROR__DIVISION_BY_ZERO = 0xbba; // 3002
140140
export type JitoVaultError =
141141
| typeof JITO_VAULT_ERROR__ARITHMETIC_OVERFLOW
142142
| typeof JITO_VAULT_ERROR__ARITHMETIC_UNDERFLOW
143+
| typeof JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID
144+
| typeof JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID
143145
| typeof JITO_VAULT_ERROR__DIVISION_BY_ZERO
144146
| typeof JITO_VAULT_ERROR__INVALID_DEPOSITOR
145147
| typeof JITO_VAULT_ERROR__INVALID_DEPOSIT_TOKEN_ACCOUNT
@@ -158,8 +160,6 @@ export type JitoVaultError =
158160
| typeof JITO_VAULT_ERROR__VAULT_BURN_ZERO
159161
| typeof JITO_VAULT_ERROR__VAULT_CAPACITY_ADMIN_INVALID
160162
| typeof JITO_VAULT_ERROR__VAULT_CAPACITY_EXCEEDED
161-
| typeof JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID
162-
| typeof JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID
163163
| typeof JITO_VAULT_ERROR__VAULT_COOLDOWN_ZERO
164164
| typeof JITO_VAULT_ERROR__VAULT_DELEGATE_ASSET_ADMIN_INVALID
165165
| typeof JITO_VAULT_ERROR__VAULT_DELEGATION_ADMIN_INVALID
@@ -205,6 +205,8 @@ if (process.env.NODE_ENV !== 'production') {
205205
jitoVaultErrorMessages = {
206206
[JITO_VAULT_ERROR__ARITHMETIC_OVERFLOW]: `ArithmeticOverflow`,
207207
[JITO_VAULT_ERROR__ARITHMETIC_UNDERFLOW]: `ArithmeticUnderflow`,
208+
[JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID]: `ConfigAdminInvalid`,
209+
[JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID]: `ConfigFeeAdminInvalid`,
208210
[JITO_VAULT_ERROR__DIVISION_BY_ZERO]: `DivisionByZero`,
209211
[JITO_VAULT_ERROR__INVALID_DEPOSITOR]: `InvalidDepositor`,
210212
[JITO_VAULT_ERROR__INVALID_DEPOSIT_TOKEN_ACCOUNT]: `InvalidDepositTokenAccount`,
@@ -223,8 +225,6 @@ if (process.env.NODE_ENV !== 'production') {
223225
[JITO_VAULT_ERROR__VAULT_BURN_ZERO]: `VaultBurnZero`,
224226
[JITO_VAULT_ERROR__VAULT_CAPACITY_ADMIN_INVALID]: `VaultCapacityAdminInvalid`,
225227
[JITO_VAULT_ERROR__VAULT_CAPACITY_EXCEEDED]: `VaultCapacityExceeded`,
226-
[JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID]: `VaultConfigAdminInvalid`,
227-
[JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID]: `VaultConfigFeeAdminInvalid`,
228228
[JITO_VAULT_ERROR__VAULT_COOLDOWN_ZERO]: `VaultCooldownZero`,
229229
[JITO_VAULT_ERROR__VAULT_DELEGATE_ASSET_ADMIN_INVALID]: `VaultDelegateAssetAdminInvalid`,
230230
[JITO_VAULT_ERROR__VAULT_DELEGATION_ADMIN_INVALID]: `VaultDelegationAdminInvalid`,

clients/js/vault_client/instructions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export * from './initializeVaultUpdateStateTracker';
2727
export * from './initializeVaultWithMint';
2828
export * from './mintTo';
2929
export * from './setAdmin';
30+
export * from './setConfigAdmin';
3031
export * from './setDepositCapacity';
3132
export * from './setFees';
3233
export * from './setIsPaused';

0 commit comments

Comments
 (0)