Skip to content

Commit

Permalink
Merge pull request #1 from jito-foundation/eb/ncn-config
Browse files Browse the repository at this point in the history
NCN Config Setup
  • Loading branch information
coachchucksol authored Nov 7, 2024
2 parents fe60486 + b14b8ee commit 27be373
Show file tree
Hide file tree
Showing 57 changed files with 4,613 additions and 265 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Program IDs may not be correct
[env]
TIP_ROUTER_PROGRAM_ID = "Fv9aHCgvPQSr4jg9W8eTS6Ys1SNmh2qjyATrbsjEMaSH"
RESTAKING_PROGRAM_ID = "6Weyp6uFyjJ3pzYz7XbXvCPAyvzLUhESEhHarFRm53Nb"
VAULT_PROGRAM_ID = "4vB3bvqKEmxV68J7XtS1HqZomjok4ZXc1ELJH9p1K1D2"
RESTAKING_PROGRAM_ID = "RestkWeAVL8fRGgzhfeoqFhsqKRchg6aa1XrcH96z4Q"
VAULT_PROGRAM_ID = "Vau1t6sLNxnzB7ZDsef8TLbPLfyZMYXH8WTNqUdm9g8"
4 changes: 2 additions & 2 deletions .cargo/programs.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TIP_ROUTER_PROGRAM_ID=Fv9aHCgvPQSr4jg9W8eTS6Ys1SNmh2qjyATrbsjEMaSH
RESTAKING_PROGRAM_ID=6Weyp6uFyjJ3pzYz7XbXvCPAyvzLUhESEhHarFRm53Nb
VAULT_PROGRAM_ID=4vB3bvqKEmxV68J7XtS1HqZomjok4ZXc1ELJH9p1K1D2
RESTAKING_PROGRAM_ID=RestkWeAVL8fRGgzhfeoqFhsqKRchg6aa1XrcH96z4Q
VAULT_PROGRAM_ID=Vau1t6sLNxnzB7ZDsef8TLbPLfyZMYXH8WTNqUdm9g8
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,4 +6,5 @@
* @see https://github.com/kinobi-so/kinobi
*/

export * from './ncnConfig';
export * from './weightTable';
147 changes: 147 additions & 0 deletions clients/js/jito_tip_router/accounts/ncnConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/**
* 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 {
getFeesDecoder,
getFeesEncoder,
type Fees,
type FeesArgs,
} from '../types';

export type NcnConfig = {
discriminator: bigint;
ncn: Address;
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: Fees;
bump: number;
reserved: Array<number>;
};

export type NcnConfigArgs = {
discriminator: number | bigint;
ncn: Address;
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: FeesArgs;
bump: number;
reserved: Array<number>;
};

export function getNcnConfigEncoder(): Encoder<NcnConfigArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['tieBreakerAdmin', getAddressEncoder()],
['feeAdmin', getAddressEncoder()],
['fees', getFeesEncoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 127 })],
]);
}

export function getNcnConfigDecoder(): Decoder<NcnConfig> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['tieBreakerAdmin', getAddressDecoder()],
['feeAdmin', getAddressDecoder()],
['fees', getFeesDecoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 127 })],
]);
}

export function getNcnConfigCodec(): Codec<NcnConfigArgs, NcnConfig> {
return combineCodec(getNcnConfigEncoder(), getNcnConfigDecoder());
}

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

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

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

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

export async function fetchAllMaybeNcnConfig(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<NcnConfig>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeNcnConfig(maybeAccount));
}

export function getNcnConfigSize(): number {
return 352;
}
16 changes: 16 additions & 0 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,23 @@ export const JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW = 0x2102; // 8450
export const JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN = 0x2200; // 8704
/** CannotCreateFutureWeightTables: Cannnot create future weight tables */
export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2201; // 8705
/** FeeCapExceeded: Fee cap exceeded */
export const JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED = 0x2300; // 8960
/** IncorrectNcnAdmin: Incorrect NCN Admin */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN = 0x2400; // 9216
/** IncorrectNcn: Incorrect NCN */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_NCN = 0x2401; // 9217
/** IncorrectFeeAdmin: Incorrect fee admin */
export const JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN = 0x2402; // 9218

export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES
| typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO
| typeof JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN
| typeof JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW
| typeof JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS;
Expand All @@ -41,6 +53,10 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW]: `Overflow`,
[JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES]: `Cannnot create future weight tables`,
[JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO]: `Zero in the denominator`,
[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`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN]: `Incorrect NCN Admin`,
[JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN]: `Incorrect weight table admin`,
[JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW]: `Modulo Overflow`,
[JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS]: `No more table slots available`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const FINALIZE_WEIGHT_TABLE_DISCRIMINATOR = 2;
export const FINALIZE_WEIGHT_TABLE_DISCRIMINATOR = 3;

export function getFinalizeWeightTableDiscriminatorBytes() {
return getU8Encoder().encode(FINALIZE_WEIGHT_TABLE_DISCRIMINATOR);
Expand Down
3 changes: 3 additions & 0 deletions clients/js/jito_tip_router/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
*/

export * from './finalizeWeightTable';
export * from './initializeConfig';
export * from './initializeWeightTable';
export * from './setConfigFees';
export * from './setNewAdmin';
export * from './updateWeightTable';
Loading

0 comments on commit 27be373

Please sign in to comment.