-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add authorized clmm and its pool state
- Loading branch information
1 parent
37df837
commit a026584
Showing
12 changed files
with
1,544 additions
and
1,308 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
members = [ | ||
"programs/*" | ||
] | ||
resolver = "2" | ||
|
||
[profile.release] | ||
overflow-checks = 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
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,36 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::states::{AuthorizedClmm, DonationProtocolData, DISCRIMINATOR_LEN}; | ||
|
||
pub const AUTHORIZED_CLMM_PREFIX: &str = "authorized_clmm"; | ||
|
||
#[derive(Accounts)] | ||
pub struct AuthorizeClmm<'info> { | ||
#[account(init, payer = payer, space = DISCRIMINATOR_LEN + AuthorizedClmm::INIT_SPACE, | ||
seeds = [ | ||
AUTHORIZED_CLMM_PREFIX.as_bytes(), | ||
donation_protocol.to_account_info().key.as_ref(), | ||
clmm_program_id.key.as_ref(), | ||
], | ||
bump, | ||
)] | ||
pub authorized_clmm: Account<'info, AuthorizedClmm>, | ||
#[account( | ||
constraint = donation_protocol.authority == payer.key(), | ||
)] | ||
pub donation_protocol: Account<'info, DonationProtocolData>, | ||
/// CHECK: Program address of CLMM, TODO: implement with Interface | ||
pub clmm_program_id: AccountInfo<'info>, | ||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
pub rent: Sysvar<'info, Rent>, | ||
} | ||
|
||
pub fn authorize_clmm(ctx: Context<AuthorizeClmm>) -> Result<()> { | ||
let authorized_clmm = &mut ctx.accounts.authorized_clmm; | ||
authorized_clmm.program_id = ctx.accounts.clmm_program_id.key(); | ||
authorized_clmm.donation_protocol = ctx.accounts.donation_protocol.key(); | ||
|
||
Ok(()) | ||
} |
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,53 @@ | ||
use anchor_lang::prelude::*; | ||
use anchor_spl::token::Mint; | ||
use raydium_amm_v3::states::{AmmConfig, PoolState, POOL_SEED}; | ||
|
||
use crate::states::{AuthorizedClmm, AuthorizedPool, DonationProtocolData, DISCRIMINATOR_LEN}; | ||
|
||
pub const AUTHORIZED_POOL_PREFIX: &str = "authorized_pool"; | ||
|
||
#[derive(Accounts)] | ||
pub struct AuthorizePool<'info> { | ||
#[account(init, payer = payer, space = DISCRIMINATOR_LEN + AuthorizedPool::INIT_SPACE, | ||
seeds = [ | ||
AUTHORIZED_POOL_PREFIX.as_bytes(), | ||
donation_protocol.key().as_ref(), | ||
pool_state.key().as_ref(), | ||
], | ||
bump, | ||
)] | ||
pub authorized_pool: Account<'info, AuthorizedPool>, | ||
/// DEX pool state with current token pair price | ||
#[account( | ||
seeds = [ | ||
POOL_SEED.as_bytes(), | ||
amm_config.key().as_ref(), | ||
donation_amm_mint.key().as_ref(), | ||
donation_protocol.donation_mint.key().as_ref(), | ||
], | ||
seeds::program = authorized_clmm.program_id.key(), | ||
bump, | ||
)] | ||
pub pool_state: AccountLoader<'info, PoolState>, | ||
pub amm_config: Box<Account<'info, AmmConfig>>, | ||
pub donation_protocol: Account<'info, DonationProtocolData>, | ||
pub donation_amm_mint: Account<'info, Mint>, | ||
#[account( | ||
constraint = authorized_clmm.donation_protocol == donation_protocol.key(), | ||
)] | ||
pub authorized_clmm: Account<'info, AuthorizedClmm>, | ||
#[account(mut)] | ||
pub payer: Signer<'info>, | ||
pub system_program: Program<'info, System>, | ||
pub rent: Sysvar<'info, Rent>, | ||
} | ||
|
||
pub fn authorize_pool(ctx: Context<AuthorizePool>) -> Result<()> { | ||
let authorized_pool = &mut ctx.accounts.authorized_pool; | ||
authorized_pool.pool_state = ctx.accounts.pool_state.key(); | ||
authorized_pool.program_id = ctx.accounts.authorized_clmm.program_id; | ||
authorized_pool.token = ctx.accounts.donation_amm_mint.key(); | ||
authorized_pool.donation_protocol = ctx.accounts.donation_protocol.key(); | ||
|
||
Ok(()) | ||
} |
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,9 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[account] | ||
#[derive(Default)] | ||
#[derive(InitSpace)] | ||
pub struct AuthorizedClmm { | ||
pub program_id: Pubkey, | ||
pub donation_protocol: Pubkey, | ||
} |
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,11 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[account] | ||
#[derive(Default)] | ||
#[derive(InitSpace)] | ||
pub struct AuthorizedPool { | ||
pub pool_state: Pubkey, | ||
pub program_id: Pubkey, | ||
pub token: Pubkey, | ||
pub donation_protocol: Pubkey, | ||
} |
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 |
---|---|---|
@@ -1,32 +1,15 @@ | ||
use anchor_lang::prelude::*; | ||
use std::mem; | ||
|
||
use super::DISCRIMINATOR_LEN; | ||
|
||
#[account] | ||
#[derive(Default)] | ||
#[derive(InitSpace)] | ||
pub struct DonationProtocolData { | ||
pub treasury_mint: Pubkey, | ||
pub treasury: Pubkey, | ||
pub donation_mint: Pubkey, | ||
pub authority: Pubkey, | ||
pub min_amount_to_earn: u64, | ||
pub min_amount_to_collect: u64, | ||
pub treasury_owner_bump: u8, | ||
} | ||
|
||
impl DonationProtocolData { | ||
const TREASURY_MINT_LEN: usize = mem::size_of::<Pubkey>(); | ||
const TREASURY_LEN: usize = mem::size_of::<Pubkey>(); | ||
const DONATION_MINT_LEN: usize = mem::size_of::<Pubkey>(); | ||
const MIN_AMOUNT_TO_EARN_LEN: usize = mem::size_of::<u64>(); | ||
const MIN_AMOUNT_TO_COLLECT_LEN: usize = mem::size_of::<u64>(); | ||
const TREASURY_OWNER_BUMP_LEN: usize = mem::size_of::<u8>(); | ||
|
||
pub const LEN: usize = DISCRIMINATOR_LEN | ||
+ DonationProtocolData::TREASURY_MINT_LEN | ||
+ DonationProtocolData::TREASURY_LEN | ||
+ DonationProtocolData::DONATION_MINT_LEN | ||
+ DonationProtocolData::MIN_AMOUNT_TO_EARN_LEN | ||
+ DonationProtocolData::MIN_AMOUNT_TO_COLLECT_LEN | ||
+ DonationProtocolData::TREASURY_OWNER_BUMP_LEN; | ||
} |
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
Oops, something went wrong.