Skip to content

Commit

Permalink
Move tracked_mints to its own account
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Nov 12, 2024
1 parent 3fd07d4 commit 01bee5a
Show file tree
Hide file tree
Showing 28 changed files with 1,400 additions and 149 deletions.
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 @@ -7,4 +7,5 @@
*/

export * from './ncnConfig';
export * from './trackedMints';
export * from './weightTable';
8 changes: 0 additions & 8 deletions clients/js/jito_tip_router/accounts/ncnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ import {
import {
getFeesDecoder,
getFeesEncoder,
getMintEntryDecoder,
getMintEntryEncoder,
type Fees,
type FeesArgs,
type MintEntry,
type MintEntryArgs,
} from '../types';

export type NcnConfig = {
Expand All @@ -51,7 +47,6 @@ export type NcnConfig = {
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: Fees;
mintList: Array<MintEntry>;
bump: number;
reserved: Array<number>;
};
Expand All @@ -62,7 +57,6 @@ export type NcnConfigArgs = {
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: FeesArgs;
mintList: Array<MintEntryArgs>;
bump: number;
reserved: Array<number>;
};
Expand All @@ -74,7 +68,6 @@ export function getNcnConfigEncoder(): Encoder<NcnConfigArgs> {
['tieBreakerAdmin', getAddressEncoder()],
['feeAdmin', getAddressEncoder()],
['fees', getFeesEncoder()],
['mintList', getArrayEncoder(getMintEntryEncoder(), { size: 64 })],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 127 })],
]);
Expand All @@ -87,7 +80,6 @@ export function getNcnConfigDecoder(): Decoder<NcnConfig> {
['tieBreakerAdmin', getAddressDecoder()],
['feeAdmin', getAddressDecoder()],
['fees', getFeesDecoder()],
['mintList', getArrayDecoder(getMintEntryDecoder(), { size: 64 })],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 127 })],
]);
Expand Down
135 changes: 135 additions & 0 deletions clients/js/jito_tip_router/accounts/trackedMints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* 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 {
getMintEntryDecoder,
getMintEntryEncoder,
type MintEntry,
type MintEntryArgs,
} from '../types';

export type TrackedMints = {
discriminator: bigint;
ncn: Address;
bump: number;
reserved: Array<number>;
stMintList: Array<MintEntry>;
};

export type TrackedMintsArgs = {
discriminator: number | bigint;
ncn: Address;
bump: number;
reserved: Array<number>;
stMintList: Array<MintEntryArgs>;
};

export function getTrackedMintsEncoder(): Encoder<TrackedMintsArgs> {
return getStructEncoder([
['discriminator', getU64Encoder()],
['ncn', getAddressEncoder()],
['bump', getU8Encoder()],
['reserved', getArrayEncoder(getU8Encoder(), { size: 7 })],
['stMintList', getArrayEncoder(getMintEntryEncoder(), { size: 64 })],
]);
}

export function getTrackedMintsDecoder(): Decoder<TrackedMints> {
return getStructDecoder([
['discriminator', getU64Decoder()],
['ncn', getAddressDecoder()],
['bump', getU8Decoder()],
['reserved', getArrayDecoder(getU8Decoder(), { size: 7 })],
['stMintList', getArrayDecoder(getMintEntryDecoder(), { size: 64 })],
]);
}

export function getTrackedMintsCodec(): Codec<TrackedMintsArgs, TrackedMints> {
return combineCodec(getTrackedMintsEncoder(), getTrackedMintsDecoder());
}

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

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

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

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

export async function fetchAllMaybeTrackedMints(
rpc: Parameters<typeof fetchEncodedAccounts>[0],
addresses: Array<Address>,
config?: FetchAccountsConfig
): Promise<MaybeAccount<TrackedMints>[]> {
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
return maybeAccounts.map((maybeAccount) => decodeTrackedMints(maybeAccount));
}
8 changes: 8 additions & 0 deletions clients/js/jito_tip_router/errors/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export const JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE = 0x2208; // 8
export const JITO_TIP_ROUTER_ERROR__CONFIG_MINTS_NOT_UPDATED = 0x2209; // 8713
/** ConfigMintListFull: NCN config vaults are at capacity */
export const JITO_TIP_ROUTER_ERROR__CONFIG_MINT_LIST_FULL = 0x220a; // 8714
/** TrackedMintListFull: Tracked mints are at capacity */
export const JITO_TIP_ROUTER_ERROR__TRACKED_MINT_LIST_FULL = 0x220b; // 8715
/** VaultIndexAlreadyInUse: Vault index already in use by a different mint */
export const JITO_TIP_ROUTER_ERROR__VAULT_INDEX_ALREADY_IN_USE = 0x220c; // 8716
/** FeeCapExceeded: Fee cap exceeded */
export const JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED = 0x2300; // 8960
/** IncorrectNcnAdmin: Incorrect NCN Admin */
Expand Down Expand Up @@ -73,6 +77,8 @@ export type JitoTipRouterError =
| typeof JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR
| typeof JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE
| typeof JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE
| typeof JITO_TIP_ROUTER_ERROR__TRACKED_MINT_LIST_FULL
| typeof JITO_TIP_ROUTER_ERROR__VAULT_INDEX_ALREADY_IN_USE
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH
| typeof JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED;
Expand All @@ -97,6 +103,8 @@ if (process.env.NODE_ENV !== 'production') {
[JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR]: `New precise number error`,
[JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE]: `There are no mints in the table`,
[JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE]: `Too many mints for table`,
[JITO_TIP_ROUTER_ERROR__TRACKED_MINT_LIST_FULL]: `Tracked mints are at capacity`,
[JITO_TIP_ROUTER_ERROR__VAULT_INDEX_ALREADY_IN_USE]: `Vault index already in use by a different mint`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH]: `Weight mints do not match - length`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH]: `Weight mints do not match - mint hash`,
[JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED]: `Weight table already initialized`,
Expand Down
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

export * from './adminUpdateWeightTable';
export * from './initializeNCNConfig';
export * from './initializeTrackedMints';
export * from './initializeWeightTable';
export * from './registerMint';
export * from './setConfigFees';
Expand Down
Loading

0 comments on commit 01bee5a

Please sign in to comment.