Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added an endpoint `claim_protocol_fee2` that requires `protocol_fee_authority` as the signer instead of an operator. Only one of the pool tokens can be claimed per instruction call.
- Added an endpoint `initialize_virtual_pool_with_token2022_transfer_hook` that allows a partner to create a virtual pool with a token-2022 base mint that supports transfer hooks. These pools are assigned a `Token2022WithTransferHook` pool type.
- Added endpoints with transfer hook support: `swap2_with_transfer_hook`, `claim_protocol_fee2_with_transfer_hook`, `claim_trading_fee_with_transfer_hook`, `claim_creator_trading_fee_with_transfer_hook`, and `withdraw_leftover_with_transfer_hook`. These accept a `transfer_hook_accounts_info: TransferHookAccountsInfo` parameter for transfer hook support on the base mint. The original endpoints are unchanged for backwards compatibility with non-transfer-hook pools.
- Added `WithTransferHook` event variants for all pool-touching events.

### Changed

Expand Down
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ damm-v2 = { path = "libs/damm-v2" }
locker = { path = "libs/locker" }
dynamic-bonding-curve = { path = "programs/dynamic-bonding-curve" }
protocol-zap = { git = "https://github.com/MeteoraAg/zap-program", rev = "064c58b317b9a85f212c0de72caea286fc72fdb4" }
spl-transfer-hook-interface = "2.1.0"

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
Expand Down
100 changes: 100 additions & 0 deletions idls/transfer_hook_counter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"address": "EBZDYx7599krFc4m2govwBdZcicr4GgepqC78m71nsHS",
"metadata": {
"name": "transfer_hook_counter",
"version": "0.1.0",
"spec": "0.1.0"
},
"instructions": [
{
"name": "initialize_extra_account_meta_list",
"discriminator": [92, 197, 174, 197, 41, 124, 19, 3],
"accounts": [
{
"name": "payer",
"writable": true,
"signer": true
},
{
"name": "extra_account_meta_list",
"writable": true
},
{
"name": "mint"
},
{
"name": "counter_account",
"writable": true
},
{
"name": "token_program"
},
{
"name": "associated_token_program"
},
{
"name": "system_program"
}
],
"args": []
},
{
"name": "transfer_hook",
"discriminator": [220, 57, 220, 152, 126, 125, 97, 168],
"accounts": [
{
"name": "source_token"
},
{
"name": "mint"
},
{
"name": "destination_token"
},
{
"name": "owner"
},
{
"name": "extra_account_meta_list"
},
{
"name": "counter_account",
"writable": true
}
],
"args": [
{
"name": "amount",
"type": "u64"
}
]
}
],
"accounts": [
{
"name": "CounterAccount",
"discriminator": [164, 8, 153, 71, 8, 44, 93, 22]
}
],
"errors": [
{
"code": 6000,
"name": "AmountTooBig",
"msg": "The amount is too big"
}
],
"types": [
{
"name": "CounterAccount",
"type": {
"kind": "struct",
"fields": [
{
"name": "counter",
"type": "u32"
}
]
}
}
]
}
1 change: 1 addition & 0 deletions programs/dynamic-bonding-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ damm-v2 = { workspace = true }
locker = { workspace = true }
protocol-zap = { workspace = true }
mpl-token-metadata = { workspace = true }
spl-transfer-hook-interface = { workspace = true }

[dev-dependencies]
proptest = { workspace = true }
Expand Down
24 changes: 24 additions & 0 deletions programs/dynamic-bonding-curve/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ pub enum PoolError {

#[msg("Invalid claim protocol fee accounts")]
InvalidClaimProtocolFeeAccounts,

#[msg("Invalid instructions sysvar account")]
InvalidInstructionsSysvar,

#[msg("Invalid remaining accounts length")]
InvalidRemainingAccountsLength,

#[msg("Missing remaining account for transfer hook")]
MissingRemainingAccountForTransferHook,

#[msg("No transfer hook program")]
NoTransferHookProgram,

#[msg("Duplicated remaining account types")]
DuplicatedRemainingAccountTypes,

#[msg("Invalid transfer hook program")]
InvalidTransferHookProgram,

#[msg("Invalid transfer hook authority")]
InvalidTransferHookAuthority,

#[msg("Transfer hook must be revoked before migration")]
TransferHookNotRevoked,
}

impl From<ProtozolZapError> for PoolError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use crate::{
ConfigParameters, LockedVestingParams, SwapParameters, SwapParameters2,
};

pub mod transfer_hook;
pub use transfer_hook::*;

/// Create partner metadata
#[event]
pub struct EvtPartnerMetadata {
Expand Down Expand Up @@ -185,12 +188,6 @@ pub struct EvtWithdrawMigrationFee {
pub flag: u8,
}

#[event]
pub struct EvtPartnerWithdrawMigrationFee {
pub pool: Pubkey,
pub fee: u64,
}

#[event]
pub struct EvtClaimPoolCreationFee {
pub pool: Pubkey,
Expand All @@ -205,10 +202,3 @@ pub struct EvtPartnerClaimPoolCreationFee {
pub creation_fee: u64,
pub fee_receiver: Pubkey,
}

#[event]
pub struct EvtClaimProtocolLiquidityMigrationFee {
pub pool: Pubkey,
pub token_base_amount: u64,
pub token_quote_amount: u64,
}
110 changes: 110 additions & 0 deletions programs/dynamic-bonding-curve/src/event/transfer_hook.rs
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transfer hook events have the same properties but different name to isolate them from the non-transfer hook events

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
use anchor_lang::prelude::*;

use crate::{state::SwapResult2, SwapParameters2};

#[event]
pub struct EvtInitializePoolWithTransferHook {
pub pool: Pubkey,
pub config: Pubkey,
pub creator: Pubkey,
pub base_mint: Pubkey,
pub pool_type: u8,
pub activation_point: u64,
}

#[event]
pub struct EvtVirtualPoolMetadataWithTransferHook {
pub virtual_pool_metadata: Pubkey,
pub virtual_pool: Pubkey,
}

#[event]
pub struct EvtSwap2WithTransferHook {
pub pool: Pubkey,
pub config: Pubkey,
pub trade_direction: u8,
pub has_referral: bool,
pub swap_parameters: SwapParameters2,
pub swap_result: SwapResult2,
pub quote_reserve_amount: u64,
pub migration_threshold: u64,
pub current_timestamp: u64,
}

#[event]
pub struct EvtCurveCompleteWithTransferHook {
pub pool: Pubkey,
pub config: Pubkey,
pub base_reserve: u64,
pub quote_reserve: u64,
}

#[event]
pub struct EvtClaimProtocolFee2WithTransferHook {
pub pool: Pubkey,
pub receiver_token_account: Pubkey,
pub token_mint: Pubkey,
pub amount: u64,
}

#[event]
pub struct EvtClaimTradingFeeWithTransferHook {
pub pool: Pubkey,
pub token_base_amount: u64,
pub token_quote_amount: u64,
}

#[event]
pub struct EvtClaimCreatorTradingFeeWithTransferHook {
pub pool: Pubkey,
pub token_base_amount: u64,
pub token_quote_amount: u64,
}

#[event]
pub struct EvtPartnerWithdrawSurplusWithTransferHook {
pub pool: Pubkey,
pub surplus_amount: u64,
}

#[event]
pub struct EvtCreatorWithdrawSurplusWithTransferHook {
pub pool: Pubkey,
pub surplus_amount: u64,
}

#[event]
pub struct EvtWithdrawLeftoverWithTransferHook {
pub pool: Pubkey,
pub leftover_receiver: Pubkey,
pub leftover_amount: u64,
}

#[event]
pub struct EvtUpdatePoolCreatorWithTransferHook {
pub pool: Pubkey,
pub creator: Pubkey,
pub new_creator: Pubkey,
}

#[event]
pub struct EvtWithdrawMigrationFeeWithTransferHook {
pub pool: Pubkey,
pub fee: u64,
pub flag: u8,
}

#[event]
pub struct EvtClaimPoolCreationFeeWithTransferHook {
pub pool: Pubkey,
pub receiver: Pubkey,
pub creation_fee: u64,
}

#[event]
pub struct EvtPartnerClaimPoolCreationFeeWithTransferHook {
pub pool: Pubkey,
pub partner: Pubkey,
pub creation_fee: u64,
pub fee_receiver: Pubkey,
}
Loading
Loading