Skip to content

Commit e3caf87

Browse files
Feat/config creation fee fix (#153)
* fix and refactor * update changelog
1 parent 0b49119 commit e3caf87

38 files changed

+432
-1016
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Add new endpoint `claim_protocol_pool_creation_fee` to allow protocol to withdraw the pool creation fee.
2929

3030
### Changed
31-
- Add new field `creation_fee` in config account state and pool account state
32-
- Allowed partners to configure the `creation_fee` when creating a config.
33-
- Charged pool creation fee according to the `creation_fee` specified in the config account (endpoints: `initialize_virtual_pool_with_token2022` and `initialize_virtual_pool_with_spl_token`)
31+
- Allowed partners to configure the `pool_creation_fee` when creating a config. The value is in SOL lamport, so when token creator create pool (throught endpoint `initialize_virtual_pool_with_spl_token` and `initialize_virtual_pool_with_token2022`), they would need to pay `pool_creation_fee` in SOL lamport. Later partner would be able to claim that fee (Meteora would take 10% from that fee)
32+
- Update field `creation_fee_bits` to field `legacy_creation_fee_bits` in pool account state
3433
- Removed the legacy pool creation fee logic from the `initialize_virtual_pool_with_token2022` endpoint.
3534

36-
### Removed
35+
### Breaking Changes
36+
All breaking changes are related to admin/operator functions
3737
- Remove endpoint `withdraw_lamports_from_pool_authority`
38+
- Change endpoint `claim_pool_creation_fee` to new endpoint `claim_legacy_pool_creation_fee`
39+
- Add new `payer` account in admin endpoint `create_claim_fee_operator`, that allow to payer to pay rent fee, instead of admin
40+
- Add new accounts `signer` and `claim_fee_operator` in endpoint `protocol_withdraw_surplus`, move the endpoint to permissioned
41+
3842

3943
## dynamic_bonding_curve [0.1.7] [PR #129](https://github.com/MeteoraAg/dynamic-bonding-curve/pull/129)
4044

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use crate::assert_eq_admin;
2+
use crate::state::{ClaimFeeOperator, PoolConfig, VirtualPool};
3+
use crate::PoolError;
4+
use anchor_lang::prelude::*;
5+
// check whether the signer is in admin list
6+
pub fn is_admin(signer: &Pubkey) -> Result<()> {
7+
require!(assert_eq_admin(signer.key()), PoolError::InvalidAdmin);
8+
Ok(())
9+
}
10+
11+
pub fn is_claim_fee_operator<'info>(
12+
claim_fee_operator: &AccountLoader<'info, ClaimFeeOperator>,
13+
signer: &Pubkey,
14+
) -> Result<()> {
15+
let claim_fee_operator = claim_fee_operator.load()?;
16+
require!(
17+
claim_fee_operator.operator.eq(signer),
18+
PoolError::Unauthorized
19+
);
20+
Ok(())
21+
}
22+
23+
pub fn is_partner_fee_claimer<'info>(
24+
config: &AccountLoader<'info, PoolConfig>,
25+
fee_claimer: &Pubkey,
26+
) -> Result<()> {
27+
let config = config.load()?;
28+
require!(config.fee_claimer.eq(fee_claimer), PoolError::Unauthorized);
29+
Ok(())
30+
}
31+
32+
pub fn is_pool_creator<'info>(
33+
pool: &AccountLoader<'info, VirtualPool>,
34+
creator: &Pubkey,
35+
) -> Result<()> {
36+
let pool = pool.load()?;
37+
require!(pool.creator.eq(creator), PoolError::Unauthorized);
38+
Ok(())
39+
}

programs/dynamic-bonding-curve/src/constants.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ pub mod fee {
9090
/// Protocol's share percentage of the pool creation fee. The remainder goes to the partner.
9191
pub const PROTOCOL_POOL_CREATION_FEE_PERCENT: u8 = 10; // 10%
9292

93-
// 0.01
94-
pub const TOKEN_2022_POOL_WITH_OUTPUT_FEE_COLLECTION_CREATION_FEE: u64 = 10_000_000;
95-
9693
// min pool creation fee: 0.001 SOL
9794
pub const MIN_POOL_CREATION_FEE: u64 = 1_000_000;
9895
// max pool creation fee: 100 SOL

programs/dynamic-bonding-curve/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ pub enum PoolError {
163163

164164
#[msg("Pool creation fee has been claimed")]
165165
PoolCreationFeeHasBeenClaimed,
166+
167+
#[msg("Not permit to do this action")]
168+
Unauthorized,
169+
170+
#[msg("Pool creation fee is zero")]
171+
ZeroPoolCreationFee,
166172
}

programs/dynamic-bonding-curve/src/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,10 @@ pub struct EvtClaimPoolCreationFee {
193193
pub receiver: Pubkey,
194194
pub creation_fee: u64,
195195
}
196+
197+
#[event]
198+
pub struct EvtPartnerClaimPoolCreationFee {
199+
pub pool: Pubkey,
200+
pub partner: Pubkey,
201+
pub creation_fee: u64,
202+
}

programs/dynamic-bonding-curve/src/instructions/admin/ix_claim_pool_creation_fee.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

programs/dynamic-bonding-curve/src/instructions/admin/ix_claim_protocol_pool_creation_fee.rs

Lines changed: 0 additions & 67 deletions
This file was deleted.

programs/dynamic-bonding-curve/src/instructions/admin/ix_close_claim_protocol_fee_operator.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anchor_lang::prelude::*;
22

3-
use crate::{assert_eq_admin, state::ClaimFeeOperator, EvtCloseClaimFeeOperator, PoolError};
3+
use crate::{state::ClaimFeeOperator, EvtCloseClaimFeeOperator};
44

55
#[event_cpi]
66
#[derive(Accounts)]
@@ -15,10 +15,7 @@ pub struct CloseClaimFeeOperatorCtx<'info> {
1515
#[account(mut)]
1616
pub rent_receiver: UncheckedAccount<'info>,
1717

18-
#[account(
19-
constraint = assert_eq_admin(admin.key()) @ PoolError::InvalidAdmin,
20-
)]
21-
pub admin: Signer<'info>,
18+
pub signer: Signer<'info>,
2219
}
2320

2421
pub fn handle_close_claim_fee_operator(ctx: Context<CloseClaimFeeOperatorCtx>) -> Result<()> {

programs/dynamic-bonding-curve/src/instructions/admin/ix_create_claim_protocol_fee_operator.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use anchor_lang::prelude::*;
22

33
use crate::{
4-
assert_eq_admin, constants::seeds::CLAIM_FEE_OPERATOR_PREFIX, state::ClaimFeeOperator,
5-
EvtCreateClaimFeeOperator, PoolError,
4+
constants::seeds::CLAIM_FEE_OPERATOR_PREFIX, state::ClaimFeeOperator, EvtCreateClaimFeeOperator,
65
};
76

87
#[event_cpi]
98
#[derive(Accounts)]
109
pub struct CreateClaimFeeOperatorCtx<'info> {
1110
#[account(
1211
init,
13-
payer = admin,
12+
payer = payer,
1413
seeds = [
1514
CLAIM_FEE_OPERATOR_PREFIX.as_ref(),
1615
operator.key().as_ref(),
@@ -23,11 +22,10 @@ pub struct CreateClaimFeeOperatorCtx<'info> {
2322
/// CHECK: operator
2423
pub operator: UncheckedAccount<'info>,
2524

26-
#[account(
27-
mut,
28-
constraint = assert_eq_admin(admin.key()) @ PoolError::InvalidAdmin,
29-
)]
30-
pub admin: Signer<'info>,
25+
pub signer: Signer<'info>,
26+
27+
#[account(mut)]
28+
pub payer: Signer<'info>,
3129

3230
pub system_program: Program<'info, System>,
3331
}
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
pub mod auth;
22
pub use auth::*;
3-
pub mod ix_claim_protocol_fee;
4-
pub use ix_claim_protocol_fee::*;
53
pub mod ix_create_claim_protocol_fee_operator;
64
pub use ix_create_claim_protocol_fee_operator::*;
75
pub mod ix_close_claim_protocol_fee_operator;
86
pub use ix_close_claim_protocol_fee_operator::*;
9-
pub mod ix_withdraw_protocol_surplus;
10-
pub use ix_withdraw_protocol_surplus::*;
11-
pub mod ix_claim_protocol_pool_creation_fee;
12-
pub use ix_claim_protocol_pool_creation_fee::*;
13-
pub mod ix_claim_pool_creation_fee;
14-
pub use ix_claim_pool_creation_fee::*;

0 commit comments

Comments
 (0)