-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set admin for config, in restaking and vault (#152)
Co-authored-by: Coach Chuck <[email protected]>
- Loading branch information
1 parent
8073a8b
commit 60b3884
Showing
38 changed files
with
1,527 additions
and
38 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
183 changes: 183 additions & 0 deletions
183
clients/js/restaking_client/instructions/setConfigAdmin.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,183 @@ | ||
/** | ||
* 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 IAccountSignerMeta, | ||
type IInstruction, | ||
type IInstructionWithAccounts, | ||
type IInstructionWithData, | ||
type ReadonlySignerAccount, | ||
type TransactionSigner, | ||
type WritableAccount, | ||
} from '@solana/web3.js'; | ||
import { JITO_RESTAKING_PROGRAM_ADDRESS } from '../programs'; | ||
import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; | ||
|
||
export const SET_CONFIG_ADMIN_DISCRIMINATOR = 24; | ||
|
||
export function getSetConfigAdminDiscriminatorBytes() { | ||
return getU8Encoder().encode(SET_CONFIG_ADMIN_DISCRIMINATOR); | ||
} | ||
|
||
export type SetConfigAdminInstruction< | ||
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS, | ||
TAccountConfig extends string | IAccountMeta<string> = string, | ||
TAccountOldAdmin extends string | IAccountMeta<string> = string, | ||
TAccountNewAdmin extends string | IAccountMeta<string> = string, | ||
TRemainingAccounts extends readonly IAccountMeta<string>[] = [], | ||
> = IInstruction<TProgram> & | ||
IInstructionWithData<Uint8Array> & | ||
IInstructionWithAccounts< | ||
[ | ||
TAccountConfig extends string | ||
? WritableAccount<TAccountConfig> | ||
: TAccountConfig, | ||
TAccountOldAdmin extends string | ||
? ReadonlySignerAccount<TAccountOldAdmin> & | ||
IAccountSignerMeta<TAccountOldAdmin> | ||
: TAccountOldAdmin, | ||
TAccountNewAdmin extends string | ||
? ReadonlySignerAccount<TAccountNewAdmin> & | ||
IAccountSignerMeta<TAccountNewAdmin> | ||
: TAccountNewAdmin, | ||
...TRemainingAccounts, | ||
] | ||
>; | ||
|
||
export type SetConfigAdminInstructionData = { discriminator: number }; | ||
|
||
export type SetConfigAdminInstructionDataArgs = {}; | ||
|
||
export function getSetConfigAdminInstructionDataEncoder(): Encoder<SetConfigAdminInstructionDataArgs> { | ||
return transformEncoder( | ||
getStructEncoder([['discriminator', getU8Encoder()]]), | ||
(value) => ({ ...value, discriminator: SET_CONFIG_ADMIN_DISCRIMINATOR }) | ||
); | ||
} | ||
|
||
export function getSetConfigAdminInstructionDataDecoder(): Decoder<SetConfigAdminInstructionData> { | ||
return getStructDecoder([['discriminator', getU8Decoder()]]); | ||
} | ||
|
||
export function getSetConfigAdminInstructionDataCodec(): Codec< | ||
SetConfigAdminInstructionDataArgs, | ||
SetConfigAdminInstructionData | ||
> { | ||
return combineCodec( | ||
getSetConfigAdminInstructionDataEncoder(), | ||
getSetConfigAdminInstructionDataDecoder() | ||
); | ||
} | ||
|
||
export type SetConfigAdminInput< | ||
TAccountConfig extends string = string, | ||
TAccountOldAdmin extends string = string, | ||
TAccountNewAdmin extends string = string, | ||
> = { | ||
config: Address<TAccountConfig>; | ||
oldAdmin: TransactionSigner<TAccountOldAdmin>; | ||
newAdmin: TransactionSigner<TAccountNewAdmin>; | ||
}; | ||
|
||
export function getSetConfigAdminInstruction< | ||
TAccountConfig extends string, | ||
TAccountOldAdmin extends string, | ||
TAccountNewAdmin extends string, | ||
>( | ||
input: SetConfigAdminInput<TAccountConfig, TAccountOldAdmin, TAccountNewAdmin> | ||
): SetConfigAdminInstruction< | ||
typeof JITO_RESTAKING_PROGRAM_ADDRESS, | ||
TAccountConfig, | ||
TAccountOldAdmin, | ||
TAccountNewAdmin | ||
> { | ||
// Program address. | ||
const programAddress = JITO_RESTAKING_PROGRAM_ADDRESS; | ||
|
||
// Original accounts. | ||
const originalAccounts = { | ||
config: { value: input.config ?? null, isWritable: true }, | ||
oldAdmin: { value: input.oldAdmin ?? null, isWritable: false }, | ||
newAdmin: { value: input.newAdmin ?? null, isWritable: false }, | ||
}; | ||
const accounts = originalAccounts as Record< | ||
keyof typeof originalAccounts, | ||
ResolvedAccount | ||
>; | ||
|
||
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); | ||
const instruction = { | ||
accounts: [ | ||
getAccountMeta(accounts.config), | ||
getAccountMeta(accounts.oldAdmin), | ||
getAccountMeta(accounts.newAdmin), | ||
], | ||
programAddress, | ||
data: getSetConfigAdminInstructionDataEncoder().encode({}), | ||
} as SetConfigAdminInstruction< | ||
typeof JITO_RESTAKING_PROGRAM_ADDRESS, | ||
TAccountConfig, | ||
TAccountOldAdmin, | ||
TAccountNewAdmin | ||
>; | ||
|
||
return instruction; | ||
} | ||
|
||
export type ParsedSetConfigAdminInstruction< | ||
TProgram extends string = typeof JITO_RESTAKING_PROGRAM_ADDRESS, | ||
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], | ||
> = { | ||
programAddress: Address<TProgram>; | ||
accounts: { | ||
config: TAccountMetas[0]; | ||
oldAdmin: TAccountMetas[1]; | ||
newAdmin: TAccountMetas[2]; | ||
}; | ||
data: SetConfigAdminInstructionData; | ||
}; | ||
|
||
export function parseSetConfigAdminInstruction< | ||
TProgram extends string, | ||
TAccountMetas extends readonly IAccountMeta[], | ||
>( | ||
instruction: IInstruction<TProgram> & | ||
IInstructionWithAccounts<TAccountMetas> & | ||
IInstructionWithData<Uint8Array> | ||
): ParsedSetConfigAdminInstruction<TProgram, TAccountMetas> { | ||
if (instruction.accounts.length < 3) { | ||
// 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: { | ||
config: getNextAccount(), | ||
oldAdmin: getNextAccount(), | ||
newAdmin: getNextAccount(), | ||
}, | ||
data: getSetConfigAdminInstructionDataDecoder().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
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.