Skip to content
Open
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
8 changes: 8 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions libs/dynamic-vault/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "dynamic-vault"
version = "0.0.1"
authors = [""]
edition = "2021"

[dependencies]
anchor-lang = { workspace = true }
5 changes: 5 additions & 0 deletions libs/dynamic-vault/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use anchor_lang::prelude::*;

declare_program!(dynamic_vault);

pub use dynamic_vault::*;
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
"devDependencies": {
"@coral-xyz/anchor-errors": "^0.31.0",
"@solana/spl-token": "^0.4.8",
"@solana/spl-token-metadata": "^0.1.6",
"@solana/web3.js": "^1.95.3",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"decimal.js": "^10.4.2",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5",
"solana-bankrun": "^0.4.0",
"decimal.js": "^10.4.2"
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

3 changes: 2 additions & 1 deletion programs/dynamic-bonding-curve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ spl-token-metadata-interface = "0.6"
dynamic-amm = { path = "../../libs/dynamic-amm" }
damm-v2 = { path = "../../libs/damm-v2" }
locker = { path = "../../libs/locker" }
dynamic-vault = { path = "../../libs/dynamic-vault" }

[dev-dependencies]
proptest = "1.2.0"
proptest = "1.2.0"
3 changes: 3 additions & 0 deletions programs/dynamic-bonding-curve/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,7 @@ pub enum PoolError {

#[msg("Invalid creator trading fee percentage")]
InvalidCreatorTradingFeePercentage,

#[msg("Invalid migration accounts")]
InvalidMigrationAccounts,
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::u64;

use crate::{
const_pda,
state::{MigrationProgress, VirtualPool},
Expand Down Expand Up @@ -52,7 +50,7 @@ pub struct MigrateMeteoraDammClaimLpTokenCtx<'info> {
}

impl<'info> MigrateMeteoraDammClaimLpTokenCtx<'info> {
fn transfer(&self, bump: u8, amount: u64) -> Result<()> {
pub fn transfer(&self, bump: u8, amount: u64) -> Result<()> {
let pool_authority_seeds = pool_authority_seeds!(bump);

transfer(
Expand Down Expand Up @@ -86,10 +84,14 @@ pub fn handle_migrate_meteora_damm_claim_lp_token<'info>(
let is_partner = ctx.accounts.owner.key() == migration_metadata.partner;
let is_creator = ctx.accounts.owner.key() == migration_metadata.pool_creator;

let mut versioned_migration_metadata = migration_metadata.get_versioned_migration_metadata()?;

let lp_to_claim = match (is_partner, is_creator) {
(true, true) => migration_metadata.claim_as_self_partnered_creator()?,
(true, false) => migration_metadata.claim_as_partner()?,
(false, true) => migration_metadata.claim_as_creator()?,
(true, true) => {
versioned_migration_metadata.validate_and_claim_as_self_partnered_creator()?
}
(true, false) => versioned_migration_metadata.validate_and_claim_as_partner()?,
(false, true) => versioned_migration_metadata.validate_and_claim_as_creator()?,
(false, false) => return Err(PoolError::InvalidOwnerAccount.into()),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::u64;

use crate::{
const_pda,
state::{MigrationProgress, VirtualPool},
*,
};
use anchor_spl::token::{Token, TokenAccount};
use anchor_spl::token::{Mint, Token, TokenAccount};
use dynamic_amm::accounts::LockEscrow;
use dynamic_amm::accounts::Pool;
use dynamic_vault::accounts::Vault;

/// create lock escrow must be before that transaction
#[derive(Accounts)]
Expand All @@ -25,16 +25,23 @@ pub struct MigrateMeteoraDammLockLpTokenCtx<'info> {
pub pool_authority: AccountInfo<'info>,

/// CHECK: pool
#[account(mut)]
pub pool: UncheckedAccount<'info>,
#[account(
mut,
has_one = lp_mint @ PoolError::InvalidMigrationAccounts,
has_one = a_vault @ PoolError::InvalidMigrationAccounts,
has_one = b_vault @ PoolError::InvalidMigrationAccounts,
has_one = a_vault_lp @ PoolError::InvalidMigrationAccounts,
has_one = b_vault_lp @ PoolError::InvalidMigrationAccounts,
)]
pub pool: Box<Account<'info, Pool>>,

/// CHECK: lp_mint
pub lp_mint: UncheckedAccount<'info>,
pub lp_mint: Box<Account<'info, Mint>>,

#[account(
mut,
has_one=pool,
has_one=owner,
has_one = pool,
has_one = owner,
)]
pub lock_escrow: Box<Account<'info, LockEscrow>>,

Expand All @@ -57,18 +64,24 @@ pub struct MigrateMeteoraDammLockLpTokenCtx<'info> {
#[account(address = dynamic_amm::ID)]
pub amm_program: UncheckedAccount<'info>,

/// CHECK: Vault account for token a. token a of the pool will be deposit / withdraw from this vault account.
pub a_vault: UncheckedAccount<'info>,
/// CHECK: Vault account for token b. token b of the pool will be deposit / withdraw from this vault account.
pub b_vault: UncheckedAccount<'info>,
/// CHECK: LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
pub a_vault_lp: UncheckedAccount<'info>,
/// CHECK: LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
pub b_vault_lp: UncheckedAccount<'info>,
/// CHECK: LP token mint of vault a
pub a_vault_lp_mint: UncheckedAccount<'info>,
/// CHECK: LP token mint of vault b
pub b_vault_lp_mint: UncheckedAccount<'info>,
/// Vault account for token a. token a of the pool will be deposit / withdraw from this vault account.
pub a_vault: Box<Account<'info, Vault>>,
/// Vault account for token b. token b of the pool will be deposit / withdraw from this vault account.
pub b_vault: Box<Account<'info, Vault>>,
/// LP token account of vault A. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
#[account(
token::mint = a_vault_lp_mint.key()
)]
pub a_vault_lp: Box<Account<'info, TokenAccount>>,
/// LP token account of vault B. Used to receive/burn the vault LP upon deposit/withdraw from the vault.
#[account(
token::mint = b_vault_lp_mint.key()
)]
pub b_vault_lp: Box<Account<'info, TokenAccount>>,
/// LP token mint of vault a
pub a_vault_lp_mint: Box<Account<'info, Mint>>,
/// LP token mint of vault b
pub b_vault_lp_mint: Box<Account<'info, Mint>>,

/// token_program
pub token_program: Program<'info, Token>,
Expand Down Expand Up @@ -119,10 +132,27 @@ pub fn handle_migrate_meteora_damm_lock_lp_token<'info>(
let is_partner = ctx.accounts.owner.key() == migration_metadata.partner;
let is_creator = ctx.accounts.owner.key() == migration_metadata.pool_creator;

let damm_migration_accounts = DammAccounts {
lp_mint: &ctx.accounts.lp_mint,
a_vault: &ctx.accounts.a_vault,
b_vault: &ctx.accounts.b_vault,
a_vault_lp: &ctx.accounts.a_vault_lp,
b_vault_lp: &ctx.accounts.b_vault_lp,
a_vault_lp_mint: &ctx.accounts.a_vault_lp_mint,
b_vault_lp_mint: &ctx.accounts.b_vault_lp_mint,
};

let mut version_migration_metadata = migration_metadata.get_versioned_migration_metadata()?;

let lp_to_lock = match (is_partner, is_creator) {
(true, true) => migration_metadata.lock_as_self_partnered_creator()?,
(true, false) => migration_metadata.lock_as_partner()?,
(false, true) => migration_metadata.lock_as_creator()?,
(true, true) => version_migration_metadata
.validate_and_lock_as_self_partnered_creator(damm_migration_accounts)?,
(true, false) => {
version_migration_metadata.validate_and_lock_as_partner(damm_migration_accounts)?
}
(false, true) => {
version_migration_metadata.validate_and_lock_as_creator(damm_migration_accounts)?
}
(false, false) => return Err(PoolError::InvalidOwnerAccount.into()),
};

Expand Down
Loading
Loading