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

Add CreateReferralLog #18

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
4 changes: 4 additions & 0 deletions bin/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ async fn main() -> Result<(), anyhow::Error> {
let event = bytemuck::from_bytes::<ReferrerWithdrawLog>(&decoded[8..]);
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"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use solana_program::rent::Rent;
use solana_program::system_instruction;
use solana_program::system_program;

use crate::logs::{emit_stack, CreateReferralLog};

pub fn execute_create_referral(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
if let [payer, referrer, vault, mint, system_program, token_program] = accounts {
// verify token program is passed
Expand Down Expand Up @@ -62,6 +64,13 @@ pub fn execute_create_referral(accounts: &[AccountInfo], instruction_data: &[u8]

invoke(&initialize_ix, &initialize_account_infos)?;

emit_stack(CreateReferralLog {
referee: *payer.key,
referer: *referrer.key,
vault: *vault.key,
mint: *mint.key,
})?;

Ok(())
} else {
Err(ProgramError::NotEnoughAccountKeys)
Expand Down
17 changes: 17 additions & 0 deletions programs/autobahn-executor/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,20 @@ pub struct ReferrerWithdrawLog {
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 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 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!(
PlatformFeeLog,
Expand All @@ -106,6 +116,13 @@ discriminant!(
REFERRER_WITHDRAW_LOG_DISCRIMINANT,
test_referrer_withdraw_log
);

discriminant!(
CreateReferralLog,
CREATE_REFERRAL_LOG_DISCRIMINANT,
test_create_referral_log
);

discriminant!(SwapEvent, SWAP_EVENT_DISCRIMINANT, test_swap_event);

/// Canonical discriminant of the given struct. It is the hash of program ID and
Expand Down
Loading