Skip to content

Commit

Permalink
Set admin for config, in restaking and vault (#152)
Browse files Browse the repository at this point in the history
Co-authored-by: Coach Chuck <[email protected]>
  • Loading branch information
ebatsell and coachchucksol authored Oct 25, 2024
1 parent 8073a8b commit 60b3884
Show file tree
Hide file tree
Showing 38 changed files with 1,527 additions and 38 deletions.
4 changes: 4 additions & 0 deletions clients/js/restaking_client/errors/jitoRestaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const JITO_RESTAKING_ERROR__VAULT_OVERFLOW = 0x7db; // 2011
export const JITO_RESTAKING_ERROR__SLASHER_OVERFLOW = 0x7dc; // 2012
/** InvalidEpochLength: InvalidEpochLength */
export const JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH = 0x7dd; // 2013
/** ConfigAdminInvalid: ConfigAdminInvalid */
export const JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID = 0x7de; // 2014
/** ArithmeticOverflow: ArithmeticOverflow */
export const JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW = 0xbb8; // 3000
/** ArithmeticUnderflow: ArithmeticUnderflow */
Expand All @@ -74,6 +76,7 @@ export const JITO_RESTAKING_ERROR__DIVISION_BY_ZERO = 0xbba; // 3002
export type JitoRestakingError =
| typeof JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW
| typeof JITO_RESTAKING_ERROR__ARITHMETIC_UNDERFLOW
| typeof JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID
| typeof JITO_RESTAKING_ERROR__DIVISION_BY_ZERO
| typeof JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH
| typeof JITO_RESTAKING_ERROR__NCN_ADMIN_INVALID
Expand Down Expand Up @@ -106,6 +109,7 @@ if (process.env.NODE_ENV !== 'production') {
jitoRestakingErrorMessages = {
[JITO_RESTAKING_ERROR__ARITHMETIC_OVERFLOW]: `ArithmeticOverflow`,
[JITO_RESTAKING_ERROR__ARITHMETIC_UNDERFLOW]: `ArithmeticUnderflow`,
[JITO_RESTAKING_ERROR__CONFIG_ADMIN_INVALID]: `ConfigAdminInvalid`,
[JITO_RESTAKING_ERROR__DIVISION_BY_ZERO]: `DivisionByZero`,
[JITO_RESTAKING_ERROR__INVALID_EPOCH_LENGTH]: `InvalidEpochLength`,
[JITO_RESTAKING_ERROR__NCN_ADMIN_INVALID]: `NcnAdminInvalid`,
Expand Down
1 change: 1 addition & 0 deletions clients/js/restaking_client/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from './operatorSetAdmin';
export * from './operatorSetFee';
export * from './operatorSetSecondaryAdmin';
export * from './operatorWarmupNcn';
export * from './setConfigAdmin';
export * from './warmupNcnVaultSlasherTicket';
export * from './warmupNcnVaultTicket';
export * from './warmupOperatorVaultTicket';
183 changes: 183 additions & 0 deletions clients/js/restaking_client/instructions/setConfigAdmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/**
* This code was AUTOGENERATED using the kinobi library.
* Please DO NOT EDIT THIS FILE, instead use visitors
* to add features, then rerun kinobi to update it.
*
* @see https://github.com/kinobi-so/kinobi
*/

import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IAccountSignerMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type ReadonlySignerAccount,
type TransactionSigner,
type WritableAccount,
} from '@solana/web3.js';
import { JITO_RESTAKING_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const SET_CONFIG_ADMIN_DISCRIMINATOR = 24;

export function getSetConfigAdminDiscriminatorBytes() {
return getU8Encoder().encode(SET_CONFIG_ADMIN_DISCRIMINATOR);
}

export type SetConfigAdminInstruction<
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS,
TAccountConfig extends string | IAccountMeta<string> = string,
TAccountOldAdmin extends string | IAccountMeta<string> = string,
TAccountNewAdmin extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountConfig extends string
? WritableAccount<TAccountConfig>
: TAccountConfig,
TAccountOldAdmin extends string
? ReadonlySignerAccount<TAccountOldAdmin> &
IAccountSignerMeta<TAccountOldAdmin>
: TAccountOldAdmin,
TAccountNewAdmin extends string
? ReadonlySignerAccount<TAccountNewAdmin> &
IAccountSignerMeta<TAccountNewAdmin>
: TAccountNewAdmin,
...TRemainingAccounts,
]
>;

export type SetConfigAdminInstructionData = { discriminator: number };

export type SetConfigAdminInstructionDataArgs = {};

export function getSetConfigAdminInstructionDataEncoder(): Encoder<SetConfigAdminInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: SET_CONFIG_ADMIN_DISCRIMINATOR })
);
}

export function getSetConfigAdminInstructionDataDecoder(): Decoder<SetConfigAdminInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
}

export function getSetConfigAdminInstructionDataCodec(): Codec<
SetConfigAdminInstructionDataArgs,
SetConfigAdminInstructionData
> {
return combineCodec(
getSetConfigAdminInstructionDataEncoder(),
getSetConfigAdminInstructionDataDecoder()
);
}

export type SetConfigAdminInput<
TAccountConfig extends string = string,
TAccountOldAdmin extends string = string,
TAccountNewAdmin extends string = string,
> = {
config: Address<TAccountConfig>;
oldAdmin: TransactionSigner<TAccountOldAdmin>;
newAdmin: TransactionSigner<TAccountNewAdmin>;
};

export function getSetConfigAdminInstruction<
TAccountConfig extends string,
TAccountOldAdmin extends string,
TAccountNewAdmin extends string,
>(
input: SetConfigAdminInput<TAccountConfig, TAccountOldAdmin, TAccountNewAdmin>
): SetConfigAdminInstruction<
typeof JITO_RESTAKING_PROGRAM_ADDRESS,
TAccountConfig,
TAccountOldAdmin,
TAccountNewAdmin
> {
// Program address.
const programAddress = JITO_RESTAKING_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
config: { value: input.config ?? null, isWritable: true },
oldAdmin: { value: input.oldAdmin ?? null, isWritable: false },
newAdmin: { value: input.newAdmin ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.config),
getAccountMeta(accounts.oldAdmin),
getAccountMeta(accounts.newAdmin),
],
programAddress,
data: getSetConfigAdminInstructionDataEncoder().encode({}),
} as SetConfigAdminInstruction<
typeof JITO_RESTAKING_PROGRAM_ADDRESS,
TAccountConfig,
TAccountOldAdmin,
TAccountNewAdmin
>;

return instruction;
}

export type ParsedSetConfigAdminInstruction<
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
config: TAccountMetas[0];
oldAdmin: TAccountMetas[1];
newAdmin: TAccountMetas[2];
};
data: SetConfigAdminInstructionData;
};

export function parseSetConfigAdminInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedSetConfigAdminInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 3) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
config: getNextAccount(),
oldAdmin: getNextAccount(),
newAdmin: getNextAccount(),
},
data: getSetConfigAdminInstructionDataDecoder().decode(instruction.data),
};
}
10 changes: 9 additions & 1 deletion clients/js/restaking_client/programs/jitoRestaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
type ParsedOperatorSetFeeInstruction,
type ParsedOperatorSetSecondaryAdminInstruction,
type ParsedOperatorWarmupNcnInstruction,
type ParsedSetConfigAdminInstruction,
type ParsedWarmupNcnVaultSlasherTicketInstruction,
type ParsedWarmupNcnVaultTicketInstruction,
type ParsedWarmupOperatorVaultTicketInstruction,
Expand Down Expand Up @@ -77,6 +78,7 @@ export enum JitoRestakingInstruction {
OperatorSetFee,
NcnDelegateTokenAccount,
OperatorDelegateTokenAccount,
SetConfigAdmin,
}

export function identifyJitoRestakingInstruction(
Expand Down Expand Up @@ -155,6 +157,9 @@ export function identifyJitoRestakingInstruction(
if (containsBytes(data, getU8Encoder().encode(23), 0)) {
return JitoRestakingInstruction.OperatorDelegateTokenAccount;
}
if (containsBytes(data, getU8Encoder().encode(24), 0)) {
return JitoRestakingInstruction.SetConfigAdmin;
}
throw new Error(
'The provided instruction could not be identified as a jitoRestaking instruction.'
);
Expand Down Expand Up @@ -234,4 +239,7 @@ export type ParsedJitoRestakingInstruction<
} & ParsedNcnDelegateTokenAccountInstruction<TProgram>)
| ({
instructionType: JitoRestakingInstruction.OperatorDelegateTokenAccount;
} & ParsedOperatorDelegateTokenAccountInstruction<TProgram>);
} & ParsedOperatorDelegateTokenAccountInstruction<TProgram>)
| ({
instructionType: JitoRestakingInstruction.SetConfigAdmin;
} & ParsedSetConfigAdminInstruction<TProgram>);
16 changes: 8 additions & 8 deletions clients/js/vault_client/errors/jitoVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export const JITO_VAULT_ERROR__VAULT_SLASHER_ADMIN_INVALID = 0x3f2; // 1010
export const JITO_VAULT_ERROR__VAULT_NCN_ADMIN_INVALID = 0x3f3; // 1011
/** VaultFeeAdminInvalid: VaultFeeAdminInvalid */
export const JITO_VAULT_ERROR__VAULT_FEE_ADMIN_INVALID = 0x3f4; // 1012
/** VaultConfigAdminInvalid: VaultConfigAdminInvalid */
export const JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID = 0x3f5; // 1013
/** VaultConfigFeeAdminInvalid: VaultConfigFeeAdminInvalid */
export const JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID = 0x3f6; // 1014
/** ConfigAdminInvalid: ConfigAdminInvalid */
export const JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID = 0x3f5; // 1013
/** ConfigFeeAdminInvalid: ConfigFeeAdminInvalid */
export const JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID = 0x3f6; // 1014
/** VaultFeeCapExceeded: VaultFeeCapExceeded */
export const JITO_VAULT_ERROR__VAULT_FEE_CAP_EXCEEDED = 0x3f7; // 1015
/** VaultFeeChangeTooSoon: VaultFeeChangeTooSoon */
Expand Down Expand Up @@ -140,6 +140,8 @@ export const JITO_VAULT_ERROR__DIVISION_BY_ZERO = 0xbba; // 3002
export type JitoVaultError =
| typeof JITO_VAULT_ERROR__ARITHMETIC_OVERFLOW
| typeof JITO_VAULT_ERROR__ARITHMETIC_UNDERFLOW
| typeof JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__DIVISION_BY_ZERO
| typeof JITO_VAULT_ERROR__INVALID_DEPOSITOR
| typeof JITO_VAULT_ERROR__INVALID_DEPOSIT_TOKEN_ACCOUNT
Expand All @@ -158,8 +160,6 @@ export type JitoVaultError =
| typeof JITO_VAULT_ERROR__VAULT_BURN_ZERO
| typeof JITO_VAULT_ERROR__VAULT_CAPACITY_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__VAULT_CAPACITY_EXCEEDED
| typeof JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__VAULT_COOLDOWN_ZERO
| typeof JITO_VAULT_ERROR__VAULT_DELEGATE_ASSET_ADMIN_INVALID
| typeof JITO_VAULT_ERROR__VAULT_DELEGATION_ADMIN_INVALID
Expand Down Expand Up @@ -205,6 +205,8 @@ if (process.env.NODE_ENV !== 'production') {
jitoVaultErrorMessages = {
[JITO_VAULT_ERROR__ARITHMETIC_OVERFLOW]: `ArithmeticOverflow`,
[JITO_VAULT_ERROR__ARITHMETIC_UNDERFLOW]: `ArithmeticUnderflow`,
[JITO_VAULT_ERROR__CONFIG_ADMIN_INVALID]: `ConfigAdminInvalid`,
[JITO_VAULT_ERROR__CONFIG_FEE_ADMIN_INVALID]: `ConfigFeeAdminInvalid`,
[JITO_VAULT_ERROR__DIVISION_BY_ZERO]: `DivisionByZero`,
[JITO_VAULT_ERROR__INVALID_DEPOSITOR]: `InvalidDepositor`,
[JITO_VAULT_ERROR__INVALID_DEPOSIT_TOKEN_ACCOUNT]: `InvalidDepositTokenAccount`,
Expand All @@ -223,8 +225,6 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_VAULT_ERROR__VAULT_BURN_ZERO]: `VaultBurnZero`,
[JITO_VAULT_ERROR__VAULT_CAPACITY_ADMIN_INVALID]: `VaultCapacityAdminInvalid`,
[JITO_VAULT_ERROR__VAULT_CAPACITY_EXCEEDED]: `VaultCapacityExceeded`,
[JITO_VAULT_ERROR__VAULT_CONFIG_ADMIN_INVALID]: `VaultConfigAdminInvalid`,
[JITO_VAULT_ERROR__VAULT_CONFIG_FEE_ADMIN_INVALID]: `VaultConfigFeeAdminInvalid`,
[JITO_VAULT_ERROR__VAULT_COOLDOWN_ZERO]: `VaultCooldownZero`,
[JITO_VAULT_ERROR__VAULT_DELEGATE_ASSET_ADMIN_INVALID]: `VaultDelegateAssetAdminInvalid`,
[JITO_VAULT_ERROR__VAULT_DELEGATION_ADMIN_INVALID]: `VaultDelegationAdminInvalid`,
Expand Down
1 change: 1 addition & 0 deletions clients/js/vault_client/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from './initializeVaultUpdateStateTracker';
export * from './initializeVaultWithMint';
export * from './mintTo';
export * from './setAdmin';
export * from './setConfigAdmin';
export * from './setDepositCapacity';
export * from './setFees';
export * from './setIsPaused';
Expand Down
Loading

0 comments on commit 60b3884

Please sign in to comment.