Skip to content

Commit

Permalink
FIX: Vote with operator.voter (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol authored Jan 21, 2025
1 parent 87b1df0 commit 3613f86
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion cli/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ pub async fn admin_cast_vote(
.epoch_snapshot(epoch_snapshot)
.operator_snapshot(operator_snapshot)
.operator(operator)
.operator_admin(keypair.pubkey())
.operator_voter(keypair.pubkey())
.meta_merkle_root(meta_merkle_root)
.epoch(epoch)
.instruction();
Expand Down
8 changes: 4 additions & 4 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export const JITO_TIP_ROUTER_ERROR__VOTING_NOT_FINALIZED = 0x222c; // 8748
export const JITO_TIP_ROUTER_ERROR__TIE_BREAKER_NOT_IN_PRIOR_VOTES = 0x222d; // 8749
/** InvalidMerkleProof: Invalid merkle proof */
export const JITO_TIP_ROUTER_ERROR__INVALID_MERKLE_PROOF = 0x222e; // 8750
/** OperatorAdminInvalid: Operator admin needs to sign its vote */
export const JITO_TIP_ROUTER_ERROR__OPERATOR_ADMIN_INVALID = 0x222f; // 8751
/** InvalidOperatorVoter: Operator voter needs to sign its vote */
export const JITO_TIP_ROUTER_ERROR__INVALID_OPERATOR_VOTER = 0x222f; // 8751
/** InvalidNcnFeeGroup: Not a valid NCN fee group */
export const JITO_TIP_ROUTER_ERROR__INVALID_NCN_FEE_GROUP = 0x2230; // 8752
/** InvalidBaseFeeGroup: Not a valid base fee group */
Expand Down Expand Up @@ -239,6 +239,7 @@ export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__INVALID_MERKLE_PROOF
| typeof JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE
| typeof JITO_TIP_ROUTER_ERROR__INVALID_NCN_FEE_GROUP
| typeof JITO_TIP_ROUTER_ERROR__INVALID_OPERATOR_VOTER
| typeof JITO_TIP_ROUTER_ERROR__INVALID_SLOTS_AFTER_CONSENSUS
| typeof JITO_TIP_ROUTER_ERROR__MINT_ENTRY_NOT_FOUND
| typeof JITO_TIP_ROUTER_ERROR__MINT_IN_TABLE
Expand All @@ -251,7 +252,6 @@ export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__NO_OPERATORS
| typeof JITO_TIP_ROUTER_ERROR__NO_REWARDS
| typeof JITO_TIP_ROUTER_ERROR__NO_VAULTS_IN_REGISTRY
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_ADMIN_INVALID
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_FINALIZED
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_IS_NOT_IN_SNAPSHOT
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_REWARD_LIST_FULL
Expand Down Expand Up @@ -332,6 +332,7 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__INVALID_MERKLE_PROOF]: `Invalid merkle proof`,
[JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE]: `Invalid mint for weight table`,
[JITO_TIP_ROUTER_ERROR__INVALID_NCN_FEE_GROUP]: `Not a valid NCN fee group`,
[JITO_TIP_ROUTER_ERROR__INVALID_OPERATOR_VOTER]: `Operator voter needs to sign its vote`,
[JITO_TIP_ROUTER_ERROR__INVALID_SLOTS_AFTER_CONSENSUS]: `Invalid slots after consensus`,
[JITO_TIP_ROUTER_ERROR__MINT_ENTRY_NOT_FOUND]: `Mint Entry not found`,
[JITO_TIP_ROUTER_ERROR__MINT_IN_TABLE]: `Mint is already in the table`,
Expand All @@ -344,7 +345,6 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__NO_OPERATORS]: `No operators in ncn`,
[JITO_TIP_ROUTER_ERROR__NO_REWARDS]: `No rewards to distribute`,
[JITO_TIP_ROUTER_ERROR__NO_VAULTS_IN_REGISTRY]: `There are no vaults in the registry`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_ADMIN_INVALID]: `Operator admin needs to sign its vote`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_FINALIZED]: `Operator is already finalized - should not happen`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_IS_NOT_IN_SNAPSHOT]: `Operator is not in snapshot`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_REWARD_LIST_FULL]: `Operator reward list full`,
Expand Down
30 changes: 15 additions & 15 deletions clients/js/jito_tip_router/instructions/castVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type CastVoteInstruction<
TAccountEpochSnapshot extends string | IAccountMeta<string> = string,
TAccountOperatorSnapshot extends string | IAccountMeta<string> = string,
TAccountOperator extends string | IAccountMeta<string> = string,
TAccountOperatorAdmin extends string | IAccountMeta<string> = string,
TAccountOperatorVoter extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
Expand All @@ -77,10 +77,10 @@ export type CastVoteInstruction<
TAccountOperator extends string
? ReadonlyAccount<TAccountOperator>
: TAccountOperator,
TAccountOperatorAdmin extends string
? ReadonlySignerAccount<TAccountOperatorAdmin> &
IAccountSignerMeta<TAccountOperatorAdmin>
: TAccountOperatorAdmin,
TAccountOperatorVoter extends string
? ReadonlySignerAccount<TAccountOperatorVoter> &
IAccountSignerMeta<TAccountOperatorVoter>
: TAccountOperatorVoter,
...TRemainingAccounts,
]
>;
Expand Down Expand Up @@ -133,7 +133,7 @@ export type CastVoteInput<
TAccountEpochSnapshot extends string = string,
TAccountOperatorSnapshot extends string = string,
TAccountOperator extends string = string,
TAccountOperatorAdmin extends string = string,
TAccountOperatorVoter extends string = string,
> = {
epochState: Address<TAccountEpochState>;
config: Address<TAccountConfig>;
Expand All @@ -142,7 +142,7 @@ export type CastVoteInput<
epochSnapshot: Address<TAccountEpochSnapshot>;
operatorSnapshot: Address<TAccountOperatorSnapshot>;
operator: Address<TAccountOperator>;
operatorAdmin: TransactionSigner<TAccountOperatorAdmin>;
operatorVoter: TransactionSigner<TAccountOperatorVoter>;
metaMerkleRoot: CastVoteInstructionDataArgs['metaMerkleRoot'];
epoch: CastVoteInstructionDataArgs['epoch'];
};
Expand All @@ -155,7 +155,7 @@ export function getCastVoteInstruction<
TAccountEpochSnapshot extends string,
TAccountOperatorSnapshot extends string,
TAccountOperator extends string,
TAccountOperatorAdmin extends string,
TAccountOperatorVoter extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: CastVoteInput<
Expand All @@ -166,7 +166,7 @@ export function getCastVoteInstruction<
TAccountEpochSnapshot,
TAccountOperatorSnapshot,
TAccountOperator,
TAccountOperatorAdmin
TAccountOperatorVoter
>,
config?: { programAddress?: TProgramAddress }
): CastVoteInstruction<
Expand All @@ -178,7 +178,7 @@ export function getCastVoteInstruction<
TAccountEpochSnapshot,
TAccountOperatorSnapshot,
TAccountOperator,
TAccountOperatorAdmin
TAccountOperatorVoter
> {
// Program address.
const programAddress =
Expand All @@ -196,7 +196,7 @@ export function getCastVoteInstruction<
isWritable: false,
},
operator: { value: input.operator ?? null, isWritable: false },
operatorAdmin: { value: input.operatorAdmin ?? null, isWritable: false },
operatorVoter: { value: input.operatorVoter ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
Expand All @@ -216,7 +216,7 @@ export function getCastVoteInstruction<
getAccountMeta(accounts.epochSnapshot),
getAccountMeta(accounts.operatorSnapshot),
getAccountMeta(accounts.operator),
getAccountMeta(accounts.operatorAdmin),
getAccountMeta(accounts.operatorVoter),
],
programAddress,
data: getCastVoteInstructionDataEncoder().encode(
Expand All @@ -231,7 +231,7 @@ export function getCastVoteInstruction<
TAccountEpochSnapshot,
TAccountOperatorSnapshot,
TAccountOperator,
TAccountOperatorAdmin
TAccountOperatorVoter
>;

return instruction;
Expand All @@ -250,7 +250,7 @@ export type ParsedCastVoteInstruction<
epochSnapshot: TAccountMetas[4];
operatorSnapshot: TAccountMetas[5];
operator: TAccountMetas[6];
operatorAdmin: TAccountMetas[7];
operatorVoter: TAccountMetas[7];
};
data: CastVoteInstructionData;
};
Expand Down Expand Up @@ -283,7 +283,7 @@ export function parseCastVoteInstruction<
epochSnapshot: getNextAccount(),
operatorSnapshot: getNextAccount(),
operator: getNextAccount(),
operatorAdmin: getNextAccount(),
operatorVoter: getNextAccount(),
},
data: getCastVoteInstructionDataDecoder().decode(instruction.data),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ pub enum JitoTipRouterError {
/// 8750 - Invalid merkle proof
#[error("Invalid merkle proof")]
InvalidMerkleProof = 0x222E,
/// 8751 - Operator admin needs to sign its vote
#[error("Operator admin needs to sign its vote")]
OperatorAdminInvalid = 0x222F,
/// 8751 - Operator voter needs to sign its vote
#[error("Operator voter needs to sign its vote")]
InvalidOperatorVoter = 0x222F,
/// 8752 - Not a valid NCN fee group
#[error("Not a valid NCN fee group")]
InvalidNcnFeeGroup = 0x2230,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct CastVote {

pub operator: solana_program::pubkey::Pubkey,

pub operator_admin: solana_program::pubkey::Pubkey,
pub operator_voter: solana_program::pubkey::Pubkey,
}

impl CastVote {
Expand Down Expand Up @@ -69,7 +69,7 @@ impl CastVote {
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.operator_admin,
self.operator_voter,
true,
));
accounts.extend_from_slice(remaining_accounts);
Expand Down Expand Up @@ -120,7 +120,7 @@ pub struct CastVoteInstructionArgs {
/// 4. `[]` epoch_snapshot
/// 5. `[]` operator_snapshot
/// 6. `[]` operator
/// 7. `[signer]` operator_admin
/// 7. `[signer]` operator_voter
#[derive(Clone, Debug, Default)]
pub struct CastVoteBuilder {
epoch_state: Option<solana_program::pubkey::Pubkey>,
Expand All @@ -130,7 +130,7 @@ pub struct CastVoteBuilder {
epoch_snapshot: Option<solana_program::pubkey::Pubkey>,
operator_snapshot: Option<solana_program::pubkey::Pubkey>,
operator: Option<solana_program::pubkey::Pubkey>,
operator_admin: Option<solana_program::pubkey::Pubkey>,
operator_voter: Option<solana_program::pubkey::Pubkey>,
meta_merkle_root: Option<[u8; 32]>,
epoch: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
Expand Down Expand Up @@ -179,8 +179,8 @@ impl CastVoteBuilder {
self
}
#[inline(always)]
pub fn operator_admin(&mut self, operator_admin: solana_program::pubkey::Pubkey) -> &mut Self {
self.operator_admin = Some(operator_admin);
pub fn operator_voter(&mut self, operator_voter: solana_program::pubkey::Pubkey) -> &mut Self {
self.operator_voter = Some(operator_voter);
self
}
#[inline(always)]
Expand Down Expand Up @@ -223,7 +223,7 @@ impl CastVoteBuilder {
.operator_snapshot
.expect("operator_snapshot is not set"),
operator: self.operator.expect("operator is not set"),
operator_admin: self.operator_admin.expect("operator_admin is not set"),
operator_voter: self.operator_voter.expect("operator_voter is not set"),
};
let args = CastVoteInstructionArgs {
meta_merkle_root: self
Expand Down Expand Up @@ -253,7 +253,7 @@ pub struct CastVoteCpiAccounts<'a, 'b> {

pub operator: &'b solana_program::account_info::AccountInfo<'a>,

pub operator_admin: &'b solana_program::account_info::AccountInfo<'a>,
pub operator_voter: &'b solana_program::account_info::AccountInfo<'a>,
}

/// `cast_vote` CPI instruction.
Expand All @@ -275,7 +275,7 @@ pub struct CastVoteCpi<'a, 'b> {

pub operator: &'b solana_program::account_info::AccountInfo<'a>,

pub operator_admin: &'b solana_program::account_info::AccountInfo<'a>,
pub operator_voter: &'b solana_program::account_info::AccountInfo<'a>,
/// The arguments for the instruction.
pub __args: CastVoteInstructionArgs,
}
Expand All @@ -295,7 +295,7 @@ impl<'a, 'b> CastVoteCpi<'a, 'b> {
epoch_snapshot: accounts.epoch_snapshot,
operator_snapshot: accounts.operator_snapshot,
operator: accounts.operator,
operator_admin: accounts.operator_admin,
operator_voter: accounts.operator_voter,
__args: args,
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@ impl<'a, 'b> CastVoteCpi<'a, 'b> {
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.operator_admin.key,
*self.operator_voter.key,
true,
));
remaining_accounts.iter().for_each(|remaining_account| {
Expand Down Expand Up @@ -390,7 +390,7 @@ impl<'a, 'b> CastVoteCpi<'a, 'b> {
account_infos.push(self.epoch_snapshot.clone());
account_infos.push(self.operator_snapshot.clone());
account_infos.push(self.operator.clone());
account_infos.push(self.operator_admin.clone());
account_infos.push(self.operator_voter.clone());
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
Expand All @@ -414,7 +414,7 @@ impl<'a, 'b> CastVoteCpi<'a, 'b> {
/// 4. `[]` epoch_snapshot
/// 5. `[]` operator_snapshot
/// 6. `[]` operator
/// 7. `[signer]` operator_admin
/// 7. `[signer]` operator_voter
#[derive(Clone, Debug)]
pub struct CastVoteCpiBuilder<'a, 'b> {
instruction: Box<CastVoteCpiBuilderInstruction<'a, 'b>>,
Expand All @@ -431,7 +431,7 @@ impl<'a, 'b> CastVoteCpiBuilder<'a, 'b> {
epoch_snapshot: None,
operator_snapshot: None,
operator: None,
operator_admin: None,
operator_voter: None,
meta_merkle_root: None,
epoch: None,
__remaining_accounts: Vec::new(),
Expand Down Expand Up @@ -492,11 +492,11 @@ impl<'a, 'b> CastVoteCpiBuilder<'a, 'b> {
self
}
#[inline(always)]
pub fn operator_admin(
pub fn operator_voter(
&mut self,
operator_admin: &'b solana_program::account_info::AccountInfo<'a>,
operator_voter: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.operator_admin = Some(operator_admin);
self.instruction.operator_voter = Some(operator_voter);
self
}
#[inline(always)]
Expand Down Expand Up @@ -584,10 +584,10 @@ impl<'a, 'b> CastVoteCpiBuilder<'a, 'b> {

operator: self.instruction.operator.expect("operator is not set"),

operator_admin: self
operator_voter: self
.instruction
.operator_admin
.expect("operator_admin is not set"),
.operator_voter
.expect("operator_voter is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
Expand All @@ -607,7 +607,7 @@ struct CastVoteCpiBuilderInstruction<'a, 'b> {
epoch_snapshot: Option<&'b solana_program::account_info::AccountInfo<'a>>,
operator_snapshot: Option<&'b solana_program::account_info::AccountInfo<'a>>,
operator: Option<&'b solana_program::account_info::AccountInfo<'a>>,
operator_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>,
operator_voter: Option<&'b solana_program::account_info::AccountInfo<'a>>,
meta_merkle_root: Option<[u8; 32]>,
epoch: Option<u64>,
/// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
Expand Down
4 changes: 2 additions & 2 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ pub enum TipRouterError {
TieBreakerNotInPriorVotes,
#[error("Invalid merkle proof")]
InvalidMerkleProof,
#[error("Operator admin needs to sign its vote")]
OperatorAdminInvalid,
#[error("Operator voter needs to sign its vote")]
InvalidOperatorVoter,
#[error("Not a valid NCN fee group")]
InvalidNcnFeeGroup,
#[error("Not a valid base fee group")]
Expand Down
2 changes: 1 addition & 1 deletion core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub enum TipRouterInstruction {
#[account(4, name = "epoch_snapshot")]
#[account(5, name = "operator_snapshot")]
#[account(6, name = "operator")]
#[account(7, signer, name = "operator_admin")]
#[account(7, signer, name = "operator_voter")]
CastVote {
meta_merkle_root: [u8; 32],
epoch: u64,
Expand Down
6 changes: 3 additions & 3 deletions idl/jito_tip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@
"isSigner": false
},
{
"name": "operatorAdmin",
"name": "operatorVoter",
"isMut": false,
"isSigner": true
}
Expand Down Expand Up @@ -3624,8 +3624,8 @@
},
{
"code": 8751,
"name": "OperatorAdminInvalid",
"msg": "Operator admin needs to sign its vote"
"name": "InvalidOperatorVoter",
"msg": "Operator voter needs to sign its vote"
},
{
"code": 8752,
Expand Down
Loading

0 comments on commit 3613f86

Please sign in to comment.