Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Don't merge]: force overwrite program fee wallet #166

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cli/src/vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum ConfigActions {
/// The new admin's pubkey
new_admin: Pubkey,
},
/// Set the config program fee wallet
SetProgramFeeWallet,
}

/// Vault commands
Expand Down
35 changes: 34 additions & 1 deletion cli/src/vault_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use jito_vault_client::{
CooldownDelegationBuilder, CrankVaultUpdateStateTrackerBuilder, CreateTokenMetadataBuilder,
EnqueueWithdrawalBuilder, InitializeConfigBuilder, InitializeVaultBuilder,
InitializeVaultOperatorDelegationBuilder, InitializeVaultUpdateStateTrackerBuilder,
MintToBuilder, SetConfigAdminBuilder, SetDepositCapacityBuilder,
MintToBuilder, SetConfigAdminBuilder, SetConfigProgramFeeWalletBuilder,
SetDepositCapacityBuilder,
},
types::WithdrawalAllocationMethod,
};
Expand Down Expand Up @@ -81,6 +82,9 @@ impl VaultCliHandler {
VaultCommands::Config {
action: ConfigActions::SetAdmin { new_admin },
} => self.set_config_admin(new_admin).await,
VaultCommands::Config {
action: ConfigActions::SetProgramFeeWallet,
} => self.set_config_program_fee_wallet().await,
VaultCommands::Vault {
action:
VaultActions::Initialize {
Expand Down Expand Up @@ -1117,4 +1121,33 @@ impl VaultCliHandler {
info!("Transaction confirmed: {:?}", tx.get_signature());
Ok(())
}

async fn set_config_program_fee_wallet(&self) -> Result<()> {
let keypair = self
.cli_config
.keypair
.as_ref()
.ok_or_else(|| anyhow!("Keypair not provided"))?;
let rpc_client = self.get_rpc_client();

let config_address = Config::find_program_address(&self.vault_program_id).0;
let mut ix_builder = SetConfigProgramFeeWalletBuilder::new();
ix_builder.config(config_address);

let blockhash = rpc_client.get_latest_blockhash().await?;
let tx = Transaction::new_signed_with_payer(
&[ix_builder.instruction()],
Some(&keypair.pubkey()),
&[keypair],
blockhash,
);

info!(
"Setting config program fee wallet transaction: {:?}",
tx.get_signature()
);
rpc_client.send_and_confirm_transaction(&tx).await?;
info!("Transaction confirmed: {:?}", tx.get_signature());
Ok(())
}
}
1 change: 1 addition & 0 deletions clients/js/vault_client/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './initializeVaultWithMint';
export * from './mintTo';
export * from './setAdmin';
export * from './setConfigAdmin';
export * from './setConfigProgramFeeWallet';
export * from './setDepositCapacity';
export * from './setFees';
export * from './setIsPaused';
Expand Down
157 changes: 157 additions & 0 deletions clients/js/vault_client/instructions/setConfigProgramFeeWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* 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 WritableAccount,
} from '@solana/web3.js';
import { JITO_VAULT_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const SET_CONFIG_PROGRAM_FEE_WALLET_DISCRIMINATOR = 32;

export function getSetConfigProgramFeeWalletDiscriminatorBytes() {
return getU8Encoder().encode(SET_CONFIG_PROGRAM_FEE_WALLET_DISCRIMINATOR);
}

export type SetConfigProgramFeeWalletInstruction<
TProgram extends string = typeof JITO_VAULT_PROGRAM_ADDRESS,
TAccountConfig extends string | IAccountMeta<string> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountConfig extends string
? WritableAccount<TAccountConfig>
: TAccountConfig,
...TRemainingAccounts,
]
>;

export type SetConfigProgramFeeWalletInstructionData = {
discriminator: number;
};

export type SetConfigProgramFeeWalletInstructionDataArgs = {};

export function getSetConfigProgramFeeWalletInstructionDataEncoder(): Encoder<SetConfigProgramFeeWalletInstructionDataArgs> {
return transformEncoder(
getStructEncoder([['discriminator', getU8Encoder()]]),
(value) => ({
...value,
discriminator: SET_CONFIG_PROGRAM_FEE_WALLET_DISCRIMINATOR,
})
);
}

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

export function getSetConfigProgramFeeWalletInstructionDataCodec(): Codec<
SetConfigProgramFeeWalletInstructionDataArgs,
SetConfigProgramFeeWalletInstructionData
> {
return combineCodec(
getSetConfigProgramFeeWalletInstructionDataEncoder(),
getSetConfigProgramFeeWalletInstructionDataDecoder()
);
}

export type SetConfigProgramFeeWalletInput<
TAccountConfig extends string = string,
> = {
config: Address<TAccountConfig>;
};

export function getSetConfigProgramFeeWalletInstruction<
TAccountConfig extends string,
>(
input: SetConfigProgramFeeWalletInput<TAccountConfig>
): SetConfigProgramFeeWalletInstruction<
typeof JITO_VAULT_PROGRAM_ADDRESS,
TAccountConfig
> {
// Program address.
const programAddress = JITO_VAULT_PROGRAM_ADDRESS;

// Original accounts.
const originalAccounts = {
config: { value: input.config ?? null, isWritable: true },
};
const accounts = originalAccounts as Record<
keyof typeof originalAccounts,
ResolvedAccount
>;

const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.config)],
programAddress,
data: getSetConfigProgramFeeWalletInstructionDataEncoder().encode({}),
} as SetConfigProgramFeeWalletInstruction<
typeof JITO_VAULT_PROGRAM_ADDRESS,
TAccountConfig
>;

return instruction;
}

export type ParsedSetConfigProgramFeeWalletInstruction<
TProgram extends string = typeof JITO_VAULT_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
config: TAccountMetas[0];
};
data: SetConfigProgramFeeWalletInstructionData;
};

export function parseSetConfigProgramFeeWalletInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedSetConfigProgramFeeWalletInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 1) {
// 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(),
},
data: getSetConfigProgramFeeWalletInstructionDataDecoder().decode(
instruction.data
),
};
}
10 changes: 9 additions & 1 deletion clients/js/vault_client/programs/jitoVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type ParsedMintToInstruction,
type ParsedSetAdminInstruction,
type ParsedSetConfigAdminInstruction,
type ParsedSetConfigProgramFeeWalletInstruction,
type ParsedSetDepositCapacityInstruction,
type ParsedSetFeesInstruction,
type ParsedSetIsPausedInstruction,
Expand Down Expand Up @@ -94,6 +95,7 @@ export enum JitoVaultInstruction {
CreateTokenMetadata,
UpdateTokenMetadata,
SetConfigAdmin,
SetConfigProgramFeeWallet,
}

export function identifyJitoVaultInstruction(
Expand Down Expand Up @@ -196,6 +198,9 @@ export function identifyJitoVaultInstruction(
if (containsBytes(data, getU8Encoder().encode(31), 0)) {
return JitoVaultInstruction.SetConfigAdmin;
}
if (containsBytes(data, getU8Encoder().encode(32), 0)) {
return JitoVaultInstruction.SetConfigProgramFeeWallet;
}
throw new Error(
'The provided instruction could not be identified as a jitoVault instruction.'
);
Expand Down Expand Up @@ -299,4 +304,7 @@ export type ParsedJitoVaultInstruction<
} & ParsedUpdateTokenMetadataInstruction<TProgram>)
| ({
instructionType: JitoVaultInstruction.SetConfigAdmin;
} & ParsedSetConfigAdminInstruction<TProgram>);
} & ParsedSetConfigAdminInstruction<TProgram>)
| ({
instructionType: JitoVaultInstruction.SetConfigProgramFeeWallet;
} & ParsedSetConfigProgramFeeWalletInstruction<TProgram>);
9 changes: 5 additions & 4 deletions clients/rust/vault_client/src/generated/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) mod r#initialize_vault_with_mint;
pub(crate) mod r#mint_to;
pub(crate) mod r#set_admin;
pub(crate) mod r#set_config_admin;
pub(crate) mod r#set_config_program_fee_wallet;
pub(crate) mod r#set_deposit_capacity;
pub(crate) mod r#set_fees;
pub(crate) mod r#set_is_paused;
Expand All @@ -46,8 +47,8 @@ pub use self::{
r#initialize_vault_ncn_slasher_operator_ticket::*, r#initialize_vault_ncn_slasher_ticket::*,
r#initialize_vault_ncn_ticket::*, r#initialize_vault_operator_delegation::*,
r#initialize_vault_update_state_tracker::*, r#initialize_vault_with_mint::*, r#mint_to::*,
r#set_admin::*, r#set_config_admin::*, r#set_deposit_capacity::*, r#set_fees::*,
r#set_is_paused::*, r#set_program_fee::*, r#set_program_fee_wallet::*,
r#set_secondary_admin::*, r#update_token_metadata::*, r#update_vault_balance::*,
r#warmup_vault_ncn_slasher_ticket::*, r#warmup_vault_ncn_ticket::*,
r#set_admin::*, r#set_config_admin::*, r#set_config_program_fee_wallet::*,
r#set_deposit_capacity::*, r#set_fees::*, r#set_is_paused::*, r#set_program_fee::*,
r#set_program_fee_wallet::*, r#set_secondary_admin::*, r#update_token_metadata::*,
r#update_vault_balance::*, r#warmup_vault_ncn_slasher_ticket::*, r#warmup_vault_ncn_ticket::*,
};
Loading
Loading