-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for payment proxies (#104)
- Loading branch information
1 parent
45939e1
commit 57a3050
Showing
17 changed files
with
321 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anchor_lang::prelude::{AccountInfo, Pubkey}; | ||
use solana_program::pubkey; | ||
|
||
use crate::state::Pool; | ||
|
||
const PAYMENT_PROXY_PROGRAM_ID: Pubkey = pubkey!("mpxdRTRiAzvxz8dgW6LQYzDATtKQBx2f1VJ6qsU28hn"); | ||
const PAYMENT_PROXY_DISCRIMINATOR: [u8; 8] = [0xee, 0x4a, 0x13, 0x79, 0x5e, 0x99, 0xac, 0x48]; | ||
const PAYMENT_PROXY_MIN_LEN: usize = 512; | ||
|
||
pub fn verify_referral(pool: &Pool, referral: &AccountInfo<'_>) -> bool { | ||
// Check if the referral account is the one defined in the pool | ||
if referral.key == &pool.referral { | ||
// early return true since the referral is the one expected | ||
return true; | ||
} | ||
|
||
// From now on we assume that the referral account is a payment proxy account with the referral | ||
// as the authority. | ||
|
||
// Check if the account is owned by expected program and that it has expected data length | ||
if referral.owner != &PAYMENT_PROXY_PROGRAM_ID || referral.data_len() < PAYMENT_PROXY_MIN_LEN { | ||
return false; | ||
} | ||
|
||
let data = referral.try_borrow_data().unwrap(); | ||
// Check if proxy account has correct discriminator | ||
if data[0..8] != PAYMENT_PROXY_DISCRIMINATOR { | ||
return false; | ||
} | ||
// Check if proxy account has correct authority | ||
if &data[8..40] != pool.referral.as_ref() { | ||
return false; | ||
} | ||
true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pubkey": "AJtUEMcZv9DDG4EVd8ugG3duAnCmmmVa6xCEUV7FqFFd", | ||
"account": { | ||
"lamports": 4454400, | ||
"data": [ | ||
"7koTeV6ZrEiQg0IPEp/Uuttukll5Ybq4Tq0Fyv/p3NtUND3zmVFT1QIAAABpbwAhsbfNghq8fn9TdloaMFqlw+SMn5DN9AMUTEH879PtpgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", | ||
"base64" | ||
], | ||
"owner": "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d", | ||
"executable": false, | ||
"rentEpoch": 18446744073709551615, | ||
"space": 512 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pubkey": "9V5HWD1ap6mCDMhBoXU5SVcZZn9ihqJtoMQZsw5MTnoD", | ||
"account": { | ||
"lamports": 4454400, | ||
"data": [ | ||
"7koTeV6ZrEiQg0IPEp/Uuttukll5Ybq4Tq0Fyv/p3NtUND3zmVFT1QIAAABpbwAhsbfNghq8fn9TdloaMFqlw+SMn5DN9AMUTEH879PtpgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", | ||
"base64" | ||
], | ||
"owner": "mpxdRTRiAzvxz8dgW6LQYzDATtKQBx2f1VJ6qsU28hn", | ||
"executable": false, | ||
"rentEpoch": 18446744073709551615, | ||
"space": 512 | ||
} | ||
} |
Oops, something went wrong.