Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
coachchucksol committed Jan 21, 2025
1 parent 26651f3 commit 722ed89
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 24 deletions.
21 changes: 19 additions & 2 deletions clients/js/jito_tip_router/instructions/claimWithPayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ClaimWithPayerInstruction<
TAccountTipDistributionAccount extends string | IAccountMeta<string> = string,
TAccountClaimStatus extends string | IAccountMeta<string> = string,
TAccountClaimant extends string | IAccountMeta<string> = string,
TAccountTipDistributionProgram extends string | IAccountMeta<string> = string,
TAccountSystemProgram extends
| string
| IAccountMeta<string> = '11111111111111111111111111111111',
Expand Down Expand Up @@ -78,6 +79,9 @@ export type ClaimWithPayerInstruction<
TAccountClaimant extends string
? WritableAccount<TAccountClaimant>
: TAccountClaimant,
TAccountTipDistributionProgram extends string
? ReadonlyAccount<TAccountTipDistributionProgram>
: TAccountTipDistributionProgram,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
: TAccountSystemProgram,
Expand Down Expand Up @@ -137,6 +141,7 @@ export type ClaimWithPayerInput<
TAccountTipDistributionAccount extends string = string,
TAccountClaimStatus extends string = string,
TAccountClaimant extends string = string,
TAccountTipDistributionProgram extends string = string,
TAccountSystemProgram extends string = string,
> = {
accountPayer: Address<TAccountAccountPayer>;
Expand All @@ -146,6 +151,7 @@ export type ClaimWithPayerInput<
tipDistributionAccount: Address<TAccountTipDistributionAccount>;
claimStatus: Address<TAccountClaimStatus>;
claimant: Address<TAccountClaimant>;
tipDistributionProgram: Address<TAccountTipDistributionProgram>;
systemProgram?: Address<TAccountSystemProgram>;
proof: ClaimWithPayerInstructionDataArgs['proof'];
amount: ClaimWithPayerInstructionDataArgs['amount'];
Expand All @@ -160,6 +166,7 @@ export function getClaimWithPayerInstruction<
TAccountTipDistributionAccount extends string,
TAccountClaimStatus extends string,
TAccountClaimant extends string,
TAccountTipDistributionProgram extends string,
TAccountSystemProgram extends string,
TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS,
>(
Expand All @@ -171,6 +178,7 @@ export function getClaimWithPayerInstruction<
TAccountTipDistributionAccount,
TAccountClaimStatus,
TAccountClaimant,
TAccountTipDistributionProgram,
TAccountSystemProgram
>,
config?: { programAddress?: TProgramAddress }
Expand All @@ -183,6 +191,7 @@ export function getClaimWithPayerInstruction<
TAccountTipDistributionAccount,
TAccountClaimStatus,
TAccountClaimant,
TAccountTipDistributionProgram,
TAccountSystemProgram
> {
// Program address.
Expand All @@ -204,6 +213,10 @@ export function getClaimWithPayerInstruction<
},
claimStatus: { value: input.claimStatus ?? null, isWritable: true },
claimant: { value: input.claimant ?? null, isWritable: true },
tipDistributionProgram: {
value: input.tipDistributionProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts as Record<
Expand All @@ -230,6 +243,7 @@ export function getClaimWithPayerInstruction<
getAccountMeta(accounts.tipDistributionAccount),
getAccountMeta(accounts.claimStatus),
getAccountMeta(accounts.claimant),
getAccountMeta(accounts.tipDistributionProgram),
getAccountMeta(accounts.systemProgram),
],
programAddress,
Expand All @@ -245,6 +259,7 @@ export function getClaimWithPayerInstruction<
TAccountTipDistributionAccount,
TAccountClaimStatus,
TAccountClaimant,
TAccountTipDistributionProgram,
TAccountSystemProgram
>;

Expand All @@ -264,7 +279,8 @@ export type ParsedClaimWithPayerInstruction<
tipDistributionAccount: TAccountMetas[4];
claimStatus: TAccountMetas[5];
claimant: TAccountMetas[6];
systemProgram: TAccountMetas[7];
tipDistributionProgram: TAccountMetas[7];
systemProgram: TAccountMetas[8];
};
data: ClaimWithPayerInstructionData;
};
Expand All @@ -277,7 +293,7 @@ export function parseClaimWithPayerInstruction<
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedClaimWithPayerInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 8) {
if (instruction.accounts.length < 9) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
Expand All @@ -297,6 +313,7 @@ export function parseClaimWithPayerInstruction<
tipDistributionAccount: getNextAccount(),
claimStatus: getNextAccount(),
claimant: getNextAccount(),
tipDistributionProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getClaimWithPayerInstructionDataDecoder().decode(instruction.data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct ClaimWithPayer {

pub claimant: solana_program::pubkey::Pubkey,

pub tip_distribution_program: solana_program::pubkey::Pubkey,

pub system_program: solana_program::pubkey::Pubkey,
}

Expand All @@ -40,7 +42,7 @@ impl ClaimWithPayer {
args: ClaimWithPayerInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.account_payer,
false,
Expand Down Expand Up @@ -68,6 +70,10 @@ impl ClaimWithPayer {
self.claimant,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.tip_distribution_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
Expand Down Expand Up @@ -121,7 +127,8 @@ pub struct ClaimWithPayerInstructionArgs {
/// 4. `[writable]` tip_distribution_account
/// 5. `[writable]` claim_status
/// 6. `[writable]` claimant
/// 7. `[optional]` system_program (default to `11111111111111111111111111111111`)
/// 7. `[]` tip_distribution_program
/// 8. `[optional]` system_program (default to `11111111111111111111111111111111`)
#[derive(Clone, Debug, Default)]
pub struct ClaimWithPayerBuilder {
account_payer: Option<solana_program::pubkey::Pubkey>,
Expand All @@ -131,6 +138,7 @@ pub struct ClaimWithPayerBuilder {
tip_distribution_account: Option<solana_program::pubkey::Pubkey>,
claim_status: Option<solana_program::pubkey::Pubkey>,
claimant: Option<solana_program::pubkey::Pubkey>,
tip_distribution_program: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
proof: Option<Vec<[u8; 32]>>,
amount: Option<u64>,
Expand Down Expand Up @@ -183,6 +191,14 @@ impl ClaimWithPayerBuilder {
self.claimant = Some(claimant);
self
}
#[inline(always)]
pub fn tip_distribution_program(
&mut self,
tip_distribution_program: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.tip_distribution_program = Some(tip_distribution_program);
self
}
/// `[optional account, default to '11111111111111111111111111111111']`
#[inline(always)]
pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
Expand Down Expand Up @@ -236,6 +252,9 @@ impl ClaimWithPayerBuilder {
.expect("tip_distribution_account is not set"),
claim_status: self.claim_status.expect("claim_status is not set"),
claimant: self.claimant.expect("claimant is not set"),
tip_distribution_program: self
.tip_distribution_program
.expect("tip_distribution_program is not set"),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
Expand Down Expand Up @@ -266,6 +285,8 @@ pub struct ClaimWithPayerCpiAccounts<'a, 'b> {

pub claimant: &'b solana_program::account_info::AccountInfo<'a>,

pub tip_distribution_program: &'b solana_program::account_info::AccountInfo<'a>,

pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}

Expand All @@ -288,6 +309,8 @@ pub struct ClaimWithPayerCpi<'a, 'b> {

pub claimant: &'b solana_program::account_info::AccountInfo<'a>,

pub tip_distribution_program: &'b solana_program::account_info::AccountInfo<'a>,

pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
/// The arguments for the instruction.
pub __args: ClaimWithPayerInstructionArgs,
Expand All @@ -308,6 +331,7 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
tip_distribution_account: accounts.tip_distribution_account,
claim_status: accounts.claim_status,
claimant: accounts.claimant,
tip_distribution_program: accounts.tip_distribution_program,
system_program: accounts.system_program,
__args: args,
}
Expand Down Expand Up @@ -345,7 +369,7 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(8 + remaining_accounts.len());
let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.account_payer.key,
false,
Expand Down Expand Up @@ -374,6 +398,10 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
*self.claimant.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.tip_distribution_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
Expand All @@ -394,7 +422,7 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(8 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(9 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.account_payer.clone());
account_infos.push(self.config.clone());
Expand All @@ -403,6 +431,7 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
account_infos.push(self.tip_distribution_account.clone());
account_infos.push(self.claim_status.clone());
account_infos.push(self.claimant.clone());
account_infos.push(self.tip_distribution_program.clone());
account_infos.push(self.system_program.clone());
remaining_accounts
.iter()
Expand All @@ -427,7 +456,8 @@ impl<'a, 'b> ClaimWithPayerCpi<'a, 'b> {
/// 4. `[writable]` tip_distribution_account
/// 5. `[writable]` claim_status
/// 6. `[writable]` claimant
/// 7. `[]` system_program
/// 7. `[]` tip_distribution_program
/// 8. `[]` system_program
#[derive(Clone, Debug)]
pub struct ClaimWithPayerCpiBuilder<'a, 'b> {
instruction: Box<ClaimWithPayerCpiBuilderInstruction<'a, 'b>>,
Expand All @@ -444,6 +474,7 @@ impl<'a, 'b> ClaimWithPayerCpiBuilder<'a, 'b> {
tip_distribution_account: None,
claim_status: None,
claimant: None,
tip_distribution_program: None,
system_program: None,
proof: None,
amount: None,
Expand Down Expand Up @@ -506,6 +537,14 @@ impl<'a, 'b> ClaimWithPayerCpiBuilder<'a, 'b> {
self
}
#[inline(always)]
pub fn tip_distribution_program(
&mut self,
tip_distribution_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.tip_distribution_program = Some(tip_distribution_program);
self
}
#[inline(always)]
pub fn system_program(
&mut self,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
Expand Down Expand Up @@ -603,6 +642,11 @@ impl<'a, 'b> ClaimWithPayerCpiBuilder<'a, 'b> {

claimant: self.instruction.claimant.expect("claimant is not set"),

tip_distribution_program: self
.instruction
.tip_distribution_program
.expect("tip_distribution_program is not set"),

system_program: self
.instruction
.system_program
Expand All @@ -626,6 +670,7 @@ struct ClaimWithPayerCpiBuilderInstruction<'a, 'b> {
tip_distribution_account: Option<&'b solana_program::account_info::AccountInfo<'a>>,
claim_status: Option<&'b solana_program::account_info::AccountInfo<'a>>,
claimant: Option<&'b solana_program::account_info::AccountInfo<'a>>,
tip_distribution_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
proof: Option<Vec<[u8; 32]>>,
amount: Option<u64>,
Expand Down
3 changes: 2 additions & 1 deletion core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ pub enum TipRouterInstruction {
#[account(4, writable, name = "tip_distribution_account")]
#[account(5, writable, name = "claim_status")]
#[account(6, writable, name = "claimant")]
#[account(7, name = "system_program")]
#[account(7, name = "tip_distribution_program")]
#[account(8, name = "system_program")]
ClaimWithPayer {
proof: Vec<[u8; 32]>,
amount: u64,
Expand Down
5 changes: 5 additions & 0 deletions idl/jito_tip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@
"isMut": true,
"isSigner": false
},
{
"name": "tipDistributionProgram",
"isMut": false,
"isSigner": false
},
{
"name": "systemProgram",
"isMut": false,
Expand Down
Loading

0 comments on commit 722ed89

Please sign in to comment.