Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 7, 2024
1 parent 736e293 commit 6851eee
Show file tree
Hide file tree
Showing 37 changed files with 611 additions and 1,518 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ jito-tip-router-client = { path = "./clients/rust/jito_tip_router", version = "0
jito-tip-router-core = { path = "./core", version = "=0.0.1" }
jito-tip-router-program = { path = "./program", version = "=0.0.1" }
jito-tip-router-shank-cli = { path = "./shank_cli", version = "=0.0.1" }
jito-bytemuck = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-account-traits-derive = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-jsm-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-restaking-client = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-restaking-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-restaking-program = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3", features = ["no-entrypoint"] }
jito-restaking-sdk = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-vault-client = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-vault-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-vault-program = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3", features = ["no-entrypoint"] }
jito-vault-sdk = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" }
jito-bytemuck = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-account-traits-derive = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-jsm-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-restaking-client = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-restaking-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-restaking-program = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d", features = ["no-entrypoint"] }
jito-restaking-sdk = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-vault-client = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-vault-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
jito-vault-program = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d", features = ["no-entrypoint"] }
jito-vault-sdk = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" }
4 changes: 0 additions & 4 deletions clients/js/jito_tip_router/accounts/weightTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export type WeightTable = {
ncn: Address;
ncnEpoch: bigint;
slotCreated: bigint;
slotFinalized: bigint;
bump: number;
reserved: Array<number>;
table: Array<WeightEntry>;
Expand All @@ -57,7 +56,6 @@ export type WeightTableArgs = {
ncn: Address;
ncnEpoch: number | bigint;
slotCreated: number | bigint;
slotFinalized: number | bigint;
bump: number;
reserved: Array<number>;
table: Array<WeightEntryArgs>;
Expand All @@ -69,7 +67,6 @@ export function getWeightTableEncoder(): Encoder<WeightTableArgs> {
['ncn', getAddressEncoder()],
['ncnEpoch', getU64Encoder()],
['slotCreated', getU64Encoder()],
['slotFinalized', getU64Encoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
['table', getArrayEncoder(getWeightEntryEncoder(), { size: 32 })],
Expand All @@ -82,7 +79,6 @@ export function getWeightTableDecoder(): Decoder<WeightTable> {
['ncn', getAddressDecoder()],
['ncnEpoch', getU64Decoder()],
['slotCreated', getU64Decoder()],
['slotFinalized', getU64Decoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
['table', getArrayDecoder(getWeightEntryDecoder(), { size: 32 })],
Expand Down
32 changes: 24 additions & 8 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
} from '@solana/web3.js';
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';

/** NoMoreTableSlots: No more table slots available */
export const JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS = 0x2000; // 8192
/** DenominatorIsZero: Zero in the denominator */
export const JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO = 0x2100; // 8448
/** ArithmeticOverflow: Overflow */
Expand All @@ -28,24 +26,38 @@ export const JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR = 0x2103; // 8451
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
/** DuplicateMintsInTable: Duplicate mints in table */
export const JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE = 0x2201; // 8705
/** NoMintsInTable: There are no mints in the table */
export const JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE = 0x2202; // 8706
/** TooManyMintsForTable: Too many mints for table */
export const JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE = 0x2203; // 8707
/** WeightTableAlreadyInitialized: Weight table already initialized */
export const JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED = 0x2204; // 8708
/** CannotCreateFutureWeightTables: Cannnot create future weight tables */
export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2201; // 8705
export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2205; // 8709
/** WeightMintsDoNotMatchLength: Weight mints do not match - length */
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH = 0x2202; // 8706
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH = 0x2206; // 8710
/** WeightMintsDoNotMatchMintHash: Weight mints do not match - mint hash */
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH = 0x2203; // 8707
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH = 0x2207; // 8711
/** InvalidMintForWeightTable: Invalid mint for weight table */
export const JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE = 0x2208; // 8712

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__DUPLICATE_MINTS_IN_TABLE
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE
| typeof JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS
| typeof JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE
| typeof JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH;
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED;

let jitoTipRouterErrorMessages: Record<JitoTipRouterError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -54,12 +66,16 @@ if (process.env.NODE_ENV !== 'production') {
[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__DUPLICATE_MINTS_IN_TABLE]: `Duplicate mints in table`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN]: `Incorrect weight table admin`,
[JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE]: `Invalid mint for weight table`,
[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__NO_MINTS_IN_TABLE]: `There are no mints in the table`,
[JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE]: `Too many mints for table`,
[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`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED]: `Weight table already initialized`,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 1;
export const ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 1;

export function getUpdateWeightTableDiscriminatorBytes() {
return getU8Encoder().encode(UPDATE_WEIGHT_TABLE_DISCRIMINATOR);
export function getAdminUpdateWeightTableDiscriminatorBytes() {
return getU8Encoder().encode(ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR);
}

export type UpdateWeightTableInstruction<
export type AdminUpdateWeightTableInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountNcn extends string | IAccountMeta<string> = string,
TAccountWeightTable extends string | IAccountMeta<string> = string,
Expand All @@ -66,47 +66,50 @@ export type UpdateWeightTableInstruction<
]
>;

export type UpdateWeightTableInstructionData = {
export type AdminUpdateWeightTableInstructionData = {
discriminator: number;
ncnEpoch: bigint;
weight: bigint;
};

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

export function getUpdateWeightTableInstructionDataEncoder(): Encoder<UpdateWeightTableInstructionDataArgs> {
export function getAdminUpdateWeightTableInstructionDataEncoder(): Encoder<AdminUpdateWeightTableInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['ncnEpoch', getU64Encoder()],
['weight', getU128Encoder()],
]),
(value) => ({ ...value, discriminator: UPDATE_WEIGHT_TABLE_DISCRIMINATOR })
(value) => ({
...value,
discriminator: ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR,
})
);
}

export function getUpdateWeightTableInstructionDataDecoder(): Decoder<UpdateWeightTableInstructionData> {
export function getAdminUpdateWeightTableInstructionDataDecoder(): Decoder<AdminUpdateWeightTableInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['ncnEpoch', getU64Decoder()],
['weight', getU128Decoder()],
]);
}

export function getUpdateWeightTableInstructionDataCodec(): Codec<
UpdateWeightTableInstructionDataArgs,
UpdateWeightTableInstructionData
export function getAdminUpdateWeightTableInstructionDataCodec(): Codec<
AdminUpdateWeightTableInstructionDataArgs,
AdminUpdateWeightTableInstructionData
> {
return combineCodec(
getUpdateWeightTableInstructionDataEncoder(),
getUpdateWeightTableInstructionDataDecoder()
getAdminUpdateWeightTableInstructionDataEncoder(),
getAdminUpdateWeightTableInstructionDataDecoder()
);
}

export type UpdateWeightTableInput<
export type AdminUpdateWeightTableInput<
TAccountNcn extends string = string,
TAccountWeightTable extends string = string,
TAccountWeightTableAdmin extends string = string,
Expand All @@ -116,25 +119,25 @@ export type UpdateWeightTableInput<
weightTable: Address<TAccountWeightTable>;
weightTableAdmin: TransactionSigner<TAccountWeightTableAdmin>;
restakingProgramId: Address<TAccountRestakingProgramId>;
ncnEpoch: UpdateWeightTableInstructionDataArgs['ncnEpoch'];
weight: UpdateWeightTableInstructionDataArgs['weight'];
ncnEpoch: AdminUpdateWeightTableInstructionDataArgs['ncnEpoch'];
weight: AdminUpdateWeightTableInstructionDataArgs['weight'];
};

export function getUpdateWeightTableInstruction<
export function getAdminUpdateWeightTableInstruction<
TAccountNcn extends string,
TAccountWeightTable extends string,
TAccountWeightTableAdmin extends string,
TAccountRestakingProgramId extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: UpdateWeightTableInput<
input: AdminUpdateWeightTableInput<
TAccountNcn,
TAccountWeightTable,
TAccountWeightTableAdmin,
TAccountRestakingProgramId
>,
config?: { programAddress?: TProgramAddress }
): UpdateWeightTableInstruction<
): AdminUpdateWeightTableInstruction<
TProgramAddress,
TAccountNcn,
TAccountWeightTable,
Expand Down Expand Up @@ -175,10 +178,10 @@ export function getUpdateWeightTableInstruction<
getAccountMeta(accounts.restakingProgramId),
],
programAddress,
data: getUpdateWeightTableInstructionDataEncoder().encode(
args as UpdateWeightTableInstructionDataArgs
data: getAdminUpdateWeightTableInstructionDataEncoder().encode(
args as AdminUpdateWeightTableInstructionDataArgs
),
} as UpdateWeightTableInstruction<
} as AdminUpdateWeightTableInstruction<
TProgramAddress,
TAccountNcn,
TAccountWeightTable,
Expand All @@ -189,7 +192,7 @@ export function getUpdateWeightTableInstruction<
return instruction;
}

export type ParsedUpdateWeightTableInstruction<
export type ParsedAdminUpdateWeightTableInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
Expand All @@ -200,17 +203,17 @@ export type ParsedUpdateWeightTableInstruction<
weightTableAdmin: TAccountMetas[2];
restakingProgramId: TAccountMetas[3];
};
data: UpdateWeightTableInstructionData;
data: AdminUpdateWeightTableInstructionData;
};

export function parseUpdateWeightTableInstruction<
export function parseAdminUpdateWeightTableInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedUpdateWeightTableInstruction<TProgram, TAccountMetas> {
): ParsedAdminUpdateWeightTableInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
Expand All @@ -229,6 +232,8 @@ export function parseUpdateWeightTableInstruction<
weightTableAdmin: getNextAccount(),
restakingProgramId: getNextAccount(),
},
data: getUpdateWeightTableInstructionDataDecoder().decode(instruction.data),
data: getAdminUpdateWeightTableInstructionDataDecoder().decode(
instruction.data
),
};
}
Loading

0 comments on commit 6851eee

Please sign in to comment.