Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ballot Box #10

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 163 additions & 0 deletions clients/js/jito_tip_router/accounts/ballotBox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/**
* 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 {
assertAccountExists,
assertAccountsExist,
combineCodec,
decodeAccount,
fetchEncodedAccount,
fetchEncodedAccounts,
getAddressDecoder,
getAddressEncoder,
getArrayDecoder,
getArrayEncoder,
getStructDecoder,
getStructEncoder,
getU64Decoder,
getU64Encoder,
getU8Decoder,
getU8Encoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type MaybeAccount,
type MaybeEncodedAccount,
} from '@solana/web3.js';
import {
getBallotTallyDecoder,
getBallotTallyEncoder,
getOperatorVoteDecoder,
getOperatorVoteEncoder,
type BallotTally,
type BallotTallyArgs,
type OperatorVote,
type OperatorVoteArgs,
} from '../types';

export type BallotBox = {
discriminator: bigint;
ncn: Address;
ncnEpoch: bigint;
bump: number;
slotCreated: bigint;
slotConsensusReached: bigint;
reserved: Array<number>;
operatorsVoted: bigint;
uniqueBallots: bigint;
operatorVotes: Array<OperatorVote>;
ballotTallies: Array<BallotTally>;
};

export type BallotBoxArgs = {
discriminator: number | bigint;
ncn: Address;
ncnEpoch: number | bigint;
bump: number;
slotCreated: number | bigint;
slotConsensusReached: number | bigint;
reserved: Array<number>;
operatorsVoted: number | bigint;
uniqueBallots: number | bigint;
operatorVotes: Array<OperatorVoteArgs>;
ballotTallies: Array<BallotTallyArgs>;
};

export function getBallotBoxEncoder(): Encoder<BallotBoxArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['ncnEpoch', getU64Encoder()],
['bump', getU8Encoder()],
['slotCreated', getU64Encoder()],
['slotConsensusReached', getU64Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })],
['operatorsVoted', getU64Encoder()],
['uniqueBallots', getU64Encoder()],
['operatorVotes', getArrayEncoder(getOperatorVoteEncoder(), { size: 32 })],
['ballotTallies', getArrayEncoder(getBallotTallyEncoder(), { size: 32 })],
]);
}

export function getBallotBoxDecoder(): Decoder<BallotBox> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['ncnEpoch', getU64Decoder()],
['bump', getU8Decoder()],
['slotCreated', getU64Decoder()],
['slotConsensusReached', getU64Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })],
['operatorsVoted', getU64Decoder()],
['uniqueBallots', getU64Decoder()],
['operatorVotes', getArrayDecoder(getOperatorVoteDecoder(), { size: 32 })],
['ballotTallies', getArrayDecoder(getBallotTallyDecoder(), { size: 32 })],
]);
}

export function getBallotBoxCodec(): Codec<BallotBoxArgs, BallotBox> {
return combineCodec(getBallotBoxEncoder(), getBallotBoxDecoder());
}

export function decodeBallotBox<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress>
): Account<BallotBox, TAddress>;
export function decodeBallotBox<TAddress extends string = string>(
encodedAccount: MaybeEncodedAccount<TAddress>
): MaybeAccount<BallotBox, TAddress>;
export function decodeBallotBox<TAddress extends string = string>(
encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>
): Account<BallotBox, TAddress> | MaybeAccount<BallotBox, TAddress> {
return decodeAccount(
encodedAccount as MaybeEncodedAccount<TAddress>,
getBallotBoxDecoder()
);
}

export async function fetchBallotBox<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<Account<BallotBox, TAddress>> {
const maybeAccount = await fetchMaybeBallotBox(rpc, address, config);
assertAccountExists(maybeAccount);
return maybeAccount;
}

export async function fetchMaybeBallotBox<TAddress extends string = string>(
rpc: Parameters<typeof fetchEncodedAccount>[0],
address: Address<TAddress>,
config?: FetchAccountConfig
): Promise<MaybeAccount<BallotBox, TAddress>> {
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
return decodeBallotBox(maybeAccount);
}

export async function fetchAllBallotBox(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<Account<BallotBox>[]> {
const maybeAccounts = await fetchAllMaybeBallotBox(rpc, addresses, config);
assertAccountsExist(maybeAccounts);
return maybeAccounts;
}

export async function fetchAllMaybeBallotBox(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<BallotBox>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeBallotBox(maybeAccount));
}
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @see https://github.com/kinobi-so/kinobi
*/

export * from './ballotBox';
export * from './epochSnapshot';
export * from './ncnConfig';
export * from './operatorSnapshot';
Expand Down
12 changes: 12 additions & 0 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ export const JITO_TIP_ROUTER_ERROR__OPERATOR_FINALIZED = 0x2216; // 8726
export const JITO_TIP_ROUTER_ERROR__TOO_MANY_VAULT_OPERATOR_DELEGATIONS = 0x2217; // 8727
/** DuplicateVaultOperatorDelegation: Duplicate vault operator delegation */
export const JITO_TIP_ROUTER_ERROR__DUPLICATE_VAULT_OPERATOR_DELEGATION = 0x2218; // 8728
/** DuplicateVoteCast: Duplicate Vote Cast */
export const JITO_TIP_ROUTER_ERROR__DUPLICATE_VOTE_CAST = 0x2219; // 8729
/** OperatorVotesFull: Operator votes full */
export const JITO_TIP_ROUTER_ERROR__OPERATOR_VOTES_FULL = 0x221a; // 8730
/** BallotTallyFull: Merkle root tally full */
export const JITO_TIP_ROUTER_ERROR__BALLOT_TALLY_FULL = 0x221b; // 8731

export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__BALLOT_TALLY_FULL
| typeof JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES
| typeof JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__CONFIG_MINT_LIST_FULL
| typeof JITO_TIP_ROUTER_ERROR__CONFIG_MINTS_NOT_UPDATED
| typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO
| typeof JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE
| typeof JITO_TIP_ROUTER_ERROR__DUPLICATE_VAULT_OPERATOR_DELEGATION
| typeof JITO_TIP_ROUTER_ERROR__DUPLICATE_VOTE_CAST
| typeof JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN
Expand All @@ -95,6 +103,7 @@ export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE
| typeof JITO_TIP_ROUTER_ERROR__NO_OPERATORS
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_FINALIZED
| typeof JITO_TIP_ROUTER_ERROR__OPERATOR_VOTES_FULL
| typeof JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE
| typeof JITO_TIP_ROUTER_ERROR__TOO_MANY_VAULT_OPERATOR_DELEGATIONS
| typeof JITO_TIP_ROUTER_ERROR__TRACKED_MINT_LIST_FULL
Expand All @@ -111,13 +120,15 @@ let jitoTipRouterErrorMessages: Record<JitoTipRouterError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
jitoTipRouterErrorMessages = {
[JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW]: `Overflow`,
[JITO_TIP_ROUTER_ERROR__BALLOT_TALLY_FULL]: `Merkle root tally full`,
[JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES]: `Cannnot create future weight tables`,
[JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR]: `Cast to imprecise number error`,
[JITO_TIP_ROUTER_ERROR__CONFIG_MINT_LIST_FULL]: `NCN config vaults are at capacity`,
[JITO_TIP_ROUTER_ERROR__CONFIG_MINTS_NOT_UPDATED]: `Config supported mints do not match NCN Vault Count`,
[JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO]: `Zero in the denominator`,
[JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE]: `Duplicate mints in table`,
[JITO_TIP_ROUTER_ERROR__DUPLICATE_VAULT_OPERATOR_DELEGATION]: `Duplicate vault operator delegation`,
[JITO_TIP_ROUTER_ERROR__DUPLICATE_VOTE_CAST]: `Duplicate Vote Cast`,
[JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED]: `Fee cap exceeded`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN]: `Incorrect fee admin`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_NCN]: `Incorrect NCN`,
Expand All @@ -129,6 +140,7 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE]: `There are no mints in the table`,
[JITO_TIP_ROUTER_ERROR__NO_OPERATORS]: `No operators in ncn`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_FINALIZED]: `Operator is already finalized - should not happen`,
[JITO_TIP_ROUTER_ERROR__OPERATOR_VOTES_FULL]: `Operator votes full`,
[JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE]: `Too many mints for table`,
[JITO_TIP_ROUTER_ERROR__TOO_MANY_VAULT_OPERATOR_DELEGATIONS]: `Too many vault operator delegations`,
[JITO_TIP_ROUTER_ERROR__TRACKED_MINT_LIST_FULL]: `Tracked mints are at capacity`,
Expand Down
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/programs/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const JITO_TIP_ROUTER_PROGRAM_ADDRESS =
'Fv9aHCgvPQSr4jg9W8eTS6Ys1SNmh2qjyATrbsjEMaSH' as Address<'Fv9aHCgvPQSr4jg9W8eTS6Ys1SNmh2qjyATrbsjEMaSH'>;

export enum JitoTipRouterAccount {
BallotBox,
EpochSnapshot,
OperatorSnapshot,
NcnConfig,
Expand Down
59 changes: 59 additions & 0 deletions clients/js/jito_tip_router/types/ballot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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 Ballot = {
merkleRoot: ReadonlyUint8Array;
maxTotalClaim: bigint;
maxNodeCount: bigint;
reserved: ReadonlyUint8Array;
};

export type BallotArgs = {
merkleRoot: ReadonlyUint8Array;
maxTotalClaim: number | bigint;
maxNodeCount: number | bigint;
reserved: ReadonlyUint8Array;
};

export function getBallotEncoder(): Encoder<BallotArgs> {
return getStructEncoder([
['merkleRoot', fixEncoderSize(getBytesEncoder(), 32)],
['maxTotalClaim', getU64Encoder()],
['maxNodeCount', getU64Encoder()],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
}

export function getBallotDecoder(): Decoder<Ballot> {
return getStructDecoder([
['merkleRoot', fixDecoderSize(getBytesDecoder(), 32)],
['maxTotalClaim', getU64Decoder()],
['maxNodeCount', getU64Decoder()],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
}

export function getBallotCodec(): Codec<BallotArgs, Ballot> {
return combineCodec(getBallotEncoder(), getBallotDecoder());
}
67 changes: 67 additions & 0 deletions clients/js/jito_tip_router/types/ballotTally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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,
getU128Decoder,
getU128Encoder,
getU64Decoder,
getU64Encoder,
type Codec,
type Decoder,
type Encoder,
type ReadonlyUint8Array,
} from '@solana/web3.js';
import {
getBallotDecoder,
getBallotEncoder,
type Ballot,
type BallotArgs,
} from '.';

export type BallotTally = {
ballot: Ballot;
stakeWeight: bigint;
tally: bigint;
reserved: ReadonlyUint8Array;
};

export type BallotTallyArgs = {
ballot: BallotArgs;
stakeWeight: number | bigint;
tally: number | bigint;
reserved: ReadonlyUint8Array;
};

export function getBallotTallyEncoder(): Encoder<BallotTallyArgs> {
return getStructEncoder([
['ballot', getBallotEncoder()],
['stakeWeight', getU128Encoder()],
['tally', getU64Encoder()],
['reserved', fixEncoderSize(getBytesEncoder(), 64)],
]);
}

export function getBallotTallyDecoder(): Decoder<BallotTally> {
return getStructDecoder([
['ballot', getBallotDecoder()],
['stakeWeight', getU128Decoder()],
['tally', getU64Decoder()],
['reserved', fixDecoderSize(getBytesDecoder(), 64)],
]);
}

export function getBallotTallyCodec(): Codec<BallotTallyArgs, BallotTally> {
return combineCodec(getBallotTallyEncoder(), getBallotTallyDecoder());
}
3 changes: 3 additions & 0 deletions clients/js/jito_tip_router/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
* @see https://github.com/kinobi-so/kinobi
*/

export * from './ballot';
export * from './ballotTally';
export * from './configAdminRole';
export * from './fee';
export * from './fees';
export * from './mintEntry';
export * from './operatorVote';
export * from './vaultOperatorStakeWeight';
export * from './weightEntry';
Loading
Loading