Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 26, 2024
1 parent fff19a0 commit 2dd2132
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 116 deletions.
4 changes: 2 additions & 2 deletions clients/js/jito_tip_router/accounts/epochRewardRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getEpochRewardRouterEncoder(): Encoder<EpochRewardRouterArgs> {
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
[
'ncnRewardBuckets',
getArrayEncoder(getRewardBucketEncoder(), { size: 16 }),
getArrayEncoder(getRewardBucketEncoder(), { size: 8 }),
],
['rewardRoutes', getArrayEncoder(getRewardRoutesEncoder(), { size: 32 })],
]);
Expand All @@ -101,7 +101,7 @@ export function getEpochRewardRouterDecoder(): Decoder<EpochRewardRouter> {
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
[
'ncnRewardBuckets',
getArrayDecoder(getRewardBucketDecoder(), { size: 16 }),
getArrayDecoder(getRewardBucketDecoder(), { size: 8 }),
],
['rewardRoutes', getArrayDecoder(getRewardRoutesDecoder(), { size: 32 })],
]);
Expand Down
4 changes: 2 additions & 2 deletions clients/js/jito_tip_router/types/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getFeesEncoder(): Encoder<FeesArgs> {
['blockEngineFeeBps', getU64Encoder()],
['daoFeeBps', getU64Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
['ncnFeeGroupsBps', getArrayEncoder(getNcnFeeEncoder(), { size: 16 })],
['ncnFeeGroupsBps', getArrayEncoder(getNcnFeeEncoder(), { size: 8 })],
]);
}

Expand All @@ -59,7 +59,7 @@ export function getFeesDecoder(): Decoder<Fees> {
['blockEngineFeeBps', getU64Decoder()],
['daoFeeBps', getU64Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
['ncnFeeGroupsBps', getArrayDecoder(getNcnFeeDecoder(), { size: 16 })],
['ncnFeeGroupsBps', getArrayDecoder(getNcnFeeDecoder(), { size: 8 })],
]);
}

Expand Down
25 changes: 4 additions & 21 deletions clients/js/jito_tip_router/types/rewardStakeWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,25 @@

import {
combineCodec,
fixDecoderSize,
fixEncoderSize,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
getStructEncoder,
getU128Decoder,
getU128Encoder,
type Codec,
type Decoder,
type Encoder,
type ReadonlyUint8Array,
} from '@solana/web3.js';

export type RewardStakeWeight = {
rewardStakeWeight: bigint;
reserved: ReadonlyUint8Array;
};
export type RewardStakeWeight = { rewardStakeWeight: bigint };

export type RewardStakeWeightArgs = {
rewardStakeWeight: number | bigint;
reserved: ReadonlyUint8Array;
};
export type RewardStakeWeightArgs = { rewardStakeWeight: number | bigint };

export function getRewardStakeWeightEncoder(): Encoder<RewardStakeWeightArgs> {
return getStructEncoder([
['rewardStakeWeight', getU128Encoder()],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
return getStructEncoder([['rewardStakeWeight', getU128Encoder()]]);
}

export function getRewardStakeWeightDecoder(): Decoder<RewardStakeWeight> {
return getStructDecoder([
['rewardStakeWeight', getU128Decoder()],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
return getStructDecoder([['rewardStakeWeight', getU128Decoder()]]);
}

export function getRewardStakeWeightCodec(): Codec<
Expand Down
13 changes: 2 additions & 11 deletions clients/js/jito_tip_router/types/stakeWeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@

import {
combineCodec,
fixDecoderSize,
fixEncoderSize,
getArrayDecoder,
getArrayEncoder,
getBytesDecoder,
getBytesEncoder,
getStructDecoder,
getStructEncoder,
getU128Decoder,
getU128Encoder,
type Codec,
type Decoder,
type Encoder,
type ReadonlyUint8Array,
} from '@solana/web3.js';
import {
getRewardStakeWeightDecoder,
Expand All @@ -33,23 +28,20 @@ import {
export type StakeWeight = {
stakeWeight: bigint;
rewardStakeWeights: Array<RewardStakeWeight>;
reserved: ReadonlyUint8Array;
};

export type StakeWeightArgs = {
stakeWeight: number | bigint;
rewardStakeWeights: Array<RewardStakeWeightArgs>;
reserved: ReadonlyUint8Array;
};

export function getStakeWeightEncoder(): Encoder<StakeWeightArgs> {
return getStructEncoder([
['stakeWeight', getU128Encoder()],
[
'rewardStakeWeights',
getArrayEncoder(getRewardStakeWeightEncoder(), { size: 16 }),
getArrayEncoder(getRewardStakeWeightEncoder(), { size: 8 }),
],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
}

Expand All @@ -58,9 +50,8 @@ export function getStakeWeightDecoder(): Decoder<StakeWeight> {
['stakeWeight', getU128Decoder()],
[
'rewardStakeWeights',
getArrayDecoder(getRewardStakeWeightDecoder(), { size: 16 }),
getArrayDecoder(getRewardStakeWeightDecoder(), { size: 8 }),
],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct EpochRewardRouter {
pub doa_rewards: u64,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 128],
pub ncn_reward_buckets: [RewardBucket; 16],
pub ncn_reward_buckets: [RewardBucket; 8],
pub reward_routes: [RewardRoutes; 32],
}

Expand Down
2 changes: 1 addition & 1 deletion clients/rust/jito_tip_router/src/generated/types/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub struct Fees {
pub dao_fee_bps: u64,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 128],
pub ncn_fee_groups_bps: [NcnFee; 16],
pub ncn_fee_groups_bps: [NcnFee; 8],
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ use borsh::{BorshDeserialize, BorshSerialize};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RewardStakeWeight {
pub reward_stake_weight: u128,
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 64],
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ use crate::generated::types::RewardStakeWeight;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StakeWeight {
pub stake_weight: u128,
pub reward_stake_weights: [RewardStakeWeight; 16],
#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
pub reserved: [u8; 64],
pub reward_stake_weights: [RewardStakeWeight; 8],
}
4 changes: 2 additions & 2 deletions core/src/epoch_reward_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct EpochRewardRouter {

reserved: [u8; 128],

ncn_reward_buckets: [RewardBucket; 16],
ncn_reward_buckets: [RewardBucket; 8],

//TODO change to 256
reward_routes: [RewardRoutes; 32],
Expand Down Expand Up @@ -437,7 +437,7 @@ impl EpochRewardRouter {
Ok(())
}

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

Expand Down
6 changes: 3 additions & 3 deletions core/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub struct Fees {
block_engine_fee_bps: PodU64,
dao_fee_bps: PodU64,
reserved: [u8; 128],
ncn_fee_groups_bps: [NcnFee; 16],
ncn_fee_groups_bps: [NcnFee; 8],
}

impl Fees {
Expand Down Expand Up @@ -474,7 +474,7 @@ mod tests {
.fee_1
.ncn_fee_bps(NcnFeeGroup::default())
.unwrap(),
0
DEFAULT_NCN_FEE
);

assert_eq!(fee_config.fee_2.activation_epoch(), STARTING_EPOCH);
Expand All @@ -485,7 +485,7 @@ mod tests {
.fee_2
.ncn_fee_bps(NcnFeeGroup::default())
.unwrap(),
0
DEFAULT_NCN_FEE
);

let new_fees = Fees::new(500, 600, 700, 10).unwrap();
Expand Down
82 changes: 41 additions & 41 deletions core/src/ncn_fee_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ pub enum NcnFeeGroupType {
Reserved5 = 0x5,
Reserved6 = 0x6,
Reserved7 = 0x7,
Reserved8 = 0x8,
Reserved9 = 0x9,
ReservedA = 0xA,
ReservedB = 0xB,
ReservedC = 0xC,
ReservedD = 0xD,
ReservedE = 0xE,
ReservedF = 0xF,
// Reserved8 = 0x8,
// Reserved9 = 0x9,
// ReservedA = 0xA,
// ReservedB = 0xB,
// ReservedC = 0xC,
// ReservedD = 0xD,
// ReservedE = 0xE,
// ReservedF = 0xF,
}

#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod)]
Expand All @@ -39,7 +39,7 @@ impl Default for NcnFeeGroup {
}

impl NcnFeeGroup {
pub const FEE_GROUP_COUNT: usize = 16;
pub const FEE_GROUP_COUNT: usize = 8;

pub const fn new(group: NcnFeeGroupType) -> Self {
// So compiler will yell at us if we miss a group
Expand All @@ -52,14 +52,14 @@ impl NcnFeeGroup {
NcnFeeGroupType::Reserved5 => Self { group: group as u8 },
NcnFeeGroupType::Reserved6 => Self { group: group as u8 },
NcnFeeGroupType::Reserved7 => Self { group: group as u8 },
NcnFeeGroupType::Reserved8 => Self { group: group as u8 },
NcnFeeGroupType::Reserved9 => Self { group: group as u8 },
NcnFeeGroupType::ReservedA => Self { group: group as u8 },
NcnFeeGroupType::ReservedB => Self { group: group as u8 },
NcnFeeGroupType::ReservedC => Self { group: group as u8 },
NcnFeeGroupType::ReservedD => Self { group: group as u8 },
NcnFeeGroupType::ReservedE => Self { group: group as u8 },
NcnFeeGroupType::ReservedF => Self { group: group as u8 },
// NcnFeeGroupType::Reserved8 => Self { group: group as u8 },
// NcnFeeGroupType::Reserved9 => Self { group: group as u8 },
// NcnFeeGroupType::ReservedA => Self { group: group as u8 },
// NcnFeeGroupType::ReservedB => Self { group: group as u8 },
// NcnFeeGroupType::ReservedC => Self { group: group as u8 },
// NcnFeeGroupType::ReservedD => Self { group: group as u8 },
// NcnFeeGroupType::ReservedE => Self { group: group as u8 },
// NcnFeeGroupType::ReservedF => Self { group: group as u8 },
}
}

Expand All @@ -73,14 +73,14 @@ impl NcnFeeGroup {
0x5 => Ok(Self::new(NcnFeeGroupType::Reserved5)),
0x6 => Ok(Self::new(NcnFeeGroupType::Reserved6)),
0x7 => Ok(Self::new(NcnFeeGroupType::Reserved7)),
0x8 => Ok(Self::new(NcnFeeGroupType::Reserved8)),
0x9 => Ok(Self::new(NcnFeeGroupType::Reserved9)),
0xA => Ok(Self::new(NcnFeeGroupType::ReservedA)),
0xB => Ok(Self::new(NcnFeeGroupType::ReservedB)),
0xC => Ok(Self::new(NcnFeeGroupType::ReservedC)),
0xD => Ok(Self::new(NcnFeeGroupType::ReservedD)),
0xE => Ok(Self::new(NcnFeeGroupType::ReservedE)),
0xF => Ok(Self::new(NcnFeeGroupType::ReservedF)),
// 0x8 => Ok(Self::new(NcnFeeGroupType::Reserved8)),
// 0x9 => Ok(Self::new(NcnFeeGroupType::Reserved9)),
// 0xA => Ok(Self::new(NcnFeeGroupType::ReservedA)),
// 0xB => Ok(Self::new(NcnFeeGroupType::ReservedB)),
// 0xC => Ok(Self::new(NcnFeeGroupType::ReservedC)),
// 0xD => Ok(Self::new(NcnFeeGroupType::ReservedD)),
// 0xE => Ok(Self::new(NcnFeeGroupType::ReservedE)),
// 0xF => Ok(Self::new(NcnFeeGroupType::ReservedF)),
_ => Err(TipRouterError::InvalidNcnFeeGroup),
}
}
Expand All @@ -95,14 +95,14 @@ impl NcnFeeGroup {
0x5 => Ok(NcnFeeGroupType::Reserved5),
0x6 => Ok(NcnFeeGroupType::Reserved6),
0x7 => Ok(NcnFeeGroupType::Reserved7),
0x8 => Ok(NcnFeeGroupType::Reserved8),
0x9 => Ok(NcnFeeGroupType::Reserved9),
0xA => Ok(NcnFeeGroupType::ReservedA),
0xB => Ok(NcnFeeGroupType::ReservedB),
0xC => Ok(NcnFeeGroupType::ReservedC),
0xD => Ok(NcnFeeGroupType::ReservedD),
0xE => Ok(NcnFeeGroupType::ReservedE),
0xF => Ok(NcnFeeGroupType::ReservedF),
// 0x8 => Ok(NcnFeeGroupType::Reserved8),
// 0x9 => Ok(NcnFeeGroupType::Reserved9),
// 0xA => Ok(NcnFeeGroupType::ReservedA),
// 0xB => Ok(NcnFeeGroupType::ReservedB),
// 0xC => Ok(NcnFeeGroupType::ReservedC),
// 0xD => Ok(NcnFeeGroupType::ReservedD),
// 0xE => Ok(NcnFeeGroupType::ReservedE),
// 0xF => Ok(NcnFeeGroupType::ReservedF),
_ => Err(TipRouterError::InvalidNcnFeeGroup),
}
}
Expand All @@ -122,14 +122,14 @@ impl NcnFeeGroup {
Self::new(NcnFeeGroupType::Reserved5),
Self::new(NcnFeeGroupType::Reserved6),
Self::new(NcnFeeGroupType::Reserved7),
Self::new(NcnFeeGroupType::Reserved8),
Self::new(NcnFeeGroupType::Reserved9),
Self::new(NcnFeeGroupType::ReservedA),
Self::new(NcnFeeGroupType::ReservedB),
Self::new(NcnFeeGroupType::ReservedC),
Self::new(NcnFeeGroupType::ReservedD),
Self::new(NcnFeeGroupType::ReservedE),
Self::new(NcnFeeGroupType::ReservedF),
// Self::new(NcnFeeGroupType::Reserved8),
// Self::new(NcnFeeGroupType::Reserved9),
// Self::new(NcnFeeGroupType::ReservedA),
// Self::new(NcnFeeGroupType::ReservedB),
// Self::new(NcnFeeGroupType::ReservedC),
// Self::new(NcnFeeGroupType::ReservedD),
// Self::new(NcnFeeGroupType::ReservedE),
// Self::new(NcnFeeGroupType::ReservedF),
]
}
}
12 changes: 6 additions & 6 deletions core/src/stake_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use crate::{error::TipRouterError, ncn_fee_group::NcnFeeGroup};
#[repr(C)]
pub struct StakeWeight {
stake_weight: PodU128,
reward_stake_weights: [RewardStakeWeight; 16],
reward_stake_weights: [RewardStakeWeight; 8],
// Reserves
reserved: [u8; 64],
// reserved: [u8; 64],
}

impl Default for StakeWeight {
fn default() -> Self {
Self {
stake_weight: PodU128::from(0),
reward_stake_weights: [RewardStakeWeight::default(); NcnFeeGroup::FEE_GROUP_COUNT],
reserved: [0; 64],
// reserved: [0; 64],
}
}
}
Expand Down Expand Up @@ -75,14 +75,14 @@ impl StakeWeight {
#[repr(C)]
pub struct RewardStakeWeight {
reward_stake_weight: PodU128,
reserved: [u8; 64],
// reserved: [u8; 64],
}

impl Default for RewardStakeWeight {
fn default() -> Self {
Self {
reward_stake_weight: PodU128::from(0),
reserved: [0; 64],
// reserved: [0; 64],
}
}
}
Expand All @@ -91,7 +91,7 @@ impl RewardStakeWeight {
pub fn new(reward_stake_weight: u128) -> Self {
Self {
reward_stake_weight: PodU128::from(reward_stake_weight),
reserved: [0; 64],
// reserved: [0; 64],
}
}

Expand Down
Loading

0 comments on commit 2dd2132

Please sign in to comment.