From a17ba77572132fc9f188e7916ff820abc24d4006 Mon Sep 17 00:00:00 2001 From: Noah Prince Date: Wed, 19 Feb 2025 20:21:38 -0800 Subject: [PATCH] Make it so queue authority pays the rent for the task if it has it --- ...queue_relinquish_expired_vote_marker_v0.rs | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/anchor-30-programs/programs/hpl-crons/src/instructions/queue_relinquish_expired_vote_marker_v0.rs b/anchor-30-programs/programs/hpl-crons/src/instructions/queue_relinquish_expired_vote_marker_v0.rs index 6dfdea3e8..1938fb0a6 100644 --- a/anchor-30-programs/programs/hpl-crons/src/instructions/queue_relinquish_expired_vote_marker_v0.rs +++ b/anchor-30-programs/programs/hpl-crons/src/instructions/queue_relinquish_expired_vote_marker_v0.rs @@ -1,4 +1,8 @@ -use anchor_lang::{prelude::*, system_program, InstructionData}; +use anchor_lang::{ + prelude::*, + system_program::{self, transfer, Transfer}, + InstructionData, +}; use spl_token::solana_program::instruction::Instruction; use tuktuk_program::{ compile_transaction, @@ -7,7 +11,7 @@ use tuktuk_program::{ program::Tuktuk, }, types::QueueTaskArgsV0, - TaskQueueV0, TransactionSourceV0, TriggerV0, + TaskQueueV0, TaskV0, TransactionSourceV0, TriggerV0, }; use crate::voter_stake_registry::{ @@ -33,6 +37,7 @@ pub struct QueueRelinquishExpiredVoteMarkerV0<'info> { pub position: Box>, /// CHECK: Via seeds #[account( + mut, seeds = [b"queue_authority"], bump, )] @@ -68,11 +73,31 @@ pub fn handler( ) .unwrap(); + // Queue authority pays for the task rent if it can, since we know it'll come back + // This makes voting cheaper for users. + let mut payer = ctx.accounts.payer.to_account_info(); + let description = "relinquish expired vote marker".to_string(); + let len = 8 + std::mem::size_of::() + 60 + description.len(); + let rent_needed = Rent::get()?.minimum_balance(len); + if ctx.accounts.queue_authority.lamports() > rent_needed { + payer = ctx.accounts.queue_authority.to_account_info(); + transfer( + CpiContext::new_with_signer( + ctx.accounts.system_program.to_account_info(), + Transfer { + from: ctx.accounts.payer.to_account_info(), + to: ctx.accounts.queue_authority.to_account_info(), + }, + &[&["queue_authority".as_bytes(), &[ctx.bumps.queue_authority]]], + ), + ctx.accounts.task_queue.min_crank_reward, + )?; + } queue_task_v0( CpiContext::new_with_signer( ctx.accounts.tuktuk_program.to_account_info(), QueueTaskV0 { - payer: ctx.accounts.payer.to_account_info(), + payer, queue_authority: ctx.accounts.queue_authority.to_account_info(), task_queue: ctx.accounts.task_queue.to_account_info(), task_queue_authority: ctx.accounts.task_queue.to_account_info(), @@ -87,7 +112,7 @@ pub fn handler( crank_reward: None, free_tasks: 0, id: args.free_task_id, - description: "relinquish expired vote marker".to_string(), + description, }, )?;