Trading Terminals can easily integrate with Meteora DAMM v2 by following this guide that explains in detail how to get the necessary data from indexing the DAMM v2 program.
Total Fees
totalFees = baseFees + dynamicFees
Base Fees
Base Fees includes either a Flat Fee or a Fee Scheduler or Rate Limiter.
BaseFeeMode can only be enums 0, 1, or 2.
- 0 = Linear Fee Scheduler
- 1 = Exponential Fee Scheduler
- 2 = Rate Limiter
Flat Fee
You can fetch the flat fee directly from the cliffFeeNumerator in the baseFee object if firstFactor, secondFactor, and thirdFactor are all 0.
// Example
baseFee: {
cliffFeeNumerator: <BN: 10000000>, // 1% flat fee
firstFactor: 0,
secondFactor: <BN: 0>,
thirdFactor: <BN: 0>,
baseFeeMode: 0
}
The Fee Scheduler depends on the poolState.activationType.
- If the
poolState.activationType == 0, then numberOfPeriod and periodFrequency is calculated in SLOT == 400ms
- If the
poolState.activationType == 1, then numberOfPeriod and periodFrequency is calculated in SECONDS == 1000ms
Fee Scheduler
- For Fee Scheduler, it contains
numberOfPeriod, periodFrequency, and reductionFactor which are paired with the firstFactor, secondFactor, and thirdFactor respectively.
interface BaseFee = {
cliffFeeNumerator: BN
firstFactor: number // numberOfPeriod
secondFactor: BN // periodFrequency
thirdFactor: BN // reductionFactor
baseFeeMode: BaseFeeMode // 0 or 1
}
You can refer to the math formula for the Fee Scheduler
here
Here are some examples of how the Fee Scheduler works:
// Fee Scheduler: 50% reduce to 1% in 10 minutes linearly
baseFee: {
cliffFeeNumerator: <BN: 500000000>,
firstFactor: 60, // numberOfPeriods
secondFactor: <BN: 8166666>, // periodFrequency
thirdFactor: <BN: 10>, // reduction factor
baseFeeMode: 0
},
// Fee Scheduler: 50% reduce to 1% in 10 minutes exponentially
baseFee: {
cliffFeeNumerator: <BN: 500000000>,
firstFactor: 60, // numberOfPeriods
secondFactor: <BN: 631>, // periodFrequency
thirdFactor: <BN: 10>, // reduction factor
baseFeeMode: 1
},
Rate Limiter
-
For Rate Limiter, it contains
feeIncrementBps, maxLimiterDuration, and referenceAmount which are paired with the firstFactor, secondFactor, and thirdFactor respectively.
-
baseFeeMode can only be 2.
interface BaseFee = {
cliff_fee_numerator: BN
first_factor: number //feeIncrementBps
secondFactor: BN // maxLimiterDuration
thirdFactor: BN // referenceAmount
baseFeeMode: BaseFeeMode // 2
}
You can refer to the math formula for the Rate Limiter
here
Here are some examples of how the Rate Limiter works:
// Rate Limiter: Starts at 1% fee -> Exponential increase in fee for 10 slots based on trade size
// 0.5 SOL trade
// fee = 0.5 SOL * 0.1% = 0.0005 SOL
// 1.5 SOL trade
// fee = 1 SOL * 0.1% + 0.5 SOL * 0.2% = 0.002 SOL
// 3 SOL trade
// fee = 1 SOL * 0.1% + 1 SOL * 0.2% + 1 SOL * 0.3% = 0.006 SOL
baseFee: {
cliffFeeNumerator: new BN(10_000_000),
firstFactor: 10, // feeIncrementBps
secondFactor: new BN(10), // maxLimiterDuration
thirdFactor: new BN(1000000000), // referenceAmount
baseFeeMode: 2, // rate limiter mode
}
Dynamic Fees (Variable Fee)
You can refer to the Dynamic Fee calculation here
Plotting Charts
Using Transfer logs from Swap transactions is not the correct way of getting the token price as we have Anti-Sniper Suite features that can cause huge fee deductions from TokenAmountIn OR TokenAmountOut. Plotting the token chart price from these will lead to a very ugly chart.
The correct way is to fetch the EvtSwap2 CPI logs from the Swap transaction.
EvtSwap is an older version of the swap CPI logs and might be deprecated in the future. Use EvtSwap2 instead.
Because of the Anti-Sniper Suite features, you will have to apply the following checks to get the correct token price either before/after the fee deduction.
[1.1] Firstly, you will need to identify where the fees are coming from (either from input or output):
feeOnInput: (collectFeeMode == 1 && tradeDirection == 1)? true: false
[1.2] Next, calculate the amount and plot price depending on where the fees are coming from (either from input or output):
if (feeOnInput): price = excludedFeeInputAmount / outputAmount
if (!feeOnInput): price = excludedFeeInputAmount / outputAmount + tradingFee + protocolFee + referralFee + partnerFee
Trading Volume
Track from Swap CPI logs:
// Depending on Trade Direction:
trading_volume += actualAmountIn * token_price
Liquidity
In the DAMM v2 pool, the liquidity is fetched from the tokenAVault and tokenBVault of the DAMM v2 pool.
liquidity = tokenAVault * tokenAPrice + tokenBVault * tokenBPrice
Locked or Vested Liquidity
In DAMM v2, there are 3 different modes for liquidity:
lockedLiquidity - which means that the liquidity is permanently locked
vestedLiquidity - which means that the liqudiity is vestedLiquidity
unlockedLiquidity - which means that the liquidity is unlocked and claimable
You can use our DAMM v2 API endpoint that tracks pool positions and show accurately whether the liqudiity is locked or not on your trading terminal.
How to Identify Launchpads Using DAMM v2
You can ping us on Discord to get a list of all launchpads configuration who are launching on DAMM v2 directly so that you can index them on your trading terminal.
Open a ticket on
discord to get access to the list.
Referral Account
- For trading terminals, we have a feature that enables trading terminals to earn referral fees from all swaps that happens on our Meteora DBC program as long as they were swapped through your trading terminal.
- For referral fees, simply add your referral token account within the swap instruction & you will receive 20% of the protocol fees for all swaps.