# PreBond Tax

Flap supports Tax tokens. Since V5.4.0  (on BNB Chain & XLayer) , tax is not only applied to migrated tax tokens but also the ones that are still on the bonding curve.&#x20;

When a tax token has already migrated DEX, it will charges a tax on every trade through the main pool and accumulate the tax in the token first. Once the accumulated token amount reaches a specific liquidation threshold, an automatic liquidation happens to sell the token for quote and sent the the beneficiary through the Tax Splitter. (Check below to learn more detaills)&#x20;

When a tax token is still on the bonding curve, we don’t implement it as a “real tax” like a migrated one. To make it simple and easy to do an off-chain quote,  we implement it as an `extra fee` added upon the current bonding curve  fee.

For example:

* For a non-tax token, the current bonding curve fee on BNB chain is 1%.
* For a token with a tax of 3%, the effective trading fee becomes: 1% + 3% = 4%
* For a token with a tax of 1%, the effective trading fee is 2%

## FAQ for Integrators

### I am using `quoteExactInput` to get a quote, do I need any change?

No. You don’t need make any changes. The `quoteExactInput` method will work as expected. For tax tokens, it will return the new quote result.

### I am doing an off-chain quote, how can I change my current implementation?

💡

If you are not able to change your off-chain quote logics, you can also raise your slippage based on the tax rate of a token.

We assume that you have implemented your off-chain quote logic based on <https://docs.flap.sh/flap/developers/trade-tokens#how-to-do-an-off-chain-quote>. In <https://docs.flap.sh/flap/developers/trade-tokens#how-to-do-an-off-chain-quote>, we have two examples:

* Swap 1 BNB for token
* Swap 1M token for BNB

Here are the changes:

* Instead of using the previous fixed 1% fee rate, **we now use a new fee rate for tax token**.
* We can get the token’s tax rate using either `getTokenV6` or `getTokenV7` , Or we can index Portal’s `FlapTokenTaxSet` event to get the token’s tax rate. (Note that `FlapTokenTaxSet` is optional, if not presented, the tax rate is 0 by default).

```tsx
//// Values From your Indexer or getTokenV6/V7

// current circulating supply 
// This can be obtained from getTokenV6 or the FlapTokenCirculatingSupplyChanged event.
let curr_circulating_supply;  
// The circulating supply threshold for the token to be migrated to DEX
// Typicially, this is 800M 
// This can be obtained from getTokenV6 or the TokenDexSupplyThreshSet event. 
let dex_supply_threshold = 800_000_000;
// The token's Tax rate 
// This can be obtained from getTokenV6 or the FlapTokenTaxSet event from the Poral 
let tax = 0; 

// The input bnb amount 
let input_bnb = 1; 

//// Compute the Quote 

// We cannot buy more than the dex_supply_threshold on the bonding curve 
// The max_reserve is the cap of the reserve 
let max_reserve = curve.estimateReserve(dex_supply_threshold);
// We estimate the current reserve from the circulating supply  
let curr_reserve = curve.estimateReserve(curr_circulating_supply);

// CHANGED!!!! 
// protocol fee on BNB chain is 1% 
let fee = 0.01 + tax; // 1% fee  + tax 

// Charge a 1% fee on the input bnb. 
let input_after_fee = input_bnb * (1 - fee); 

// If the user pays more than required, we will automatically refund the user 
let new_reserve = curr_reserve + min(input_after_fee, max_reserve - curr_reserve);
// estimate new circulating supply from new reserve 
let new_circulating_supply = curve.estimateSupply(new_reserve);

// The diff of circulating supply is the output token amount 
let output_amt = new_circulating_supply - curr_circulating_supply; 
```

Similarly for the sale:

```tsx

//// From Indexer Or getTokenV6/V7 

// current circulating supply 
let curr_circulating_supply;  
// The circulating supply threshold for the token to be migrated to DEX
// Typicially, this is 800M 
// This can be obtained from getTokenV6/V7 or the TokenDexSupplyThreshSet event.
let dex_supply_threshold;
// The token's Tax rate 
// This can be obtained from getTokenV6 or the FlapTokenTaxSet event from the Poral 
// eg.  this token has a 3% tax 
let tax = 0.03; 

// BNB fee 
// protocol 1% , tax 3% 
// Effective fee: 4% 
let fee = 0.01 + tax = 0.04;

// The input token amount
let input_token_amt = 1_000_000; 

// estimate the current reserve 
let curr_reserve = curve.estimateReserve(curr_circulating_supply);

// estimate the new resereve 
let new_reserve = curve.estimateReserve(curr_circulating_supply - input_token_amt);

// The diff is the output amount without deducting the fee 
let output_eth_before_fee =  curr_reserve - new_reserve;  

// we take 1% fee from the quote token 
let output_eth = output_eth_before_fee * (1 - fee);
```
