From fff19a032a4f4b1c2f35ce4ff5910f51055eea3a Mon Sep 17 00:00:00 2001 From: Christian Krueger Date: Tue, 26 Nov 2024 13:45:32 -0600 Subject: [PATCH] made linter happy --- clients/js/jito_tip_router/types/index.ts | 2 + .../js/jito_tip_router/types/rewardBucket.ts | 48 +++++++++++ .../js/jito_tip_router/types/rewardRoutes.ts | 57 +++++++++++++ .../src/generated/types/mod.rs | 8 +- .../src/generated/types/reward_bucket.rs | 15 ++++ .../src/generated/types/reward_routes.rs | 21 +++++ core/src/ballot_box.rs | 6 +- core/src/epoch_reward_router.rs | 10 ++- core/src/epoch_snapshot.rs | 10 +-- core/src/operator_reward_router.rs | 85 ++----------------- core/src/stake_weight.rs | 2 +- core/src/tracked_mints.rs | 2 +- idl/jito_tip_router.json | 50 ----------- 13 files changed, 174 insertions(+), 142 deletions(-) create mode 100644 clients/js/jito_tip_router/types/rewardBucket.ts create mode 100644 clients/js/jito_tip_router/types/rewardRoutes.ts create mode 100644 clients/rust/jito_tip_router/src/generated/types/reward_bucket.rs create mode 100644 clients/rust/jito_tip_router/src/generated/types/reward_routes.rs diff --git a/clients/js/jito_tip_router/types/index.ts b/clients/js/jito_tip_router/types/index.ts index aff498b..e26498c 100644 --- a/clients/js/jito_tip_router/types/index.ts +++ b/clients/js/jito_tip_router/types/index.ts @@ -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'; diff --git a/clients/js/jito_tip_router/types/rewardBucket.ts b/clients/js/jito_tip_router/types/rewardBucket.ts new file mode 100644 index 0000000..9c7a1d4 --- /dev/null +++ b/clients/js/jito_tip_router/types/rewardBucket.ts @@ -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 { + return getStructEncoder([ + ['rewards', getU64Encoder()], + ['reserved', fixEncoderSize(getBytesEncoder(), 64)], + ]); +} + +export function getRewardBucketDecoder(): Decoder { + return getStructDecoder([ + ['rewards', getU64Decoder()], + ['reserved', fixDecoderSize(getBytesDecoder(), 64)], + ]); +} + +export function getRewardBucketCodec(): Codec { + return combineCodec(getRewardBucketEncoder(), getRewardBucketDecoder()); +} diff --git a/clients/js/jito_tip_router/types/rewardRoutes.ts b/clients/js/jito_tip_router/types/rewardRoutes.ts new file mode 100644 index 0000000..7dab2fe --- /dev/null +++ b/clients/js/jito_tip_router/types/rewardRoutes.ts @@ -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; +}; + +export type RewardRoutesArgs = { + destination: Address; + rewards: number | bigint; + reserved: Array; +}; + +export function getRewardRoutesEncoder(): Encoder { + return getStructEncoder([ + ['destination', getAddressEncoder()], + ['rewards', getU64Encoder()], + ['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })], + ]); +} + +export function getRewardRoutesDecoder(): Decoder { + return getStructDecoder([ + ['destination', getAddressDecoder()], + ['rewards', getU64Decoder()], + ['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })], + ]); +} + +export function getRewardRoutesCodec(): Codec { + return combineCodec(getRewardRoutesEncoder(), getRewardRoutesDecoder()); +} diff --git a/clients/rust/jito_tip_router/src/generated/types/mod.rs b/clients/rust/jito_tip_router/src/generated/types/mod.rs index 0a6d1a3..024fedd 100644 --- a/clients/rust/jito_tip_router/src/generated/types/mod.rs +++ b/clients/rust/jito_tip_router/src/generated/types/mod.rs @@ -13,6 +13,8 @@ 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; @@ -20,7 +22,7 @@ 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::*, }; diff --git a/clients/rust/jito_tip_router/src/generated/types/reward_bucket.rs b/clients/rust/jito_tip_router/src/generated/types/reward_bucket.rs new file mode 100644 index 0000000..448dd79 --- /dev/null +++ b/clients/rust/jito_tip_router/src/generated/types/reward_bucket.rs @@ -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. +//! +//! + +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::"))] + pub reserved: [u8; 64], +} diff --git a/clients/rust/jito_tip_router/src/generated/types/reward_routes.rs b/clients/rust/jito_tip_router/src/generated/types/reward_routes.rs new file mode 100644 index 0000000..6e3faf5 --- /dev/null +++ b/clients/rust/jito_tip_router/src/generated/types/reward_routes.rs @@ -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. +//! +//! + +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::") + )] + pub destination: Pubkey, + pub rewards: u64, + #[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] + pub reserved: [u8; 128], +} diff --git a/core/src/ballot_box.rs b/core/src/ballot_box.rs index 7abe8e1..6534068 100644 --- a/core/src/ballot_box.rs +++ b/core/src/ballot_box.rs @@ -78,7 +78,7 @@ impl BallotTally { self.ballot } - pub fn stake_weight(&self) -> &StakeWeight { + pub const fn stake_weight(&self) -> &StakeWeight { &self.stake_weight } @@ -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 } @@ -292,7 +292,7 @@ impl BallotBox { } } - pub fn operator_votes(&self) -> &[OperatorVote; 32] { + pub const fn operator_votes(&self) -> &[OperatorVote; 32] { &self.operator_votes } diff --git a/core/src/epoch_reward_router.rs b/core/src/epoch_reward_router.rs index 60ed1b0..965bdbf 100644 --- a/core/src/epoch_reward_router.rs +++ b/core/src/epoch_reward_router.rs @@ -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() } @@ -351,7 +355,7 @@ impl EpochRewardRouter { } } - Err(TipRouterError::OperatorRewardListFull.into()) + Err(TipRouterError::OperatorRewardListFull) } pub fn decrement_operator_rewards( @@ -370,7 +374,7 @@ impl EpochRewardRouter { } } - Err(TipRouterError::OperatorRewardNotFound.into()) + Err(TipRouterError::OperatorRewardNotFound) } pub fn reward_pool(&self) -> u64 { @@ -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 } diff --git a/core/src/epoch_snapshot.rs b/core/src/epoch_snapshot.rs index 66701ce..9b586a6 100644 --- a/core/src/epoch_snapshot.rs +++ b/core/src/epoch_snapshot.rs @@ -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 } } @@ -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 } @@ -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 } diff --git a/core/src/operator_reward_router.rs b/core/src/operator_reward_router.rs index c0301cd..c80f260 100644 --- a/core/src/operator_reward_router.rs +++ b/core/src/operator_reward_router.rs @@ -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)] @@ -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( @@ -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 { diff --git a/core/src/stake_weight.rs b/core/src/stake_weight.rs index 3dc7034..d425b31 100644 --- a/core/src/stake_weight.rs +++ b/core/src/stake_weight.rs @@ -34,7 +34,7 @@ impl StakeWeight { Ok(self.reward_stake_weights[group_index].reward_stake_weight()) } - pub fn increment(&mut self, stake_weight: &StakeWeight) -> Result<(), TipRouterError> { + pub fn increment(&mut self, stake_weight: &Self) -> Result<(), TipRouterError> { self.increment_stake_weight(stake_weight.stake_weight())?; for group in NcnFeeGroup::all_groups().iter() { diff --git a/core/src/tracked_mints.rs b/core/src/tracked_mints.rs index beb19fe..cff3b03 100644 --- a/core/src/tracked_mints.rs +++ b/core/src/tracked_mints.rs @@ -30,7 +30,7 @@ impl MintEntry { self.vault_index.into() } - pub fn ncn_fee_group(&self) -> NcnFeeGroup { + pub const fn ncn_fee_group(&self) -> NcnFeeGroup { self.ncn_fee_group } } diff --git a/idl/jito_tip_router.json b/idl/jito_tip_router.json index 2452079..399c9f5 100644 --- a/idl/jito_tip_router.json +++ b/idl/jito_tip_router.json @@ -1414,56 +1414,6 @@ ] } }, - { - "name": "RewardRoutes", - "type": { - "kind": "struct", - "fields": [ - { - "name": "destination", - "type": "publicKey" - }, - { - "name": "rewards", - "type": { - "defined": "PodU64" - } - }, - { - "name": "reserved", - "type": { - "array": [ - "u8", - 128 - ] - } - } - ] - } - }, - { - "name": "RewardBucket", - "type": { - "kind": "struct", - "fields": [ - { - "name": "rewards", - "type": { - "defined": "PodU64" - } - }, - { - "name": "reserved", - "type": { - "array": [ - "u8", - 64 - ] - } - } - ] - } - }, { "name": "StakeWeight", "type": {