Skip to content

Commit

Permalink
use const for deposit fee
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Dec 2, 2024
1 parent e7482ce commit af5caec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions programs/protocol-contracts-solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ declare_id!("ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis");
pub mod gateway {
use super::*;

const DEPOSIT_FEE: u64 = 2_000_000;

pub fn initialize(
ctx: Context<Initialize>,
tss_address: [u8; 20],
Expand Down Expand Up @@ -182,8 +184,7 @@ pub mod gateway {
require!(!pda.deposit_paused, Errors::DepositPaused);
require!(receiver != [0u8; 20], Errors::EmptyReceiver);

let deposit_fee = 2_000_000;
let amount_with_fees = amount + deposit_fee;
let amount_with_fees = amount + DEPOSIT_FEE;
let cpi_context = CpiContext::new(
ctx.accounts.system_program.to_account_info(),
system_program::Transfer {
Expand All @@ -196,7 +197,7 @@ pub mod gateway {
"{:?} deposits {:?} lamports to PDA with fee {:?}; receiver {:?}",
ctx.accounts.signer.key(),
amount,
deposit_fee,
DEPOSIT_FEE,
receiver,
);

Expand Down Expand Up @@ -236,15 +237,14 @@ pub mod gateway {
require!(receiver != [0u8; 20], Errors::EmptyReceiver);

// transfer deposit_fee
let deposit_fee = 2_000_000;
let cpi_context = CpiContext::new(
ctx.accounts.system_program.to_account_info(),
system_program::Transfer {
from: ctx.accounts.signer.to_account_info().clone(),
to: pda.to_account_info().clone(),
},
);
system_program::transfer(cpi_context, deposit_fee)?;
system_program::transfer(cpi_context, DEPOSIT_FEE)?;

let pda_ata = get_associated_token_address(&ctx.accounts.pda.key(), &from.mint);
// must deposit to the ATA from PDA in order to receive credit
Expand Down

0 comments on commit af5caec

Please sign in to comment.