-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,196 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
260 changes: 260 additions & 0 deletions
260
clients/js/jito_tip_router/instructions/registerMint.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.