diff --git a/clients/js/jito_tip_router/accounts/ncnConfig.ts b/clients/js/jito_tip_router/accounts/ncnConfig.ts index 2d385eb..6299e66 100644 --- a/clients/js/jito_tip_router/accounts/ncnConfig.ts +++ b/clients/js/jito_tip_router/accounts/ncnConfig.ts @@ -141,7 +141,3 @@ export async function fetchAllMaybeNcnConfig( const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeNcnConfig(maybeAccount)); } - -export function getNcnConfigSize(): number { - return 352; -} diff --git a/clients/rust/jito_tip_router/src/generated/accounts/ncn_config.rs b/clients/rust/jito_tip_router/src/generated/accounts/ncn_config.rs index 8897227..eaca31b 100644 --- a/clients/rust/jito_tip_router/src/generated/accounts/ncn_config.rs +++ b/clients/rust/jito_tip_router/src/generated/accounts/ncn_config.rs @@ -35,8 +35,6 @@ pub struct NcnConfig { } impl NcnConfig { - pub const LEN: usize = 352; - #[inline(always)] pub fn from_bytes(data: &[u8]) -> Result { let mut data = data; diff --git a/core/src/fees.rs b/core/src/fees.rs index 8d89e6f..c592597 100644 --- a/core/src/fees.rs +++ b/core/src/fees.rs @@ -1,4 +1,5 @@ use bytemuck::{Pod, Zeroable}; +use jito_bytemuck::types::PodU64; use shank::ShankType; use solana_program::{msg, pubkey::Pubkey}; use spl_math::precise_number::PreciseNumber; @@ -15,7 +16,7 @@ pub struct Fees { } impl Fees { - pub const fn new( + pub fn new( wallet: Pubkey, dao_fee_share_bps: u64, ncn_fee_share_bps: u64, @@ -35,17 +36,17 @@ impl Fees { } } - const fn current_fee(&self, current_epoch: u64) -> &Fee { + fn current_fee(&self, current_epoch: u64) -> &Fee { // If either fee is not yet active, return the other one - if self.fee_1.activation_epoch > current_epoch { + if self.fee_1.activation_epoch() > current_epoch { return &self.fee_2; } - if self.fee_2.activation_epoch > current_epoch { + if self.fee_2.activation_epoch() > current_epoch { return &self.fee_1; } // Otherwise return the one with higher activation epoch - if self.fee_1.activation_epoch >= self.fee_2.activation_epoch { + if self.fee_1.activation_epoch() >= self.fee_2.activation_epoch() { &self.fee_1 } else { &self.fee_2 @@ -60,8 +61,8 @@ impl Fees { Ok(()) } - pub const fn block_engine_fee(&self, current_epoch: u64) -> u64 { - self.current_fee(current_epoch).block_engine_fee_bps + pub fn block_engine_fee(&self, current_epoch: u64) -> u64 { + self.current_fee(current_epoch).block_engine_fee_bps() } pub fn precise_block_engine_fee( @@ -80,9 +81,9 @@ impl Fees { pub fn dao_fee(&self, current_epoch: u64) -> Result { let fee = self.current_fee(current_epoch); let remaining_bps = MAX_FEE_BPS - .checked_sub(fee.block_engine_fee_bps) + .checked_sub(fee.block_engine_fee_bps()) .ok_or(TipRouterError::ArithmeticOverflow)?; - fee.ncn_share_bps + fee.dao_share_bps() .checked_mul(MAX_FEE_BPS) .and_then(|x| x.checked_div(remaining_bps)) .ok_or(TipRouterError::DenominatorIsZero) @@ -118,9 +119,9 @@ impl Fees { let fee = self.current_fee(current_epoch); let remaining_bps = MAX_FEE_BPS - .checked_sub(fee.block_engine_fee_bps) + .checked_sub(fee.block_engine_fee_bps()) .ok_or(TipRouterError::ArithmeticOverflow)?; - fee.ncn_share_bps + fee.ncn_share_bps() .checked_mul(MAX_FEE_BPS) .and_then(|x| x.checked_div(remaining_bps)) .ok_or(TipRouterError::DenominatorIsZero) @@ -149,21 +150,21 @@ impl Fees { .ok_or(TipRouterError::DenominatorIsZero) } - pub const fn fee_wallet(&self, current_epoch: u64) -> Pubkey { + pub fn fee_wallet(&self, current_epoch: u64) -> Pubkey { self.current_fee(current_epoch).wallet } fn get_updatable_fee_mut(&mut self, current_epoch: u64) -> &mut Fee { // If either fee is scheduled for next epoch, return that one - if self.fee_1.activation_epoch > current_epoch { + if self.fee_1.activation_epoch() > current_epoch { return &mut self.fee_1; } - if self.fee_2.activation_epoch > current_epoch { + if self.fee_2.activation_epoch() > current_epoch { return &mut self.fee_2; } // Otherwise return the one with lower activation epoch - if self.fee_1.activation_epoch <= self.fee_2.activation_epoch { + if self.fee_1.activation_epoch() <= self.fee_2.activation_epoch() { &mut self.fee_1 } else { &mut self.fee_2 @@ -186,13 +187,13 @@ impl Fees { if new_dao_fee_bps > MAX_FEE_BPS { return Err(TipRouterError::FeeCapExceeded); } - new_fees.ncn_share_bps = new_dao_fee_bps; + new_fees.set_dao_share_bps(new_dao_fee_bps); } if let Some(new_ncn_fee_bps) = new_ncn_fee_bps { if new_ncn_fee_bps > MAX_FEE_BPS { return Err(TipRouterError::FeeCapExceeded); } - new_fees.ncn_share_bps = new_ncn_fee_bps; + new_fees.set_ncn_share_bps(new_ncn_fee_bps); } if let Some(new_block_engine_fee_bps) = new_block_engine_fee_bps { // Block engine fee must be less than MAX_FEE_BPS, @@ -202,7 +203,7 @@ impl Fees { msg!("Block engine fee cannot equal or exceed MAX_FEE_BPS"); return Err(TipRouterError::FeeCapExceeded); } - new_fees.block_engine_fee_bps = new_block_engine_fee_bps; + new_fees.set_block_engine_fee_bps(new_block_engine_fee_bps); } if let Some(new_wallet) = new_wallet { new_fees.wallet = new_wallet; @@ -212,7 +213,7 @@ impl Fees { .checked_add(1) .ok_or(TipRouterError::ArithmeticOverflow)?; - new_fees.activation_epoch = next_epoch; + new_fees.set_activation_epoch(next_epoch); self.check_fees_okay(next_epoch)?; @@ -224,14 +225,14 @@ impl Fees { #[repr(C)] pub struct Fee { wallet: Pubkey, - dao_share_bps: u64, - ncn_share_bps: u64, - block_engine_fee_bps: u64, - activation_epoch: u64, + dao_share_bps: PodU64, + ncn_share_bps: PodU64, + block_engine_fee_bps: PodU64, + activation_epoch: PodU64, } impl Fee { - pub const fn new( + pub fn new( wallet: Pubkey, dao_share_bps: u64, ncn_share_bps: u64, @@ -240,12 +241,44 @@ impl Fee { ) -> Self { Self { wallet, - ncn_share_bps, - dao_share_bps, - block_engine_fee_bps, - activation_epoch: epoch, + dao_share_bps: PodU64::from(dao_share_bps), + ncn_share_bps: PodU64::from(ncn_share_bps), + block_engine_fee_bps: PodU64::from(block_engine_fee_bps), + activation_epoch: PodU64::from(epoch), } } + + pub fn dao_share_bps(&self) -> u64 { + self.dao_share_bps.into() + } + + pub fn ncn_share_bps(&self) -> u64 { + self.ncn_share_bps.into() + } + + pub fn block_engine_fee_bps(&self) -> u64 { + self.block_engine_fee_bps.into() + } + + pub fn activation_epoch(&self) -> u64 { + self.activation_epoch.into() + } + + fn set_dao_share_bps(&mut self, value: u64) { + self.dao_share_bps = PodU64::from(value); + } + + fn set_ncn_share_bps(&mut self, value: u64) { + self.ncn_share_bps = PodU64::from(value); + } + + fn set_block_engine_fee_bps(&mut self, value: u64) { + self.block_engine_fee_bps = PodU64::from(value); + } + + fn set_activation_epoch(&mut self, value: u64) { + self.activation_epoch = PodU64::from(value); + } } #[cfg(test)] @@ -261,26 +294,26 @@ mod tests { fees.set_new_fees(Some(400), None, None, Some(new_wallet), 10) .unwrap(); - assert_eq!(fees.fee_1.ncn_share_bps, 400); + assert_eq!(fees.fee_1.dao_share_bps(), 400); assert_eq!(fees.fee_1.wallet, new_wallet); - assert_eq!(fees.fee_1.activation_epoch, 11); + assert_eq!(fees.fee_1.activation_epoch(), 11); } #[test] fn test_update_fees_no_changes() { let original = Fee::new(Pubkey::new_unique(), 100, 200, 300, 5); let mut fees = Fees::new(Pubkey::new_unique(), 100, 200, 300, 5); - fees.fee_1 = original.clone(); + fees.fee_1 = original; fees.set_new_fees(None, None, None, None, 10).unwrap(); - assert_eq!(fees.fee_1.ncn_share_bps, original.ncn_share_bps); - assert_eq!(fees.fee_1.ncn_share_bps, original.ncn_share_bps); + assert_eq!(fees.fee_1.dao_share_bps(), original.dao_share_bps()); + assert_eq!(fees.fee_1.ncn_share_bps(), original.ncn_share_bps()); assert_eq!( - fees.fee_1.block_engine_fee_bps, - original.block_engine_fee_bps + fees.fee_1.block_engine_fee_bps(), + original.block_engine_fee_bps() ); assert_eq!(fees.fee_1.wallet, original.wallet); - assert_eq!(fees.fee_1.activation_epoch, 11); + assert_eq!(fees.fee_1.activation_epoch(), 11); } #[test] @@ -325,17 +358,17 @@ mod tests { fn test_current_fee() { let mut fees = Fees::new(Pubkey::new_unique(), 100, 200, 300, 5); - assert_eq!(fees.current_fee(5).activation_epoch, 5); + assert_eq!(fees.current_fee(5).activation_epoch(), 5); - fees.fee_1.activation_epoch = 10; + fees.fee_1.set_activation_epoch(10); - assert_eq!(fees.current_fee(5).activation_epoch, 5); - assert_eq!(fees.current_fee(10).activation_epoch, 10); + assert_eq!(fees.current_fee(5).activation_epoch(), 5); + assert_eq!(fees.current_fee(10).activation_epoch(), 10); - fees.fee_2.activation_epoch = 15; + fees.fee_2.set_activation_epoch(15); - assert_eq!(fees.current_fee(12).activation_epoch, 10); - assert_eq!(fees.current_fee(15).activation_epoch, 15); + assert_eq!(fees.current_fee(12).activation_epoch(), 10); + assert_eq!(fees.current_fee(15).activation_epoch(), 15); } #[test] @@ -343,21 +376,21 @@ mod tests { let mut fees = Fees::new(Pubkey::new_unique(), 100, 200, 300, 5); let fee = fees.get_updatable_fee_mut(10); - fee.ncn_share_bps = 400; - fee.activation_epoch = 11; + fee.set_dao_share_bps(400); + fee.set_activation_epoch(11); - assert_eq!(fees.fee_1.ncn_share_bps, 400); - assert_eq!(fees.fee_1.activation_epoch, 11); + assert_eq!(fees.fee_1.dao_share_bps(), 400); + assert_eq!(fees.fee_1.activation_epoch(), 11); - fees.fee_2.activation_epoch = 13; + fees.fee_2.set_activation_epoch(13); let fee = fees.get_updatable_fee_mut(12); - fee.ncn_share_bps = 500; - fee.activation_epoch = 13; + fee.set_dao_share_bps(500); + fee.set_activation_epoch(13); - assert_eq!(fees.fee_2.ncn_share_bps, 500); - assert_eq!(fees.fee_2.activation_epoch, 13); + assert_eq!(fees.fee_2.dao_share_bps(), 500); + assert_eq!(fees.fee_2.activation_epoch(), 13); - assert_eq!(fees.get_updatable_fee_mut(u64::MAX).activation_epoch, 11); + assert_eq!(fees.get_updatable_fee_mut(u64::MAX).activation_epoch(), 11); } } diff --git a/idl/jito_tip_router.json b/idl/jito_tip_router.json index 54c8f19..3fd2c53 100644 --- a/idl/jito_tip_router.json +++ b/idl/jito_tip_router.json @@ -385,19 +385,27 @@ }, { "name": "daoShareBps", - "type": "u64" + "type": { + "defined": "PodU64" + } }, { "name": "ncnShareBps", - "type": "u64" + "type": { + "defined": "PodU64" + } }, { "name": "blockEngineFeeBps", - "type": "u64" + "type": { + "defined": "PodU64" + } }, { "name": "activationEpoch", - "type": "u64" + "type": { + "defined": "PodU64" + } } ] }