Skip to content

Commit

Permalink
set new admins instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Nov 7, 2024
1 parent a14b7fb commit 7ca1fd6
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 5 deletions.
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './finalizeWeightTable';
export * from './initializeConfig';
export * from './initializeWeightTable';
export * from './setConfigFees';
export * from './setNewAdmin';
export * from './updateWeightTable';
240 changes: 240 additions & 0 deletions clients/js/jito_tip_router/instructions/setNewAdmin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/**
* 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 ReadonlyAccount,
type ReadonlySignerAccount,
type TransactionSigner,
type WritableAccount,
} from '@solana/web3.js';
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';
import {
getConfigAdminRoleDecoder,
getConfigAdminRoleEncoder,
type ConfigAdminRole,
type ConfigAdminRoleArgs,
} from '../types';

export const SET_NEW_ADMIN_DISCRIMINATOR = 5;

export function getSetNewAdminDiscriminatorBytes() {
return getU8Encoder().encode(SET_NEW_ADMIN_DISCRIMINATOR);
}

export type SetNewAdminInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountConfig extends string | IAccountMeta<string> = string,
TAccountNcn extends string | IAccountMeta<string> = string,
TAccountNcnAdmin extends string | IAccountMeta<string> = string,
TAccountNewAdmin extends string | IAccountMeta<string> = string,
TAccountRestakingProgramId extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountConfig extends string
? WritableAccount<TAccountConfig>
: TAccountConfig,
TAccountNcn extends string ? ReadonlyAccount<TAccountNcn> : TAccountNcn,
TAccountNcnAdmin extends string
? ReadonlySignerAccount<TAccountNcnAdmin> &
IAccountSignerMeta<TAccountNcnAdmin>
: TAccountNcnAdmin,
TAccountNewAdmin extends string
? ReadonlyAccount<TAccountNewAdmin>
: TAccountNewAdmin,
TAccountRestakingProgramId extends string
? ReadonlyAccount<TAccountRestakingProgramId>
: TAccountRestakingProgramId,
...TRemainingAccounts,
]
>;

export type SetNewAdminInstructionData = {
discriminator: number;
role: ConfigAdminRole;
};

export type SetNewAdminInstructionDataArgs = { role: ConfigAdminRoleArgs };

export function getSetNewAdminInstructionDataEncoder(): Encoder<SetNewAdminInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['role', getConfigAdminRoleEncoder()],
]),
(value) => ({ ...value, discriminator: SET_NEW_ADMIN_DISCRIMINATOR })
);
}

export function getSetNewAdminInstructionDataDecoder(): Decoder<SetNewAdminInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['role', getConfigAdminRoleDecoder()],
]);
}

export function getSetNewAdminInstructionDataCodec(): Codec<
SetNewAdminInstructionDataArgs,
SetNewAdminInstructionData
> {
return combineCodec(
getSetNewAdminInstructionDataEncoder(),
getSetNewAdminInstructionDataDecoder()
);
}

export type SetNewAdminInput<
TAccountConfig extends string = string,
TAccountNcn extends string = string,
TAccountNcnAdmin extends string = string,
TAccountNewAdmin extends string = string,
TAccountRestakingProgramId extends string = string,
> = {
config: Address<TAccountConfig>;
ncn: Address<TAccountNcn>;
ncnAdmin: TransactionSigner<TAccountNcnAdmin>;
newAdmin: Address<TAccountNewAdmin>;
restakingProgramId: Address<TAccountRestakingProgramId>;
role: SetNewAdminInstructionDataArgs['role'];
};

export function getSetNewAdminInstruction<
TAccountConfig extends string,
TAccountNcn extends string,
TAccountNcnAdmin extends string,
TAccountNewAdmin extends string,
TAccountRestakingProgramId extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: SetNewAdminInput<
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountNewAdmin,
TAccountRestakingProgramId
>,
config?: { programAddress?: TProgramAddress }
): SetNewAdminInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountNewAdmin,
TAccountRestakingProgramId
> {
// Program address.
const programAddress =
config?.programAddress ?? JITO_TIP_ROUTER_PROGRAM_ADDRESS;

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

// Original args.
const args = { ...input };

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.config),
getAccountMeta(accounts.ncn),
getAccountMeta(accounts.ncnAdmin),
getAccountMeta(accounts.newAdmin),
getAccountMeta(accounts.restakingProgramId),
],
programAddress,
data: getSetNewAdminInstructionDataEncoder().encode(
args as SetNewAdminInstructionDataArgs
),
} as SetNewAdminInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountNewAdmin,
TAccountRestakingProgramId
>;

return instruction;
}

export type ParsedSetNewAdminInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
config: TAccountMetas[0];
ncn: TAccountMetas[1];
ncnAdmin: TAccountMetas[2];
newAdmin: TAccountMetas[3];
restakingProgramId: TAccountMetas[4];
};
data: SetNewAdminInstructionData;
};

export function parseSetNewAdminInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedSetNewAdminInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 5) {
// 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(),
ncn: getNextAccount(),
ncnAdmin: getNextAccount(),
newAdmin: getNextAccount(),
restakingProgramId: getNextAccount(),
},
data: getSetNewAdminInstructionDataDecoder().decode(instruction.data),
};
}
10 changes: 9 additions & 1 deletion clients/js/jito_tip_router/programs/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
type ParsedInitializeConfigInstruction,
type ParsedInitializeWeightTableInstruction,
type ParsedSetConfigFeesInstruction,
type ParsedSetNewAdminInstruction,
type ParsedUpdateWeightTableInstruction,
} from '../instructions';

Expand All @@ -34,6 +35,7 @@ export enum JitoTipRouterInstruction {
UpdateWeightTable,
FinalizeWeightTable,
SetConfigFees,
SetNewAdmin,
}

export function identifyJitoTipRouterInstruction(
Expand All @@ -55,6 +57,9 @@ export function identifyJitoTipRouterInstruction(
if (containsBytes(data, getU8Encoder().encode(4), 0)) {
return JitoTipRouterInstruction.SetConfigFees;
}
if (containsBytes(data, getU8Encoder().encode(5), 0)) {
return JitoTipRouterInstruction.SetNewAdmin;
}
throw new Error(
'The provided instruction could not be identified as a jitoTipRouter instruction.'
);
Expand All @@ -77,4 +82,7 @@ export type ParsedJitoTipRouterInstruction<
} & ParsedFinalizeWeightTableInstruction<TProgram>)
| ({
instructionType: JitoTipRouterInstruction.SetConfigFees;
} & ParsedSetConfigFeesInstruction<TProgram>);
} & ParsedSetConfigFeesInstruction<TProgram>)
| ({
instructionType: JitoTipRouterInstruction.SetNewAdmin;
} & ParsedSetNewAdminInstruction<TProgram>);
38 changes: 38 additions & 0 deletions clients/js/jito_tip_router/types/configAdminRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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,
getEnumDecoder,
getEnumEncoder,
type Codec,
type Decoder,
type Encoder,
} from '@solana/web3.js';

export enum ConfigAdminRole {
FeeAdmin,
TieBreakerAdmin,
}

export type ConfigAdminRoleArgs = ConfigAdminRole;

export function getConfigAdminRoleEncoder(): Encoder<ConfigAdminRoleArgs> {
return getEnumEncoder(ConfigAdminRole);
}

export function getConfigAdminRoleDecoder(): Decoder<ConfigAdminRole> {
return getEnumDecoder(ConfigAdminRole);
}

export function getConfigAdminRoleCodec(): Codec<
ConfigAdminRoleArgs,
ConfigAdminRole
> {
return combineCodec(getConfigAdminRoleEncoder(), getConfigAdminRoleDecoder());
}
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @see https://github.com/kinobi-so/kinobi
*/

export * from './configAdminRole';
export * from './fee';
export * from './fees';
export * from './weightEntry';
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ pub(crate) mod r#finalize_weight_table;
pub(crate) mod r#initialize_config;
pub(crate) mod r#initialize_weight_table;
pub(crate) mod r#set_config_fees;
pub(crate) mod r#set_new_admin;
pub(crate) mod r#update_weight_table;

pub use self::{
r#finalize_weight_table::*, r#initialize_config::*, r#initialize_weight_table::*,
r#set_config_fees::*, r#update_weight_table::*,
r#set_config_fees::*, r#set_new_admin::*, r#update_weight_table::*,
};
Loading

0 comments on commit 7ca1fd6

Please sign in to comment.