Skip to content

Commit

Permalink
almost ready for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 5, 2024
1 parent fe60486 commit 3a7f258
Show file tree
Hide file tree
Showing 25 changed files with 532 additions and 642 deletions.
176 changes: 131 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ serde = { version = "^1.0", features = ["derive"] }
serde_with = "3.9.0"
shank = "0.4.2"
shank_idl = "0.4.2"
spl-math = { version = "0.3.0", features = ["no-entrypoint"] }
solana-account-decoder = "~1.18"
solana-cli-config = "~1.18"
solana-program = "~1.18"
Expand Down
18 changes: 17 additions & 1 deletion clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,44 @@ export const JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO = 0x2100; // 8448
export const JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW = 0x2101; // 8449
/** ModuloOverflow: Modulo Overflow */
export const JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW = 0x2102; // 8450
/** NewPreciseNumberError: New precise number error */
export const JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR = 0x2103; // 8451
/** CastToImpreciseNumberError: Cast to imprecise number error */
export const JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR = 0x2104; // 8452
/** IncorrectWeightTableAdmin: Incorrect weight table admin */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN = 0x2200; // 8704
/** CannotCreateFutureWeightTables: Cannnot create future weight tables */
export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2201; // 8705
/** WeightMintsDoNotMatchLength: Weight mints do not match - length */
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH = 0x2202; // 8706
/** WeightMintsDoNotMatchMintHash: Weight mints do not match - mint hash */
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH = 0x2203; // 8707

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__CAST_TO_IMPRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS;
| typeof JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH;

let jitoTipRouterErrorMessages: Record<JitoTipRouterError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
jitoTipRouterErrorMessages = {
[JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW]: `Overflow`,
[JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES]: `Cannnot create future weight tables`,
[JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR]: `Cast to imprecise number error`,
[JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO]: `Zero in the denominator`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN]: `Incorrect weight table admin`,
[JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW]: `Modulo Overflow`,
[JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR]: `New precise number error`,
[JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS]: `No more table slots available`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH]: `Weight mints do not match - length`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH]: `Weight mints do not match - mint hash`,
};
}

Expand Down
10 changes: 10 additions & 0 deletions clients/js/jito_tip_router/instructions/finalizeWeightTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,23 @@ export type FinalizeWeightTableInstruction<
export type FinalizeWeightTableInstructionData = {
discriminator: number;
ncnEpoch: bigint;
mintHash: bigint;
mintCount: number;
};

export type FinalizeWeightTableInstructionDataArgs = {
ncnEpoch: number | bigint;
mintHash: number | bigint;
mintCount: number;
};

export function getFinalizeWeightTableInstructionDataEncoder(): Encoder<FinalizeWeightTableInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['ncnEpoch', getU64Encoder()],
['mintHash', getU64Encoder()],
['mintCount', getU8Encoder()],
]),
(value) => ({
...value,
Expand All @@ -90,6 +96,8 @@ export function getFinalizeWeightTableInstructionDataDecoder(): Decoder<Finalize
return getStructDecoder([
['discriminator', getU8Decoder()],
['ncnEpoch', getU64Decoder()],
['mintHash', getU64Decoder()],
['mintCount', getU8Decoder()],
]);
}

Expand All @@ -114,6 +122,8 @@ export type FinalizeWeightTableInput<
weightTableAdmin: TransactionSigner<TAccountWeightTableAdmin>;
restakingProgramId: Address<TAccountRestakingProgramId>;
ncnEpoch: FinalizeWeightTableInstructionDataArgs['ncnEpoch'];
mintHash: FinalizeWeightTableInstructionDataArgs['mintHash'];
mintCount: FinalizeWeightTableInstructionDataArgs['mintCount'];
};

export function getFinalizeWeightTableInstruction<
Expand Down
17 changes: 7 additions & 10 deletions clients/js/jito_tip_router/instructions/updateWeightTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
combineCodec,
getStructDecoder,
getStructEncoder,
getU128Decoder,
getU128Encoder,
getU64Decoder,
getU64Encoder,
getU8Decoder,
Expand Down Expand Up @@ -67,23 +69,20 @@ export type UpdateWeightTableInstruction<
export type UpdateWeightTableInstructionData = {
discriminator: number;
ncnEpoch: bigint;
weightNumerator: bigint;
weightDenominator: bigint;
weight: bigint;
};

export type UpdateWeightTableInstructionDataArgs = {
ncnEpoch: number | bigint;
weightNumerator: number | bigint;
weightDenominator: number | bigint;
weight: number | bigint;
};

export function getUpdateWeightTableInstructionDataEncoder(): Encoder<UpdateWeightTableInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['ncnEpoch', getU64Encoder()],
['weightNumerator', getU64Encoder()],
['weightDenominator', getU64Encoder()],
['weight', getU128Encoder()],
]),
(value) => ({ ...value, discriminator: UPDATE_WEIGHT_TABLE_DISCRIMINATOR })
);
Expand All @@ -93,8 +92,7 @@ export function getUpdateWeightTableInstructionDataDecoder(): Decoder<UpdateWeig
return getStructDecoder([
['discriminator', getU8Decoder()],
['ncnEpoch', getU64Decoder()],
['weightNumerator', getU64Decoder()],
['weightDenominator', getU64Decoder()],
['weight', getU128Decoder()],
]);
}

Expand All @@ -119,8 +117,7 @@ export type UpdateWeightTableInput<
weightTableAdmin: TransactionSigner<TAccountWeightTableAdmin>;
restakingProgramId: Address<TAccountRestakingProgramId>;
ncnEpoch: UpdateWeightTableInstructionDataArgs['ncnEpoch'];
weightNumerator: UpdateWeightTableInstructionDataArgs['weightNumerator'];
weightDenominator: UpdateWeightTableInstructionDataArgs['weightDenominator'];
weight: UpdateWeightTableInstructionDataArgs['weight'];
};

export function getUpdateWeightTableInstruction<
Expand Down
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,4 +6,5 @@
* @see https://github.com/kinobi-so/kinobi
*/

export * from './jitoNumber';
export * from './weightEntry';
40 changes: 40 additions & 0 deletions clients/js/jito_tip_router/types/jitoNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* 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,
getArrayDecoder,
getArrayEncoder,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
type Codec,
type Decoder,
type Encoder,
} from '@solana/web3.js';

export type JitoNumber = { value: Array<number> };

export type JitoNumberArgs = JitoNumber;

export function getJitoNumberEncoder(): Encoder<JitoNumberArgs> {
return getStructEncoder([
['value', getArrayEncoder(getU8Encoder(), { size: 16 })],
]);
}

export function getJitoNumberDecoder(): Decoder<JitoNumber> {
return getStructDecoder([
['value', getArrayDecoder(getU8Decoder(), { size: 16 })],
]);
}

export function getJitoNumberCodec(): Codec<JitoNumberArgs, JitoNumber> {
return combineCodec(getJitoNumberEncoder(), getJitoNumberDecoder());
}
16 changes: 10 additions & 6 deletions clients/js/jito_tip_router/types/weightEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@ import {
getAddressEncoder,
getStructDecoder,
getStructEncoder,
getU64Decoder,
getU64Encoder,
type Address,
type Codec,
type Decoder,
type Encoder,
} from '@solana/web3.js';
import {
getJitoNumberDecoder,
getJitoNumberEncoder,
type JitoNumber,
type JitoNumberArgs,
} from '.';

export type WeightEntry = { mint: Address; weight: bigint };
export type WeightEntry = { mint: Address; weight: JitoNumber };

export type WeightEntryArgs = { mint: Address; weight: number | bigint };
export type WeightEntryArgs = { mint: Address; weight: JitoNumberArgs };

export function getWeightEntryEncoder(): Encoder<WeightEntryArgs> {
return getStructEncoder([
['mint', getAddressEncoder()],
['weight', getU64Encoder()],
['weight', getJitoNumberEncoder()],
]);
}

export function getWeightEntryDecoder(): Decoder<WeightEntry> {
return getStructDecoder([
['mint', getAddressDecoder()],
['weight', getU64Decoder()],
['weight', getJitoNumberDecoder()],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ pub enum JitoTipRouterError {
/// 8450 - Modulo Overflow
#[error("Modulo Overflow")]
ModuloOverflow = 0x2102,
/// 8451 - New precise number error
#[error("New precise number error")]
NewPreciseNumberError = 0x2103,
/// 8452 - Cast to imprecise number error
#[error("Cast to imprecise number error")]
CastToImpreciseNumberError = 0x2104,
/// 8704 - Incorrect weight table admin
#[error("Incorrect weight table admin")]
IncorrectWeightTableAdmin = 0x2200,
/// 8705 - Cannnot create future weight tables
#[error("Cannnot create future weight tables")]
CannotCreateFutureWeightTables = 0x2201,
/// 8706 - Weight mints do not match - length
#[error("Weight mints do not match - length")]
WeightMintsDoNotMatchLength = 0x2202,
/// 8707 - Weight mints do not match - mint hash
#[error("Weight mints do not match - mint hash")]
WeightMintsDoNotMatchMintHash = 0x2203,
}

impl solana_program::program_error::PrintProgramError for JitoTipRouterError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ impl Default for FinalizeWeightTableInstructionData {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FinalizeWeightTableInstructionArgs {
pub ncn_epoch: u64,
pub mint_hash: u64,
pub mint_count: u8,
}

/// Instruction builder for `FinalizeWeightTable`.
Expand All @@ -99,6 +101,8 @@ pub struct FinalizeWeightTableBuilder {
weight_table_admin: Option<solana_program::pubkey::Pubkey>,
restaking_program_id: Option<solana_program::pubkey::Pubkey>,
ncn_epoch: Option<u64>,
mint_hash: Option<u64>,
mint_count: Option<u8>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}

Expand Down Expand Up @@ -137,6 +141,16 @@ impl FinalizeWeightTableBuilder {
self.ncn_epoch = Some(ncn_epoch);
self
}
#[inline(always)]
pub fn mint_hash(&mut self, mint_hash: u64) -> &mut Self {
self.mint_hash = Some(mint_hash);
self
}
#[inline(always)]
pub fn mint_count(&mut self, mint_count: u8) -> &mut Self {
self.mint_count = Some(mint_count);
self
}
/// Add an additional account to the instruction.
#[inline(always)]
pub fn add_remaining_account(
Expand Down Expand Up @@ -169,6 +183,8 @@ impl FinalizeWeightTableBuilder {
};
let args = FinalizeWeightTableInstructionArgs {
ncn_epoch: self.ncn_epoch.clone().expect("ncn_epoch is not set"),
mint_hash: self.mint_hash.clone().expect("mint_hash is not set"),
mint_count: self.mint_count.clone().expect("mint_count is not set"),
};

accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
Expand Down Expand Up @@ -325,6 +341,8 @@ impl<'a, 'b> FinalizeWeightTableCpiBuilder<'a, 'b> {
weight_table_admin: None,
restaking_program_id: None,
ncn_epoch: None,
mint_hash: None,
mint_count: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
Expand Down Expand Up @@ -363,6 +381,16 @@ impl<'a, 'b> FinalizeWeightTableCpiBuilder<'a, 'b> {
self.instruction.ncn_epoch = Some(ncn_epoch);
self
}
#[inline(always)]
pub fn mint_hash(&mut self, mint_hash: u64) -> &mut Self {
self.instruction.mint_hash = Some(mint_hash);
self
}
#[inline(always)]
pub fn mint_count(&mut self, mint_count: u8) -> &mut Self {
self.instruction.mint_count = Some(mint_count);
self
}
/// Add an additional account to the instruction.
#[inline(always)]
pub fn add_remaining_account(
Expand Down Expand Up @@ -410,6 +438,16 @@ impl<'a, 'b> FinalizeWeightTableCpiBuilder<'a, 'b> {
.ncn_epoch
.clone()
.expect("ncn_epoch is not set"),
mint_hash: self
.instruction
.mint_hash
.clone()
.expect("mint_hash is not set"),
mint_count: self
.instruction
.mint_count
.clone()
.expect("mint_count is not set"),
};
let instruction = FinalizeWeightTableCpi {
__program: self.instruction.__program,
Expand Down Expand Up @@ -447,6 +485,8 @@ struct FinalizeWeightTableCpiBuilderInstruction<'a, 'b> {
weight_table_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>,
restaking_program_id: Option<&'b solana_program::account_info::AccountInfo<'a>>,
ncn_epoch: Option<u64>,
mint_hash: Option<u64>,
mint_count: Option<u8>,
/// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
Expand Down
Loading

0 comments on commit 3a7f258

Please sign in to comment.