Skip to content

Commit

Permalink
made linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 26, 2024
1 parent 5416db3 commit fff19a0
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 142 deletions.
2 changes: 2 additions & 0 deletions clients/js/jito_tip_router/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export * from './mintEntry';
export * from './ncnFee';
export * from './ncnFeeGroup';
export * from './operatorVote';
export * from './rewardBucket';
export * from './rewardRoutes';
export * from './rewardStakeWeight';
export * from './stakeWeight';
export * from './vaultOperatorStakeWeight';
Expand Down
48 changes: 48 additions & 0 deletions clients/js/jito_tip_router/types/rewardBucket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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,
fixDecoderSize,
fixEncoderSize,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
getStructEncoder,
getU64Decoder,
getU64Encoder,
type Codec,
type Decoder,
type Encoder,
type ReadonlyUint8Array,
} from '@solana/web3.js';

export type RewardBucket = { rewards: bigint; reserved: ReadonlyUint8Array };

export type RewardBucketArgs = {
rewards: number | bigint;
reserved: ReadonlyUint8Array;
};

export function getRewardBucketEncoder(): Encoder<RewardBucketArgs> {
return getStructEncoder([
['rewards', getU64Encoder()],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
}

export function getRewardBucketDecoder(): Decoder<RewardBucket> {
return getStructDecoder([
['rewards', getU64Decoder()],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
}

export function getRewardBucketCodec(): Codec<RewardBucketArgs, RewardBucket> {
return combineCodec(getRewardBucketEncoder(), getRewardBucketDecoder());
}
57 changes: 57 additions & 0 deletions clients/js/jito_tip_router/types/rewardRoutes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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,
getAddressDecoder,
getAddressEncoder,
getArrayDecoder,
getArrayEncoder,
getStructDecoder,
getStructEncoder,
getU64Decoder,
getU64Encoder,
getU8Decoder,
getU8Encoder,
type Address,
type Codec,
type Decoder,
type Encoder,
} from '@solana/web3.js';

export type RewardRoutes = {
destination: Address;
rewards: bigint;
reserved: Array<number>;
};

export type RewardRoutesArgs = {
destination: Address;
rewards: number | bigint;
reserved: Array<number>;
};

export function getRewardRoutesEncoder(): Encoder<RewardRoutesArgs> {
return getStructEncoder([
['destination', getAddressEncoder()],
['rewards', getU64Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
]);
}

export function getRewardRoutesDecoder(): Decoder<RewardRoutes> {
return getStructDecoder([
['destination', getAddressDecoder()],
['rewards', getU64Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
]);
}

export function getRewardRoutesCodec(): Codec<RewardRoutesArgs, RewardRoutes> {
return combineCodec(getRewardRoutesEncoder(), getRewardRoutesDecoder());
}
8 changes: 5 additions & 3 deletions clients/rust/jito_tip_router/src/generated/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ pub(crate) mod r#mint_entry;
pub(crate) mod r#ncn_fee;
pub(crate) mod r#ncn_fee_group;
pub(crate) mod r#operator_vote;
pub(crate) mod r#reward_bucket;
pub(crate) mod r#reward_routes;
pub(crate) mod r#reward_stake_weight;
pub(crate) mod r#stake_weight;
pub(crate) mod r#vault_operator_stake_weight;
pub(crate) mod r#weight_entry;

pub use self::{
r#ballot::*, r#ballot_tally::*, r#config_admin_role::*, r#fee_config::*, r#fees::*,
r#mint_entry::*, r#ncn_fee::*, r#ncn_fee_group::*, r#operator_vote::*,
r#reward_stake_weight::*, r#stake_weight::*, r#vault_operator_stake_weight::*,
r#weight_entry::*,
r#mint_entry::*, r#ncn_fee::*, r#ncn_fee_group::*, r#operator_vote::*, r#reward_bucket::*,
r#reward_routes::*, r#reward_stake_weight::*, r#stake_weight::*,
r#vault_operator_stake_weight::*, r#weight_entry::*,
};
15 changes: 15 additions & 0 deletions clients/rust/jito_tip_router/src/generated/types/reward_bucket.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! 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.
//!
//! <https://github.com/kinobi-so/kinobi>
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RewardBucket {
pub rewards: u64,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 64],
}
21 changes: 21 additions & 0 deletions clients/rust/jito_tip_router/src/generated/types/reward_routes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! 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.
//!
//! <https://github.com/kinobi-so/kinobi>
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RewardRoutes {
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub destination: Pubkey,
pub rewards: u64,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 128],
}
6 changes: 3 additions & 3 deletions core/src/ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl BallotTally {
self.ballot
}

pub fn stake_weight(&self) -> &StakeWeight {
pub const fn stake_weight(&self) -> &StakeWeight {
&self.stake_weight
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl OperatorVote {
self.slot_voted.into()
}

pub fn stake_weight(&self) -> &StakeWeight {
pub const fn stake_weight(&self) -> &StakeWeight {
&self.stake_weight
}

Expand Down Expand Up @@ -292,7 +292,7 @@ impl BallotBox {
}
}

pub fn operator_votes(&self) -> &[OperatorVote; 32] {
pub const fn operator_votes(&self) -> &[OperatorVote; 32] {
&self.operator_votes
}

Expand Down
10 changes: 7 additions & 3 deletions core/src/epoch_reward_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl RewardRoutes {
self.destination
}

pub fn set_destination(&mut self, destination: Pubkey) {
self.destination = destination;
}

pub fn rewards(&self) -> u64 {
self.rewards.into()
}
Expand Down Expand Up @@ -351,7 +355,7 @@ impl EpochRewardRouter {
}
}

Err(TipRouterError::OperatorRewardListFull.into())
Err(TipRouterError::OperatorRewardListFull)
}

pub fn decrement_operator_rewards(
Expand All @@ -370,7 +374,7 @@ impl EpochRewardRouter {
}
}

Err(TipRouterError::OperatorRewardNotFound.into())
Err(TipRouterError::OperatorRewardNotFound)
}

pub fn reward_pool(&self) -> u64 {
Expand Down Expand Up @@ -433,7 +437,7 @@ impl EpochRewardRouter {
Ok(())
}

pub fn ncn_reward_buckets(&self) -> &[RewardBucket; 16] {
pub const fn ncn_reward_buckets(&self) -> &[RewardBucket; 16] {
&self.ncn_reward_buckets
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/epoch_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ impl VaultOperatorStakeWeight {
self.vault_index.into()
}

pub fn stake_weight(&self) -> &StakeWeight {
pub const fn stake_weight(&self) -> &StakeWeight {
&self.stake_weight
}

pub fn vault(&self) -> Pubkey {
pub const fn vault(&self) -> Pubkey {
self.vault
}

pub fn ncn_fee_group(&self) -> NcnFeeGroup {
pub const fn ncn_fee_group(&self) -> NcnFeeGroup {
self.ncn_fee_group
}
}
Expand Down Expand Up @@ -445,7 +445,7 @@ impl OperatorSnapshot {
self.valid_operator_vault_delegations.into()
}

pub fn stake_weight(&self) -> &StakeWeight {
pub const fn stake_weight(&self) -> &StakeWeight {
&self.stake_weight
}

Expand All @@ -459,7 +459,7 @@ impl OperatorSnapshot {
.any(|v| v.vault_index() == vault_index)
}

pub fn vault_operator_stake_weight(&self) -> &[VaultOperatorStakeWeight] {
pub const fn vault_operator_stake_weight(&self) -> &[VaultOperatorStakeWeight] {
&self.vault_operator_stake_weight
}

Expand Down
85 changes: 9 additions & 76 deletions core/src/operator_reward_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,10 @@ use solana_program::{account_info::AccountInfo, msg, program_error::ProgramError
use spl_math::precise_number::PreciseNumber;

use crate::{
discriminators::Discriminators, epoch_snapshot::OperatorSnapshot, error::TipRouterError,
discriminators::Discriminators, epoch_reward_router::RewardRoutes,
epoch_snapshot::OperatorSnapshot, error::TipRouterError,
};

#[derive(Debug, Clone, PartialEq, Eq, Copy, Zeroable, ShankType, Pod, ShankType)]
#[repr(C)]
pub struct RewardRoutes {
destination: Pubkey,
rewards: PodU64,
reserved: [u8; 128],
}

impl Default for RewardRoutes {
fn default() -> Self {
Self {
destination: Pubkey::default(),
rewards: PodU64::from(0),
reserved: [0; 128],
}
}
}

impl RewardRoutes {
pub const fn destination(&self) -> Pubkey {
self.destination
}

pub fn rewards(&self) -> u64 {
self.rewards.into()
}

pub fn increment_rewards(&mut self, rewards: u64) -> Result<(), TipRouterError> {
self.rewards = PodU64::from(
self.rewards()
.checked_add(rewards)
.ok_or(TipRouterError::ArithmeticOverflow)?,
);
Ok(())
}

pub fn decrement_rewards(&mut self, rewards: u64) -> Result<(), TipRouterError> {
self.rewards = PodU64::from(
self.rewards()
.checked_sub(rewards)
.ok_or(TipRouterError::ArithmeticUnderflowError)?,
);
Ok(())
}
}

#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod)]
#[repr(C)]
pub struct RewardBucket {
rewards: PodU64,
reserved: [u8; 64],
}

impl Default for RewardBucket {
fn default() -> Self {
Self {
rewards: PodU64::from(0),
reserved: [0; 64],
}
}
}

impl RewardBucket {
pub fn rewards(&self) -> u64 {
self.rewards.into()
}
}

// PDA'd ["epoch_reward_router", NCN, NCN_EPOCH_SLOT]
#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod, AccountDeserialize, ShankAccount)]
#[repr(C)]
Expand Down Expand Up @@ -318,21 +251,21 @@ impl OperatorEpochRewardRouter {
}

for vault_reward in self.vault_rewards.iter_mut() {
if vault_reward.destination == vault {
if vault_reward.destination() == vault {
vault_reward.increment_rewards(rewards)?;
return Ok(());
}
}

for vault_reward in self.vault_rewards.iter_mut() {
if vault_reward.destination == Pubkey::default() {
vault_reward.destination = vault;
vault_reward.rewards = PodU64::from(rewards);
if vault_reward.destination() == Pubkey::default() {
vault_reward.set_destination(vault);
vault_reward.increment_rewards(rewards)?;
return Ok(());
}
}

Err(TipRouterError::OperatorRewardListFull.into())
Err(TipRouterError::OperatorRewardListFull)
}

pub fn decrement_vault_rewards(
Expand All @@ -345,13 +278,13 @@ impl OperatorEpochRewardRouter {
}

for operator_reward in self.vault_rewards.iter_mut() {
if operator_reward.destination == vault {
if operator_reward.destination() == vault {
operator_reward.decrement_rewards(rewards)?;
return Ok(());
}
}

Err(TipRouterError::OperatorRewardNotFound.into())
Err(TipRouterError::OperatorRewardNotFound)
}

pub fn reward_pool(&self) -> u64 {
Expand Down
Loading

0 comments on commit fff19a0

Please sign in to comment.