Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Dec 15, 2024
1 parent 7d1568e commit 894ab8f
Show file tree
Hide file tree
Showing 61 changed files with 2,012 additions and 114 deletions.
522 changes: 494 additions & 28 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 @@ -71,6 +71,7 @@ solana-rpc-client-api = "~1.18"
solana-security-txt = "1.1.1"
spl-associated-token-account = { version = "2.2.0", features = ["no-entrypoint"] }
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
switchboard-on-demand = "0.1.0"
syn = "2.0.72"
thiserror = "1.0.57"
tokio = { version = "1.36.0", features = ["full"] }
Expand Down
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 @@ -30,6 +30,8 @@ export const JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR = 0x2105; // 8453
export const JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR = 0x2106; // 8454
/** CastToU64Error: Cast to u64 error */
export const JITO_TIP_ROUTER_ERROR__CAST_TO_U64_ERROR = 0x2107; // 8455
/** CastToU128Error: Cast to u128 error */
export const JITO_TIP_ROUTER_ERROR__CAST_TO_U128_ERROR = 0x2108; // 8456
/** IncorrectWeightTableAdmin: Incorrect weight table admin */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN = 0x2200; // 8704
/** DuplicateMintsInTable: Duplicate mints in table */
Expand Down Expand Up @@ -137,6 +139,7 @@ export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__BALLOT_TALLY_NOT_FOUND_FULL
| 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__CAST_TO_U128_ERROR
| typeof JITO_TIP_ROUTER_ERROR__CAST_TO_U64_ERROR
| typeof JITO_TIP_ROUTER_ERROR__CONFIG_MINT_LIST_FULL
| typeof JITO_TIP_ROUTER_ERROR__CONFIG_MINTS_NOT_UPDATED
Expand Down Expand Up @@ -198,6 +201,7 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__BALLOT_TALLY_NOT_FOUND_FULL]: `Ballot tally not found`,
[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__CAST_TO_U128_ERROR]: `Cast to u128 error`,
[JITO_TIP_ROUTER_ERROR__CAST_TO_U64_ERROR]: `Cast to u64 error`,
[JITO_TIP_ROUTER_ERROR__CONFIG_MINT_LIST_FULL]: `NCN config vaults are at capacity`,
[JITO_TIP_ROUTER_ERROR__CONFIG_MINTS_NOT_UPDATED]: `Config supported mints do not match NCN Vault Count`,
Expand Down
2 changes: 1 addition & 1 deletion clients/js/jito_tip_router/instructions/castVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const CAST_VOTE_DISCRIMINATOR = 20;
export const CAST_VOTE_DISCRIMINATOR = 22;

export function getCastVoteDiscriminatorBytes() {
return getU8Encoder().encode(CAST_VOTE_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const DISTRIBUTE_BASE_NCN_REWARD_ROUTE_DISCRIMINATOR = 15;
export const DISTRIBUTE_BASE_NCN_REWARD_ROUTE_DISCRIMINATOR = 17;

export function getDistributeBaseNcnRewardRouteDiscriminatorBytes() {
return getU8Encoder().encode(DISTRIBUTE_BASE_NCN_REWARD_ROUTE_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const DISTRIBUTE_BASE_REWARDS_DISCRIMINATOR = 14;
export const DISTRIBUTE_BASE_REWARDS_DISCRIMINATOR = 16;

export function getDistributeBaseRewardsDiscriminatorBytes() {
return getU8Encoder().encode(DISTRIBUTE_BASE_REWARDS_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const DISTRIBUTE_NCN_OPERATOR_REWARDS_DISCRIMINATOR = 16;
export const DISTRIBUTE_NCN_OPERATOR_REWARDS_DISCRIMINATOR = 18;

export function getDistributeNcnOperatorRewardsDiscriminatorBytes() {
return getU8Encoder().encode(DISTRIBUTE_NCN_OPERATOR_REWARDS_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const DISTRIBUTE_NCN_VAULT_REWARDS_DISCRIMINATOR = 17;
export const DISTRIBUTE_NCN_VAULT_REWARDS_DISCRIMINATOR = 19;

export function getDistributeNcnVaultRewardsDiscriminatorBytes() {
return getU8Encoder().encode(DISTRIBUTE_NCN_VAULT_REWARDS_DISCRIMINATOR);
Expand Down
2 changes: 2 additions & 0 deletions clients/js/jito_tip_router/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export * from './registerMint';
export * from './routeBaseRewards';
export * from './routeNcnRewards';
export * from './setConfigFees';
export * from './setJtoWeight';
export * from './setLstWeight';
export * from './setMerkleRoot';
export * from './setNewAdmin';
export * from './setTieBreaker';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_BALLOT_BOX_DISCRIMINATOR = 19;
export const INITIALIZE_BALLOT_BOX_DISCRIMINATOR = 21;

export function getInitializeBallotBoxDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_BALLOT_BOX_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_BASE_REWARD_ROUTER_DISCRIMINATOR = 10;
export const INITIALIZE_BASE_REWARD_ROUTER_DISCRIMINATOR = 12;

export function getInitializeBaseRewardRouterDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_BASE_REWARD_ROUTER_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_EPOCH_SNAPSHOT_DISCRIMINATOR = 6;
export const INITIALIZE_EPOCH_SNAPSHOT_DISCRIMINATOR = 8;

export function getInitializeEpochSnapshotDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_EPOCH_SNAPSHOT_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_NCN_REWARD_ROUTER_DISCRIMINATOR = 11;
export const INITIALIZE_NCN_REWARD_ROUTER_DISCRIMINATOR = 13;

export function getInitializeNcnRewardRouterDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_NCN_REWARD_ROUTER_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const INITIALIZE_OPERATOR_SNAPSHOT_DISCRIMINATOR = 7;
export const INITIALIZE_OPERATOR_SNAPSHOT_DISCRIMINATOR = 9;

export function getInitializeOperatorSnapshotDiscriminatorBytes() {
return getU8Encoder().encode(INITIALIZE_OPERATOR_SNAPSHOT_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REALLOC_BALLOT_BOX_DISCRIMINATOR = 23;
export const REALLOC_BALLOT_BOX_DISCRIMINATOR = 25;

export function getReallocBallotBoxDiscriminatorBytes() {
return getU8Encoder().encode(REALLOC_BALLOT_BOX_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REALLOC_BASE_REWARD_ROUTER_DISCRIMINATOR = 25;
export const REALLOC_BASE_REWARD_ROUTER_DISCRIMINATOR = 27;

export function getReallocBaseRewardRouterDiscriminatorBytes() {
return getU8Encoder().encode(REALLOC_BASE_REWARD_ROUTER_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REALLOC_OPERATOR_SNAPSHOT_DISCRIMINATOR = 24;
export const REALLOC_OPERATOR_SNAPSHOT_DISCRIMINATOR = 26;

export function getReallocOperatorSnapshotDiscriminatorBytes() {
return getU8Encoder().encode(REALLOC_OPERATOR_SNAPSHOT_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REALLOC_WEIGHT_TABLE_DISCRIMINATOR = 26;
export const REALLOC_WEIGHT_TABLE_DISCRIMINATOR = 28;

export function getReallocWeightTableDiscriminatorBytes() {
return getU8Encoder().encode(REALLOC_WEIGHT_TABLE_DISCRIMINATOR);
Expand Down
2 changes: 1 addition & 1 deletion clients/js/jito_tip_router/instructions/registerMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REGISTER_MINT_DISCRIMINATOR = 9;
export const REGISTER_MINT_DISCRIMINATOR = 11;

export function getRegisterMintDiscriminatorBytes() {
return getU8Encoder().encode(REGISTER_MINT_DISCRIMINATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const ROUTE_BASE_REWARDS_DISCRIMINATOR = 12;
export const ROUTE_BASE_REWARDS_DISCRIMINATOR = 14;

export function getRouteBaseRewardsDiscriminatorBytes() {
return getU8Encoder().encode(ROUTE_BASE_REWARDS_DISCRIMINATOR);
Expand Down
2 changes: 1 addition & 1 deletion clients/js/jito_tip_router/instructions/routeNcnRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const ROUTE_NCN_REWARDS_DISCRIMINATOR = 13;
export const ROUTE_NCN_REWARDS_DISCRIMINATOR = 15;

export function getRouteNcnRewardsDiscriminatorBytes() {
return getU8Encoder().encode(ROUTE_NCN_REWARDS_DISCRIMINATOR);
Expand Down
201 changes: 201 additions & 0 deletions clients/js/jito_tip_router/instructions/setJtoWeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/**
* 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,
getU64Decoder,
getU64Encoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type ReadonlyAccount,
type WritableAccount,
} from '@solana/web3.js';
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const SET_JTO_WEIGHT_DISCRIMINATOR = 7;

export function getSetJtoWeightDiscriminatorBytes() {
return getU8Encoder().encode(SET_JTO_WEIGHT_DISCRIMINATOR);
}

export type SetJtoWeightInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountNcn extends string | IAccountMeta<string> = string,
TAccountWeightTable extends string | IAccountMeta<string> = string,
TAccountJtoUsdFeed extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountNcn extends string ? ReadonlyAccount<TAccountNcn> : TAccountNcn,
TAccountWeightTable extends string
? WritableAccount<TAccountWeightTable>
: TAccountWeightTable,
TAccountJtoUsdFeed extends string
? ReadonlyAccount<TAccountJtoUsdFeed>
: TAccountJtoUsdFeed,
...TRemainingAccounts,
]
>;

export type SetJtoWeightInstructionData = {
discriminator: number;
epoch: bigint;
};

export type SetJtoWeightInstructionDataArgs = { epoch: number | bigint };

export function getSetJtoWeightInstructionDataEncoder(): Encoder<SetJtoWeightInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['epoch', getU64Encoder()],
]),
(value) => ({ ...value, discriminator: SET_JTO_WEIGHT_DISCRIMINATOR })
);
}

export function getSetJtoWeightInstructionDataDecoder(): Decoder<SetJtoWeightInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['epoch', getU64Decoder()],
]);
}

export function getSetJtoWeightInstructionDataCodec(): Codec<
SetJtoWeightInstructionDataArgs,
SetJtoWeightInstructionData
> {
return combineCodec(
getSetJtoWeightInstructionDataEncoder(),
getSetJtoWeightInstructionDataDecoder()
);
}

export type SetJtoWeightInput<
TAccountNcn extends string = string,
TAccountWeightTable extends string = string,
TAccountJtoUsdFeed extends string = string,
> = {
ncn: Address<TAccountNcn>;
weightTable: Address<TAccountWeightTable>;
jtoUsdFeed: Address<TAccountJtoUsdFeed>;
epoch: SetJtoWeightInstructionDataArgs['epoch'];
};

export function getSetJtoWeightInstruction<
TAccountNcn extends string,
TAccountWeightTable extends string,
TAccountJtoUsdFeed extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: SetJtoWeightInput<
TAccountNcn,
TAccountWeightTable,
TAccountJtoUsdFeed
>,
config?: { programAddress?: TProgramAddress }
): SetJtoWeightInstruction<
TProgramAddress,
TAccountNcn,
TAccountWeightTable,
TAccountJtoUsdFeed
> {
// Program address.
const programAddress =
config?.programAddress ?? JITO_TIP_ROUTER_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
ncn: { value: input.ncn ?? null, isWritable: false },
weightTable: { value: input.weightTable ?? null, isWritable: true },
jtoUsdFeed: { value: input.jtoUsdFeed ?? 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.ncn),
getAccountMeta(accounts.weightTable),
getAccountMeta(accounts.jtoUsdFeed),
],
programAddress,
data: getSetJtoWeightInstructionDataEncoder().encode(
args as SetJtoWeightInstructionDataArgs
),
} as SetJtoWeightInstruction<
TProgramAddress,
TAccountNcn,
TAccountWeightTable,
TAccountJtoUsdFeed
>;

return instruction;
}

export type ParsedSetJtoWeightInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
ncn: TAccountMetas[0];
weightTable: TAccountMetas[1];
jtoUsdFeed: TAccountMetas[2];
};
data: SetJtoWeightInstructionData;
};

export function parseSetJtoWeightInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedSetJtoWeightInstruction<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: {
ncn: getNextAccount(),
weightTable: getNextAccount(),
jtoUsdFeed: getNextAccount(),
},
data: getSetJtoWeightInstructionDataDecoder().decode(instruction.data),
};
}
Loading

0 comments on commit 894ab8f

Please sign in to comment.