Skip to content

Commit

Permalink
epoch marker
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Jan 22, 2025
1 parent 3613f86 commit b0908f5
Show file tree
Hide file tree
Showing 49 changed files with 1,333 additions and 291 deletions.
29 changes: 29 additions & 0 deletions cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use jito_tip_router_core::{
base_reward_router::{BaseRewardReceiver, BaseRewardRouter},
config::Config as TipRouterConfig,
constants::MAX_REALLOC_BYTES,
epoch_marker::EpochMarker,
epoch_snapshot::{EpochSnapshot, OperatorSnapshot},
epoch_state::EpochState,
ncn_fee_group::NcnFeeGroup,
Expand Down Expand Up @@ -323,6 +324,9 @@ pub async fn create_epoch_state(handler: &CliHandler, epoch: u64) -> Result<()>
let (epoch_state, _, _) =
EpochState::find_program_address(&handler.tip_router_program_id, &ncn, epoch);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
Expand All @@ -334,6 +338,7 @@ pub async fn create_epoch_state(handler: &CliHandler, epoch: u64) -> Result<()>
if epoch_state_account.is_none() {
// Initialize ballot box
let initialize_ballot_box_ix = InitializeEpochStateBuilder::new()
.epoch_marker(epoch_marker)
.config(config)
.epoch_state(epoch_state)
.ncn(ncn)
Expand Down Expand Up @@ -402,6 +407,9 @@ pub async fn create_weight_table(handler: &CliHandler, epoch: u64) -> Result<()>
let (epoch_state, _, _) =
EpochState::find_program_address(&handler.tip_router_program_id, &ncn, epoch);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
Expand All @@ -413,6 +421,7 @@ pub async fn create_weight_table(handler: &CliHandler, epoch: u64) -> Result<()>
if weight_table_account.is_none() {
// Initialize weight table
let initialize_weight_table_ix = InitializeWeightTableBuilder::new()
.epoch_marker(epoch_marker)
.vault_registry(vault_registry)
.ncn(ncn)
.epoch_state(epoch_state)
Expand Down Expand Up @@ -588,12 +597,16 @@ pub async fn create_epoch_snapshot(handler: &CliHandler, epoch: u64) -> Result<(
let (epoch_snapshot, _, _) =
EpochSnapshot::find_program_address(&handler.tip_router_program_id, &ncn, epoch);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
);

let initialize_epoch_snapshot_ix = InitializeEpochSnapshotBuilder::new()
.epoch_marker(epoch_marker)
.config(config)
.ncn(ncn)
.epoch_state(epoch_state)
Expand Down Expand Up @@ -644,6 +657,9 @@ pub async fn create_operator_snapshot(
epoch,
);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
Expand All @@ -655,6 +671,7 @@ pub async fn create_operator_snapshot(
if operator_snapshot_account.is_none() {
// Initialize operator snapshot
let initialize_operator_snapshot_ix = InitializeOperatorSnapshotBuilder::new()
.epoch_marker(epoch_marker)
.config(config)
.ncn(ncn)
.operator(operator)
Expand Down Expand Up @@ -808,6 +825,9 @@ pub async fn create_ballot_box(handler: &CliHandler, epoch: u64) -> Result<()> {
let (ballot_box, _, _) =
BallotBox::find_program_address(&handler.tip_router_program_id, &ncn, epoch);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
Expand All @@ -819,6 +839,7 @@ pub async fn create_ballot_box(handler: &CliHandler, epoch: u64) -> Result<()> {
if ballot_box_account.is_none() {
// Initialize ballot box
let initialize_ballot_box_ix = InitializeBallotBoxBuilder::new()
.epoch_marker(epoch_marker)
.config(config)
.epoch_state(epoch_state)
.ballot_box(ballot_box)
Expand Down Expand Up @@ -947,6 +968,9 @@ pub async fn create_base_reward_router(handler: &CliHandler, epoch: u64) -> Resu
let (base_reward_receiver, _, _) =
BaseRewardReceiver::find_program_address(&handler.tip_router_program_id, &ncn, epoch);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
Expand All @@ -957,6 +981,7 @@ pub async fn create_base_reward_router(handler: &CliHandler, epoch: u64) -> Resu
// Skip if base reward router already exists
if base_reward_router_account.is_none() {
let initialize_base_reward_router_ix = InitializeBaseRewardRouterBuilder::new()
.epoch_marker(epoch_marker)
.ncn(ncn)
.epoch_state(epoch_state)
.base_reward_router(base_reward_router)
Expand Down Expand Up @@ -1047,12 +1072,16 @@ pub async fn create_ncn_reward_router(
epoch,
);

let (epoch_marker, _, _) =
EpochMarker::find_program_address(&jito_tip_router_program::id(), &ncn, epoch);

let (account_payer, _, _) = AccountPayer::find_program_address(
&handler.tip_router_program_id,
&jito_tip_distribution::ID,
);

let initialize_ncn_reward_router_ix = InitializeNcnRewardRouterBuilder::new()
.epoch_marker(epoch_marker)
.epoch_state(epoch_state)
.ncn(ncn)
.operator(operator)
Expand Down
8 changes: 6 additions & 2 deletions clients/js/jito_tip_router/accounts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type Config = {
feeConfig: FeeConfig;
bump: number;
epochsAfterConsensusBeforeClose: bigint;
startingValidEpoch: bigint;
reserved: Array<number>;
};

Expand All @@ -64,6 +65,7 @@ export type ConfigArgs = {
feeConfig: FeeConfigArgs;
bump: number;
epochsAfterConsensusBeforeClose: number | bigint;
startingValidEpoch: number | bigint;
reserved: Array<number>;
};

Expand All @@ -78,7 +80,8 @@ export function getConfigEncoder(): Encoder<ConfigArgs> {
['feeConfig', getFeeConfigEncoder()],
['bump', getU8Encoder()],
['epochsAfterConsensusBeforeClose', getU64Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 119 })],
['startingValidEpoch', getU64Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 111 })],
]);
}

Expand All @@ -93,7 +96,8 @@ export function getConfigDecoder(): Decoder<Config> {
['feeConfig', getFeeConfigDecoder()],
['bump', getU8Decoder()],
['epochsAfterConsensusBeforeClose', getU64Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 119 })],
['startingValidEpoch', getU64Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 111 })],
]);
}

Expand Down
121 changes: 121 additions & 0 deletions clients/js/jito_tip_router/accounts/epochMarker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
* 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 {
assertAccountExists,
assertAccountsExist,
combineCodec,
decodeAccount,
fetchEncodedAccount,
fetchEncodedAccounts,
getAddressDecoder,
getAddressEncoder,
getStructDecoder,
getStructEncoder,
getU64Decoder,
getU64Encoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type MaybeAccount,
type MaybeEncodedAccount,
} from '@solana/web3.js';

export type EpochMarker = {
discriminator: bigint;
ncn: Address;
epoch: bigint;
slotClosed: bigint;
};

export type EpochMarkerArgs = {
discriminator: number | bigint;
ncn: Address;
epoch: number | bigint;
slotClosed: number | bigint;
};

export function getEpochMarkerEncoder(): Encoder<EpochMarkerArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['epoch', getU64Encoder()],
['slotClosed', getU64Encoder()],
]);
}

export function getEpochMarkerDecoder(): Decoder<EpochMarker> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['epoch', getU64Decoder()],
['slotClosed', getU64Decoder()],
]);
}

export function getEpochMarkerCodec(): Codec<EpochMarkerArgs, EpochMarker> {
return combineCodec(getEpochMarkerEncoder(), getEpochMarkerDecoder());
}

export function decodeEpochMarker<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>
): Account<EpochMarker, TAddress>;
export function decodeEpochMarker<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>
): MaybeAccount<EpochMarker, TAddress>;
export function decodeEpochMarker<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
): Account<EpochMarker, TAddress> | MaybeAccount<EpochMarker, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getEpochMarkerDecoder()
);
}

export async function fetchEpochMarker<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<Account<EpochMarker, TAddress>> {
const maybeAccount = await fetchMaybeEpochMarker(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}

export async function fetchMaybeEpochMarker<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<MaybeAccount<EpochMarker, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeEpochMarker(maybeAccount);
}

export async function fetchAllEpochMarker(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<Account<EpochMarker>[]> {
const maybeAccounts = await fetchAllMaybeEpochMarker(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}

export async function fetchAllMaybeEpochMarker(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<EpochMarker>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeEpochMarker(maybeAccount));
}
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export * from './ballotBox';
export * from './baseRewardRouter';
export * from './config';
export * from './epochMarker';
export * from './epochSnapshot';
export * from './epochState';
export * from './ncnRewardRouter';
Expand Down
5 changes: 5 additions & 0 deletions clients/js/jito_tip_router/instructions/adminSetParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export type AdminSetParametersInstruction<

export type AdminSetParametersInstructionData = {
discriminator: number;
startingValidEpoch: Option<bigint>;
epochsBeforeStall: Option<bigint>;
epochsAfterConsensusBeforeClose: Option<bigint>;
validSlotsAfterConsensus: Option<bigint>;
};

export type AdminSetParametersInstructionDataArgs = {
startingValidEpoch: OptionOrNullable<number | bigint>;
epochsBeforeStall: OptionOrNullable<number | bigint>;
epochsAfterConsensusBeforeClose: OptionOrNullable<number | bigint>;
validSlotsAfterConsensus: OptionOrNullable<number | bigint>;
Expand All @@ -81,6 +83,7 @@ export function getAdminSetParametersInstructionDataEncoder(): Encoder<AdminSetP
return transformEncoder(
getStructEncoder([
['discriminator', getU8Encoder()],
['startingValidEpoch', getOptionEncoder(getU64Encoder())],
['epochsBeforeStall', getOptionEncoder(getU64Encoder())],
['epochsAfterConsensusBeforeClose', getOptionEncoder(getU64Encoder())],
['validSlotsAfterConsensus', getOptionEncoder(getU64Encoder())],
Expand All @@ -92,6 +95,7 @@ export function getAdminSetParametersInstructionDataEncoder(): Encoder<AdminSetP
export function getAdminSetParametersInstructionDataDecoder(): Decoder<AdminSetParametersInstructionData> {
return getStructDecoder([
['discriminator', getU8Decoder()],
['startingValidEpoch', getOptionDecoder(getU64Decoder())],
['epochsBeforeStall', getOptionDecoder(getU64Decoder())],
['epochsAfterConsensusBeforeClose', getOptionDecoder(getU64Decoder())],
['validSlotsAfterConsensus', getOptionDecoder(getU64Decoder())],
Expand All @@ -116,6 +120,7 @@ export type AdminSetParametersInput<
config: Address<TAccountConfig>;
ncn: Address<TAccountNcn>;
ncnAdmin: TransactionSigner<TAccountNcnAdmin>;
startingValidEpoch: AdminSetParametersInstructionDataArgs['startingValidEpoch'];
epochsBeforeStall: AdminSetParametersInstructionDataArgs['epochsBeforeStall'];
epochsAfterConsensusBeforeClose: AdminSetParametersInstructionDataArgs['epochsAfterConsensusBeforeClose'];
validSlotsAfterConsensus: AdminSetParametersInstructionDataArgs['validSlotsAfterConsensus'];
Expand Down
Loading

0 comments on commit b0908f5

Please sign in to comment.