Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 20, 2024
1 parent 4f4db15 commit 47c4a00
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ use spl_math::precise_number::PreciseNumber;

use crate::{constants::PRECISE_CONSENSUS, discriminators::Discriminators, error::TipRouterError};

// vote_stake_weight
// reward_stake_weight

// to make calculations easier, we can calculate the operator percentage when
// the ballot box is closed.

#[derive(Debug, Clone, PartialEq, Eq, Copy, Zeroable, ShankType, Pod, ShankType)]
#[repr(C)]
pub struct Ballot {
Expand Down Expand Up @@ -282,6 +288,10 @@ impl BallotBox {
self.slot_consensus_reached() > 0
}

pub fn ballot_tallies(&self) -> &[BallotTally; 32] {
&self.ballot_tallies
}

pub fn get_winning_ballot(&self) -> Result<Ballot, TipRouterError> {
if self.winning_ballot.is_valid() {
Ok(self.winning_ballot)
Expand Down
2 changes: 2 additions & 0 deletions core/src/discriminators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ pub enum Discriminators {
// Voting
BallotBox = 0x20,
// Distribution
RewardRouter = 0x30,
OperatorRewardRouter = 0x31,
}
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod fees;
pub mod instruction;
pub mod loaders;
pub mod ncn_config;
pub mod reward_router;
pub mod tracked_mints;
pub mod weight_entry;
pub mod weight_table;
87 changes: 87 additions & 0 deletions core/src/reward_router.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
use bytemuck::{Pod, Zeroable};
use jito_bytemuck::{types::PodU64, AccountDeserialize, Discriminator};
use shank::{ShankAccount, ShankType};
use solana_program::pubkey::Pubkey;

use crate::{
ballot_box::{self, BallotBox},
discriminators::Discriminators,
error::TipRouterError,
};

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

// PDA'd ["epoch_reward_router", NCN, NCN_EPOCH_SLOT]
#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod, AccountDeserialize, ShankAccount)]
#[repr(C)]
pub struct EpochRewardRouter {
ncn: Pubkey,

ncn_epoch: PodU64,

bump: u8,

slot_created: PodU64,

reserved: [u8; 128],

reward_pool: PodU64,

operator_rewards: [OperatorReward; 32],
}

impl Discriminator for EpochRewardRouter {
const DISCRIMINATOR: u8 = Discriminators::EpochSnapshot as u8;
}

impl EpochRewardRouter {
pub fn process_new_rewards(
&mut self,
ballot_box: &BallotBox,
new_rewards: u64,
) -> Result<(), TipRouterError> {
let winning_ballot = ballot_box.get_winning_ballot()?;
for tally in ballot_box.ballot_tallies() {}

Ok(())
}
}

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

// PDA'd ["operator_reward_router", NCN, NCN_EPOCH_SLOT]
#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod, AccountDeserialize, ShankAccount)]
#[repr(C)]
pub struct OperatorRewardRouter {
ncn: Pubkey,

ncn_epoch: PodU64,

bump: u8,

slot_created: PodU64,

reserved: [u8; 128],

reward_pool: PodU64,

vault_rewards: [VaultReward; 32],
}

impl Discriminator for OperatorRewardRouter {
const DISCRIMINATOR: u8 = Discriminators::EpochSnapshot as u8;
}

impl EpochRewardRouter {}

0 comments on commit 47c4a00

Please sign in to comment.