add CreateReferralLog (#18)
This commit is contained in:
parent
1bf5e6e2b6
commit
f9e8f8bf7c
|
@ -166,6 +166,10 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
let event = bytemuck::from_bytes::<ReferrerWithdrawLog>(&decoded[8..]);
|
let event = bytemuck::from_bytes::<ReferrerWithdrawLog>(&decoded[8..]);
|
||||||
println!("ReferrerWithdrawLog - referer: {:?}, referer_token_account: {:?}, amount: {}", event.referer, event.referer_token_account, event.amount);
|
println!("ReferrerWithdrawLog - referer: {:?}, referer_token_account: {:?}, amount: {}", event.referer, event.referer_token_account, event.amount);
|
||||||
}
|
}
|
||||||
|
&CREATE_REFERRAL_LOG_DISCRIMINANT => {
|
||||||
|
let event = bytemuck::from_bytes::<CreateReferralLog>(&decoded[8..]);
|
||||||
|
println!("CreateReferralLog - referer: {:?}, referee: {:?}, vault: {:?}, mint: {:?}", event.referer, event.referee, event.vault, event.mint);
|
||||||
|
}
|
||||||
_ => panic!("Unknown log discriminant"),
|
_ => panic!("Unknown log discriminant"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ use solana_program::sysvar::Sysvar;
|
||||||
|
|
||||||
use crate::create_pda::create_pda_account;
|
use crate::create_pda::create_pda_account;
|
||||||
|
|
||||||
|
use crate::logs::{emit_stack, CreateReferralLog};
|
||||||
|
|
||||||
pub fn execute_create_referral(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
|
pub fn execute_create_referral(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
|
||||||
if let [payer, referrer, vault, mint, system_program, token_program] = accounts {
|
if let [payer, referrer, vault, mint, system_program, token_program] = accounts {
|
||||||
// verify token program is passed
|
// verify token program is passed
|
||||||
|
@ -56,6 +58,13 @@ pub fn execute_create_referral(accounts: &[AccountInfo], instruction_data: &[u8]
|
||||||
let initialize_account_infos = [vault.clone(), mint.clone(), token_program.clone()];
|
let initialize_account_infos = [vault.clone(), mint.clone(), token_program.clone()];
|
||||||
invoke(&initialize_ix, &initialize_account_infos)?;
|
invoke(&initialize_ix, &initialize_account_infos)?;
|
||||||
|
|
||||||
|
emit_stack(CreateReferralLog {
|
||||||
|
referee: *payer.key,
|
||||||
|
referer: *referrer.key,
|
||||||
|
vault: *vault.key,
|
||||||
|
mint: *mint.key,
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(ProgramError::NotEnoughAccountKeys)
|
Err(ProgramError::NotEnoughAccountKeys)
|
||||||
|
|
|
@ -84,10 +84,20 @@ pub struct ReferrerWithdrawLog {
|
||||||
pub amount: u64,
|
pub amount: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy, Zeroable, Pod)]
|
||||||
|
pub struct CreateReferralLog {
|
||||||
|
pub referee: Pubkey,
|
||||||
|
pub referer: Pubkey,
|
||||||
|
pub vault: Pubkey,
|
||||||
|
pub mint: Pubkey,
|
||||||
|
}
|
||||||
|
|
||||||
pub const PLATFORM_FEE_LOG_DISCRIMINANT: [u8; 8] = [160, 183, 104, 34, 255, 190, 119, 188];
|
pub const PLATFORM_FEE_LOG_DISCRIMINANT: [u8; 8] = [160, 183, 104, 34, 255, 190, 119, 188];
|
||||||
pub const REFERRER_FEE_LOG_DISCRIMINANT: [u8; 8] = [198, 149, 221, 27, 28, 103, 76, 95];
|
pub const REFERRER_FEE_LOG_DISCRIMINANT: [u8; 8] = [198, 149, 221, 27, 28, 103, 76, 95];
|
||||||
pub const REFERRER_WITHDRAW_LOG_DISCRIMINANT: [u8; 8] = [25, 7, 239, 41, 67, 36, 141, 92];
|
pub const REFERRER_WITHDRAW_LOG_DISCRIMINANT: [u8; 8] = [25, 7, 239, 41, 67, 36, 141, 92];
|
||||||
pub const SWAP_EVENT_DISCRIMINANT: [u8; 8] = [56, 178, 48, 245, 42, 152, 27, 75];
|
pub const SWAP_EVENT_DISCRIMINANT: [u8; 8] = [56, 178, 48, 245, 42, 152, 27, 75];
|
||||||
|
pub const CREATE_REFERRAL_LOG_DISCRIMINANT: [u8; 8] = [114, 188, 157, 65, 100, 179, 129, 169];
|
||||||
|
|
||||||
discriminant!(
|
discriminant!(
|
||||||
PlatformFeeLog,
|
PlatformFeeLog,
|
||||||
|
@ -106,6 +116,13 @@ discriminant!(
|
||||||
REFERRER_WITHDRAW_LOG_DISCRIMINANT,
|
REFERRER_WITHDRAW_LOG_DISCRIMINANT,
|
||||||
test_referrer_withdraw_log
|
test_referrer_withdraw_log
|
||||||
);
|
);
|
||||||
|
|
||||||
|
discriminant!(
|
||||||
|
CreateReferralLog,
|
||||||
|
CREATE_REFERRAL_LOG_DISCRIMINANT,
|
||||||
|
test_create_referral_log
|
||||||
|
);
|
||||||
|
|
||||||
discriminant!(SwapEvent, SWAP_EVENT_DISCRIMINANT, test_swap_event);
|
discriminant!(SwapEvent, SWAP_EVENT_DISCRIMINANT, test_swap_event);
|
||||||
|
|
||||||
/// Canonical discriminant of the given struct. It is the hash of program ID and
|
/// Canonical discriminant of the given struct. It is the hash of program ID and
|
||||||
|
|
Loading…
Reference in New Issue