Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix zap in damm-v2 with new base fee mode
- Add missing instructions sysvar in remaining accounts for `zap_in_damm_v2` which is used in rate limited DAMM v2 Pool for single swap validation

## zap [0.2.0] [PR #15](https://github.com/MeteoraAg/zap-program/pull/15)

Expand Down
191 changes: 104 additions & 87 deletions idls/damm_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"address": "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG",
"metadata": {
"name": "cp_amm",
"version": "0.1.6",
"version": "0.1.7",
"spec": "0.1.0",
"description": "Created with Anchor"
},
Expand Down Expand Up @@ -305,79 +305,20 @@
},
{
"name": "token_a_account",
"docs": ["The treasury token a account"],
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
48, 9, 89, 123, 106, 114, 131, 251, 50, 173, 254, 250, 10, 80,
160, 84, 143, 100, 81, 249, 134, 112, 30, 213, 50, 166, 239,
78, 53, 175, 188, 85
]
},
{
"kind": "account",
"path": "token_a_program"
},
{
"kind": "account",
"path": "token_a_mint"
}
],
"program": {
"kind": "const",
"value": [
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
219, 233, 248, 89
]
}
}
"writable": true
},
{
"name": "token_b_account",
"docs": ["The treasury token b account"],
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
48, 9, 89, 123, 106, 114, 131, 251, 50, 173, 254, 250, 10, 80,
160, 84, 143, 100, 81, 249, 134, 112, 30, 213, 50, 166, 239,
78, 53, 175, 188, 85
]
},
{
"kind": "account",
"path": "token_b_program"
},
{
"kind": "account",
"path": "token_b_mint"
}
],
"program": {
"kind": "const",
"value": [
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
219, 233, 248, 89
]
}
}
"writable": true
},
{
"name": "operator",
"docs": ["Claim fee operator"]
},
{
"name": "whitelisted_address",
"name": "signer",
"docs": ["Operator"],
"signer": true,
"relations": ["operator"]
"signer": true
},
{
"name": "token_a_program",
Expand Down Expand Up @@ -498,9 +439,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "rent_receiver",
Expand Down Expand Up @@ -535,7 +475,7 @@
"writable": true
},
{
"name": "admin",
"name": "signer",
"signer": true
},
{
Expand Down Expand Up @@ -637,9 +577,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "rent_receiver",
Expand Down Expand Up @@ -690,9 +629,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "payer",
Expand Down Expand Up @@ -760,9 +698,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "payer",
Expand Down Expand Up @@ -831,7 +768,7 @@
"name": "whitelisted_address"
},
{
"name": "admin",
"name": "signer",
"signer": true
},
{
Expand Down Expand Up @@ -989,9 +926,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "payer",
Expand Down Expand Up @@ -2057,9 +1993,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "event_authority",
Expand Down Expand Up @@ -2408,9 +2343,8 @@
"name": "operator"
},
{
"name": "whitelisted_address",
"signer": true,
"relations": ["operator"]
"name": "signer",
"signer": true
},
{
"name": "event_authority",
Expand Down Expand Up @@ -2577,6 +2511,54 @@
"type": "u8"
}
]
},
{
"name": "zap_protocol_fee",
"discriminator": [213, 155, 187, 34, 56, 182, 91, 240],
"accounts": [
{
"name": "pool_authority",
"address": "HLnpSz9h2S4hiLQ43rnSD9XkcUThA7B8hQMKmDaiTLcC"
},
{
"name": "pool",
"writable": true
},
{
"name": "token_vault",
"writable": true
},
{
"name": "token_mint"
},
{
"name": "receiver_token",
"writable": true
},
{
"name": "operator",
"docs": ["zap claim fee operator"]
},
{
"name": "signer",
"docs": ["Operator"],
"signer": true
},
{
"name": "token_program",
"docs": ["Token program"]
},
{
"name": "sysvar_instructions",
"address": "Sysvar1nstructions1111111111111111111111111"
}
],
"args": [
{
"name": "max_amount",
"type": "u64"
}
]
}
],
"accounts": [
Expand Down Expand Up @@ -3011,6 +2993,41 @@
"code": 6059,
"name": "MissingOperatorAccount",
"msg": "Missing operator account"
},
{
"code": 6060,
"name": "IncorrectATA",
"msg": "Incorrect ATA"
},
{
"code": 6061,
"name": "InvalidZapOutParameters",
"msg": "Invalid zap out parameters"
},
{
"code": 6062,
"name": "InvalidWithdrawProtocolFeeZapAccounts",
"msg": "Invalid withdraw protocol fee zap accounts"
},
{
"code": 6063,
"name": "MintRestrictedFromZap",
"msg": "SOL,USDC protocol fee cannot be withdrawn via zap"
},
{
"code": 6064,
"name": "CpiDisabled",
"msg": "CPI disabled"
},
{
"code": 6065,
"name": "MissingZapOutInstruction",
"msg": "Missing zap out instruction"
},
{
"code": 6066,
"name": "InvalidZapAccounts",
"msg": "Invalid zap accounts"
}
],
"types": [
Expand Down
17 changes: 12 additions & 5 deletions programs/zap/src/instructions/ix_zap_in_damm_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ pub struct ZapInDammv2Ctx<'info> {
}

impl<'info> ZapInDammv2Ctx<'info> {
fn swap(&self, amount: u64, trade_direction: TradeDirection) -> Result<()> {
fn swap(
&self,
amount: u64,
trade_direction: TradeDirection,
remaining_accounts: &[AccountInfo<'info>],
) -> Result<()> {
let (input_token_account, output_token_account) = if trade_direction == TradeDirection::AtoB
{
(
Expand Down Expand Up @@ -99,7 +104,8 @@ impl<'info> ZapInDammv2Ctx<'info> {
payer: self.owner.to_account_info(),
referral_token_account: None, // TODO check whether it should be some(damm_program)
},
),
)
.with_remaining_accounts(remaining_accounts.to_vec()),
SwapParameters2 {
amount_0: amount,
amount_1: 0,
Expand Down Expand Up @@ -140,8 +146,8 @@ impl<'info> ZapInDammv2Ctx<'info> {
}
}

pub fn handle_zap_in_damm_v2(
ctx: Context<ZapInDammv2Ctx>,
pub fn handle_zap_in_damm_v2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, ZapInDammv2Ctx<'info>>,
pre_sqrt_price: u128, // sqrt price user observe in local
max_sqrt_price_change_bps: u32, // max sqrt price change after swap
) -> Result<()> {
Expand Down Expand Up @@ -216,7 +222,8 @@ pub fn handle_zap_in_damm_v2(
return Ok(()); // no need to swap, just return
}
drop(pool);
ctx.accounts.swap(swap_in_amount, trade_direction)?;
ctx.accounts
.swap(swap_in_amount, trade_direction, &ctx.remaining_accounts)?;
}
Err(err) => {
// if calculation fail, we just skip swap and add liquidity with remaining amount
Expand Down
4 changes: 2 additions & 2 deletions programs/zap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub mod zap {
)
}

pub fn zap_in_damm_v2(
ctx: Context<ZapInDammv2Ctx>,
pub fn zap_in_damm_v2<'c: 'info, 'info>(
ctx: Context<'_, '_, 'c, 'info, ZapInDammv2Ctx<'info>>,
pre_sqrt_price: u128,
max_sqrt_price_change_bps: u32,
) -> Result<()> {
Expand Down
13 changes: 9 additions & 4 deletions tests/common/endpoints/zapIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AccountMeta,
PublicKey,
SystemProgram,
SYSVAR_INSTRUCTIONS_PUBKEY,
Transaction,
} from "@solana/web3.js";
import { DAMM_V2_PROGRAM_ID } from "../damm_v2";
Expand All @@ -14,15 +15,12 @@ import {
deriveLedgerAccount,
getDammV2Pool,
} from "../pda";
import { createZapProgram, ZAP_PROGRAM_ID } from "./zapOut";
import { createZapProgram } from "./zapOut";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import {
DLMM_PROGRAM_ID_LOCAL,
getBinArrayAccountMetaByBinRange,
getLbPairState,
MEMO_PROGRAM_ID,
SET_COMPUTE_UNIT_LIMIT_IX,
StrategyType,
} from "../dlmm";

export async function zapInDammv2(params: {
Expand Down Expand Up @@ -87,6 +85,13 @@ export async function zapInDammv2(params: {
dammProgram: DAMM_V2_PROGRAM_ID,
dammEventAuthority: deriveDammV2EventAuthority(),
})
.remainingAccounts([
{
isSigner: false,
isWritable: false,
pubkey: SYSVAR_INSTRUCTIONS_PUBKEY,
},
])
.transaction();
}

Expand Down
Loading
Loading