Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Nov 8, 2024
2 parents 6851eee + 27be373 commit f75b100
Show file tree
Hide file tree
Showing 58 changed files with 5,017 additions and 284 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 @@ -42,13 +42,25 @@ export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH = 0x2206; /
export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH = 0x2207; // 8711
/** InvalidMintForWeightTable: Invalid mint for weight table */
export const JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE = 0x2208; // 8712
/** 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__CAST_TO_IMPRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO
| typeof JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE
| 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__INVALID_MINT_FOR_WEIGHT_TABLE
| typeof JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW
Expand All @@ -67,6 +79,10 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR]: `Cast to imprecise number error`,
[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__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__INVALID_MINT_FOR_WEIGHT_TABLE]: `Invalid mint for weight table`,
[JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW]: `Modulo Overflow`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 1;
export const ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 4;

export function getAdminUpdateWeightTableDiscriminatorBytes() {
return getU8Encoder().encode(ADMIN_UPDATE_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,4 +7,7 @@
*/

export * from './adminUpdateWeightTable';
export * from './initializeNCNConfig';
export * from './initializeWeightTable';
export * from './setConfigFees';
export * from './setNewAdmin';
Loading

0 comments on commit f75b100

Please sign in to comment.