Skip to content

Commit

Permalink
Some feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Nov 7, 2024
1 parent f3f9f47 commit b033c72
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 301 deletions.
6 changes: 5 additions & 1 deletion clients/js/jito_tip_router/accounts/ncnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type NcnConfig = {
discriminator: bigint;
ncn: Address;
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: Fees;
bump: number;
reserved: Array<number>;
Expand All @@ -54,6 +55,7 @@ export type NcnConfigArgs = {
discriminator: number | bigint;
ncn: Address;
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: FeesArgs;
bump: number;
reserved: Array<number>;
Expand All @@ -64,6 +66,7 @@ export function getNcnConfigEncoder(): Encoder<NcnConfigArgs> {
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['tieBreakerAdmin', getAddressEncoder()],
['feeAdmin', getAddressEncoder()],
['fees', getFeesEncoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 127 })],
Expand All @@ -75,6 +78,7 @@ export function getNcnConfigDecoder(): Decoder<NcnConfig> {
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['tieBreakerAdmin', getAddressDecoder()],
['feeAdmin', getAddressDecoder()],
['fees', getFeesDecoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 127 })],
Expand Down Expand Up @@ -139,5 +143,5 @@ export async function fetchAllMaybeNcnConfig(
}

export function getNcnConfigSize(): number {
return 320;
return 352;
}
4 changes: 4 additions & 0 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ export const JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED = 0x2300; // 8960
export const JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN = 0x2400; // 9216
/** IncorrectNcn: Incorrect NCN */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_NCN = 0x2401; // 9217
/** IncorrectFeeAdmin: Incorrect fee admin */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN = 0x2402; // 9218

export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES
| typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO
| typeof JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN
Expand All @@ -51,6 +54,7 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES]: `Cannnot create future weight tables`,
[JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO]: `Zero in the denominator`,
[JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED]: `Fee cap exceeded`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN]: `Incorrect fee admin`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_NCN]: `Incorrect NCN`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN]: `Incorrect NCN Admin`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN]: `Incorrect weight table admin`,
Expand Down
32 changes: 16 additions & 16 deletions clients/js/jito_tip_router/instructions/initializeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export type InitializeConfigInstruction<
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,
TAccountFeeWallet extends string | IAccountMeta<string> = string,
TAccountTieBreakerAdmin extends string | IAccountMeta<string> = string,
TAccountPayer extends string | IAccountMeta<string> = string,
TAccountRestakingProgramId extends string | IAccountMeta<string> = string,
TAccountSystemProgram extends
| string
Expand All @@ -55,15 +55,15 @@ export type InitializeConfigInstruction<
? WritableAccount<TAccountConfig>
: TAccountConfig,
TAccountNcn extends string ? ReadonlyAccount<TAccountNcn> : TAccountNcn,
TAccountNcnAdmin extends string
? WritableAccount<TAccountNcnAdmin>
: TAccountNcnAdmin,
TAccountFeeWallet extends string
? ReadonlyAccount<TAccountFeeWallet>
: TAccountFeeWallet,
TAccountTieBreakerAdmin extends string
? ReadonlyAccount<TAccountTieBreakerAdmin>
: TAccountTieBreakerAdmin,
TAccountPayer extends string
? WritableAccount<TAccountPayer>
: TAccountPayer,
TAccountRestakingProgramId extends string
? ReadonlyAccount<TAccountRestakingProgramId>
: TAccountRestakingProgramId,
Expand Down Expand Up @@ -121,17 +121,17 @@ export function getInitializeConfigInstructionDataCodec(): Codec<
export type InitializeConfigInput<
TAccountConfig extends string = string,
TAccountNcn extends string = string,
TAccountNcnAdmin extends string = string,
TAccountFeeWallet extends string = string,
TAccountTieBreakerAdmin extends string = string,
TAccountPayer extends string = string,
TAccountRestakingProgramId extends string = string,
TAccountSystemProgram extends string = string,
> = {
config: Address<TAccountConfig>;
ncn: Address<TAccountNcn>;
ncnAdmin: Address<TAccountNcnAdmin>;
feeWallet: Address<TAccountFeeWallet>;
tieBreakerAdmin: Address<TAccountTieBreakerAdmin>;
payer: Address<TAccountPayer>;
restakingProgramId: Address<TAccountRestakingProgramId>;
systemProgram?: Address<TAccountSystemProgram>;
daoFeeBps: InitializeConfigInstructionDataArgs['daoFeeBps'];
Expand All @@ -142,19 +142,19 @@ export type InitializeConfigInput<
export function getInitializeConfigInstruction<
TAccountConfig extends string,
TAccountNcn extends string,
TAccountNcnAdmin extends string,
TAccountFeeWallet extends string,
TAccountTieBreakerAdmin extends string,
TAccountPayer extends string,
TAccountRestakingProgramId extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: InitializeConfigInput<
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountFeeWallet,
TAccountTieBreakerAdmin,
TAccountPayer,
TAccountRestakingProgramId,
TAccountSystemProgram
>,
Expand All @@ -163,9 +163,9 @@ export function getInitializeConfigInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountFeeWallet,
TAccountTieBreakerAdmin,
TAccountPayer,
TAccountRestakingProgramId,
TAccountSystemProgram
> {
Expand All @@ -177,12 +177,12 @@ export function getInitializeConfigInstruction<
const originalAccounts = {
config: { value: input.config ?? null, isWritable: true },
ncn: { value: input.ncn ?? null, isWritable: false },
ncnAdmin: { value: input.ncnAdmin ?? null, isWritable: true },
feeWallet: { value: input.feeWallet ?? null, isWritable: false },
tieBreakerAdmin: {
value: input.tieBreakerAdmin ?? null,
isWritable: false,
},
payer: { value: input.payer ?? null, isWritable: true },
restakingProgramId: {
value: input.restakingProgramId ?? null,
isWritable: false,
Expand All @@ -208,9 +208,9 @@ export function getInitializeConfigInstruction<
accounts: [
getAccountMeta(accounts.config),
getAccountMeta(accounts.ncn),
getAccountMeta(accounts.ncnAdmin),
getAccountMeta(accounts.feeWallet),
getAccountMeta(accounts.tieBreakerAdmin),
getAccountMeta(accounts.payer),
getAccountMeta(accounts.restakingProgramId),
getAccountMeta(accounts.systemProgram),
],
Expand All @@ -222,9 +222,9 @@ export function getInitializeConfigInstruction<
TProgramAddress,
TAccountConfig,
TAccountNcn,
TAccountNcnAdmin,
TAccountFeeWallet,
TAccountTieBreakerAdmin,
TAccountPayer,
TAccountRestakingProgramId,
TAccountSystemProgram
>;
Expand All @@ -240,9 +240,9 @@ export type ParsedInitializeConfigInstruction<
accounts: {
config: TAccountMetas[0];
ncn: TAccountMetas[1];
feeWallet: TAccountMetas[2];
tieBreakerAdmin: TAccountMetas[3];
payer: TAccountMetas[4];
ncnAdmin: TAccountMetas[2];
feeWallet: TAccountMetas[3];
tieBreakerAdmin: TAccountMetas[4];
restakingProgramId: TAccountMetas[5];
systemProgram: TAccountMetas[6];
};
Expand Down Expand Up @@ -272,9 +272,9 @@ export function parseInitializeConfigInstruction<
accounts: {
config: getNextAccount(),
ncn: getNextAccount(),
ncnAdmin: getNextAccount(),
feeWallet: getNextAccount(),
tieBreakerAdmin: getNextAccount(),
payer: getNextAccount(),
restakingProgramId: getNextAccount(),
systemProgram: getNextAccount(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ pub struct NcnConfig {
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub tie_breaker_admin: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub fee_admin: Pubkey,
pub fees: Fees,
pub bump: u8,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 127],
}

impl NcnConfig {
pub const LEN: usize = 320;
pub const LEN: usize = 352;

#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub enum JitoTipRouterError {
/// 9217 - Incorrect NCN
#[error("Incorrect NCN")]
IncorrectNcn = 0x2401,
/// 9218 - Incorrect fee admin
#[error("Incorrect fee admin")]
IncorrectFeeAdmin = 0x2402,
}

impl solana_program::program_error::PrintProgramError for JitoTipRouterError {
Expand Down
Loading

0 comments on commit b033c72

Please sign in to comment.