Skip to content

Commit

Permalink
Register mints
Browse files Browse the repository at this point in the history
  • Loading branch information
ebatsell committed Nov 8, 2024
1 parent 2451771 commit 3fd07d4
Show file tree
Hide file tree
Showing 20 changed files with 1,196 additions and 31 deletions.
8 changes: 8 additions & 0 deletions clients/js/jito_tip_router/accounts/ncnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ import {
import {
getFeesDecoder,
getFeesEncoder,
getMintEntryDecoder,
getMintEntryEncoder,
type Fees,
type FeesArgs,
type MintEntry,
type MintEntryArgs,
} from '../types';

export type NcnConfig = {
Expand All @@ -47,6 +51,7 @@ export type NcnConfig = {
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: Fees;
mintList: Array<MintEntry>;
bump: number;
reserved: Array<number>;
};
Expand All @@ -57,6 +62,7 @@ export type NcnConfigArgs = {
tieBreakerAdmin: Address;
feeAdmin: Address;
fees: FeesArgs;
mintList: Array<MintEntryArgs>;
bump: number;
reserved: Array<number>;
};
Expand All @@ -68,6 +74,7 @@ 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 @@ -80,6 +87,7 @@ 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
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 @@ -42,6 +42,10 @@ 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
/** ConfigMintsNotUpdated: Config supported mints do not match NCN Vault Count */
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
/** FeeCapExceeded: Fee cap exceeded */
export const JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED = 0x2300; // 8960
/** IncorrectNcnAdmin: Incorrect NCN Admin */
Expand All @@ -55,6 +59,8 @@ 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__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__FEE_CAP_EXCEEDED
Expand All @@ -77,6 +83,8 @@ 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__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__FEE_CAP_EXCEEDED]: `Fee cap exceeded`,
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 @@ -9,5 +9,6 @@
export * from './adminUpdateWeightTable';
export * from './initializeNCNConfig';
export * from './initializeWeightTable';
export * from './registerMint';
export * from './setConfigFees';
export * from './setNewAdmin';
260 changes: 260 additions & 0 deletions clients/js/jito_tip_router/instructions/registerMint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
/**
* 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,
getStructDecoder,
getStructEncoder,
getU8Decoder,
getU8Encoder,
transformEncoder,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type ReadonlyAccount,
type WritableAccount,
} from '@solana/web3.js';
import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const REGISTER_MINT_DISCRIMINATOR = 5;

export function getRegisterMintDiscriminatorBytes() {
return getU8Encoder().encode(REGISTER_MINT_DISCRIMINATOR);
}

export type RegisterMintInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountRestakingConfig extends string | IAccountMeta<string> = string,
TAccountNcnConfig extends string | IAccountMeta<string> = string,
TAccountNcn extends string | IAccountMeta<string> = string,
TAccountVault extends string | IAccountMeta<string> = string,
TAccountVaultNcnTicket extends string | IAccountMeta<string> = string,
TAccountNcnVaultTicket extends string | IAccountMeta<string> = string,
TAccountRestakingProgramId extends string | IAccountMeta<string> = string,
TAccountVaultProgramId extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountRestakingConfig extends string
? ReadonlyAccount<TAccountRestakingConfig>
: TAccountRestakingConfig,
TAccountNcnConfig extends string
? WritableAccount<TAccountNcnConfig>
: TAccountNcnConfig,
TAccountNcn extends string ? ReadonlyAccount<TAccountNcn> : TAccountNcn,
TAccountVault extends string
? ReadonlyAccount<TAccountVault>
: TAccountVault,
TAccountVaultNcnTicket extends string
? ReadonlyAccount<TAccountVaultNcnTicket>
: TAccountVaultNcnTicket,
TAccountNcnVaultTicket extends string
? ReadonlyAccount<TAccountNcnVaultTicket>
: TAccountNcnVaultTicket,
TAccountRestakingProgramId extends string
? ReadonlyAccount<TAccountRestakingProgramId>
: TAccountRestakingProgramId,
TAccountVaultProgramId extends string
? ReadonlyAccount<TAccountVaultProgramId>
: TAccountVaultProgramId,
...TRemainingAccounts,
]
>;

export type RegisterMintInstructionData = { discriminator: number };

export type RegisterMintInstructionDataArgs = {};

export function getRegisterMintInstructionDataEncoder(): Encoder<RegisterMintInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({ ...value, discriminator: REGISTER_MINT_DISCRIMINATOR })
);
}

export function getRegisterMintInstructionDataDecoder(): Decoder<RegisterMintInstructionData> {
return getStructDecoder([['discriminator', getU8Decoder()]]);
}

export function getRegisterMintInstructionDataCodec(): Codec<
RegisterMintInstructionDataArgs,
RegisterMintInstructionData
> {
return combineCodec(
getRegisterMintInstructionDataEncoder(),
getRegisterMintInstructionDataDecoder()
);
}

export type RegisterMintInput<
TAccountRestakingConfig extends string = string,
TAccountNcnConfig extends string = string,
TAccountNcn extends string = string,
TAccountVault extends string = string,
TAccountVaultNcnTicket extends string = string,
TAccountNcnVaultTicket extends string = string,
TAccountRestakingProgramId extends string = string,
TAccountVaultProgramId extends string = string,
> = {
restakingConfig: Address<TAccountRestakingConfig>;
ncnConfig: Address<TAccountNcnConfig>;
ncn: Address<TAccountNcn>;
vault: Address<TAccountVault>;
vaultNcnTicket: Address<TAccountVaultNcnTicket>;
ncnVaultTicket: Address<TAccountNcnVaultTicket>;
restakingProgramId: Address<TAccountRestakingProgramId>;
vaultProgramId: Address<TAccountVaultProgramId>;
};

export function getRegisterMintInstruction<
TAccountRestakingConfig extends string,
TAccountNcnConfig extends string,
TAccountNcn extends string,
TAccountVault extends string,
TAccountVaultNcnTicket extends string,
TAccountNcnVaultTicket extends string,
TAccountRestakingProgramId extends string,
TAccountVaultProgramId extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
input: RegisterMintInput<
TAccountRestakingConfig,
TAccountNcnConfig,
TAccountNcn,
TAccountVault,
TAccountVaultNcnTicket,
TAccountNcnVaultTicket,
TAccountRestakingProgramId,
TAccountVaultProgramId
>,
config?: { programAddress?: TProgramAddress }
): RegisterMintInstruction<
TProgramAddress,
TAccountRestakingConfig,
TAccountNcnConfig,
TAccountNcn,
TAccountVault,
TAccountVaultNcnTicket,
TAccountNcnVaultTicket,
TAccountRestakingProgramId,
TAccountVaultProgramId
> {
// Program address.
const programAddress =
config?.programAddress ?? JITO_TIP_ROUTER_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
restakingConfig: {
value: input.restakingConfig ?? null,
isWritable: false,
},
ncnConfig: { value: input.ncnConfig ?? null, isWritable: true },
ncn: { value: input.ncn ?? null, isWritable: false },
vault: { value: input.vault ?? null, isWritable: false },
vaultNcnTicket: { value: input.vaultNcnTicket ?? null, isWritable: false },
ncnVaultTicket: { value: input.ncnVaultTicket ?? null, isWritable: false },
restakingProgramId: {
value: input.restakingProgramId ?? null,
isWritable: false,
},
vaultProgramId: { value: input.vaultProgramId ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.restakingConfig),
getAccountMeta(accounts.ncnConfig),
getAccountMeta(accounts.ncn),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.vaultNcnTicket),
getAccountMeta(accounts.ncnVaultTicket),
getAccountMeta(accounts.restakingProgramId),
getAccountMeta(accounts.vaultProgramId),
],
programAddress,
data: getRegisterMintInstructionDataEncoder().encode({}),
} as RegisterMintInstruction<
TProgramAddress,
TAccountRestakingConfig,
TAccountNcnConfig,
TAccountNcn,
TAccountVault,
TAccountVaultNcnTicket,
TAccountNcnVaultTicket,
TAccountRestakingProgramId,
TAccountVaultProgramId
>;

return instruction;
}

export type ParsedRegisterMintInstruction<
TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
restakingConfig: TAccountMetas[0];
ncnConfig: TAccountMetas[1];
ncn: TAccountMetas[2];
vault: TAccountMetas[3];
vaultNcnTicket: TAccountMetas[4];
ncnVaultTicket: TAccountMetas[5];
restakingProgramId: TAccountMetas[6];
vaultProgramId: TAccountMetas[7];
};
data: RegisterMintInstructionData;
};

export function parseRegisterMintInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedRegisterMintInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 8) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
accountIndex += 1;
return accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
restakingConfig: getNextAccount(),
ncnConfig: getNextAccount(),
ncn: getNextAccount(),
vault: getNextAccount(),
vaultNcnTicket: getNextAccount(),
ncnVaultTicket: getNextAccount(),
restakingProgramId: getNextAccount(),
vaultProgramId: getNextAccount(),
},
data: getRegisterMintInstructionDataDecoder().decode(instruction.data),
};
}
10 changes: 9 additions & 1 deletion clients/js/jito_tip_router/programs/jitoTipRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type ParsedAdminUpdateWeightTableInstruction,
type ParsedInitializeNCNConfigInstruction,
type ParsedInitializeWeightTableInstruction,
type ParsedRegisterMintInstruction,
type ParsedSetConfigFeesInstruction,
type ParsedSetNewAdminInstruction,
} from '../instructions';
Expand All @@ -34,6 +35,7 @@ export enum JitoTipRouterInstruction {
SetNewAdmin,
InitializeWeightTable,
AdminUpdateWeightTable,
RegisterMint,
}

export function identifyJitoTipRouterInstruction(
Expand All @@ -55,6 +57,9 @@ export function identifyJitoTipRouterInstruction(
if (containsBytes(data, getU8Encoder().encode(4), 0)) {
return JitoTipRouterInstruction.AdminUpdateWeightTable;
}
if (containsBytes(data, getU8Encoder().encode(5), 0)) {
return JitoTipRouterInstruction.RegisterMint;
}
throw new Error(
'The provided instruction could not be identified as a jitoTipRouter instruction.'
);
Expand All @@ -77,4 +82,7 @@ export type ParsedJitoTipRouterInstruction<
} & ParsedInitializeWeightTableInstruction<TProgram>)
| ({
instructionType: JitoTipRouterInstruction.AdminUpdateWeightTable;
} & ParsedAdminUpdateWeightTableInstruction<TProgram>);
} & ParsedAdminUpdateWeightTableInstruction<TProgram>)
| ({
instructionType: JitoTipRouterInstruction.RegisterMint;
} & ParsedRegisterMintInstruction<TProgram>);
1 change: 1 addition & 0 deletions clients/js/jito_tip_router/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
export * from './configAdminRole';
export * from './fee';
export * from './fees';
export * from './mintEntry';
export * from './weightEntry';
Loading

0 comments on commit 3fd07d4

Please sign in to comment.