1. Background
In Staple's pricing mechanism, the oracle price serves as the basis for determining the trading rate of a token pair, which is then adjusted by the parameter $r_{alr}$ on the price adjustment curve. When the oracle price remains unchanged, the trading price is entirely dependent on $r_{alr}$  a higher $r_{alr}$ leads to a lower trading price.
However, any of the following actions: liquidity allocation, liquidity deallocation, and swapping in a Virtual Trading Pair (VTP), can alter the $r_{alr}$ value of the VTP (as described in Towards Capital Efficiency  Staple's LP Architecture and Mechanism), thereby affecting the swap price for subsequent transactions. As a result, through actions like liquidity allocation or deallocation, a trader can to some extent control the $r_{alr}$ parameter of a VTP, creating opportunities for arbitrage profit by exploiting these price variations.
In specific, the following operations could give rise to an arbitrage opportunity that is detrimental to LP's assets:

A trader swaps $token_0$ for $token_1$ to move up $r_{alr}$.

The trader then allocates $token_0$ liquidity to or deallocates $token_1$ liquidity from the same VTP, driving $r_{alr}$ even higher.

The same trader swaps the same amount of $token_1$ he received in step 1 back to $token_0$.
Notice:

Without step 2, the trader should get in step 3 the exact amount of $token_0$ he spent in step 1 (See Staple's Pricing Mechanism).

In step 2, moving $r_{alr}$ upwards results in a lower trading price for $token_0$ to $token_1$ and, conversely, a higher trading price for the trading direction from $token_1$ to $token_0$. This increased price ratio of $token_1$ to $token_0$ enables the trader to swap back more $token_0$ than what was spent in step 1, leading to an arbitrage profit at the expense of the LP's assets.
With the same definition as in "Staple's Pricing Mechanism":

$ALR_0 = \frac{A_0}{L_0}$
The asset liabity ratio of $token_0$;

$ALR_1 = \frac{A_1}{L_1}$
The asset liabity ratio of $token_1$,
We clarify the four allocation and deallocation patterns that result in a higher $r_{alr}$, potentially creating arbitrage opportunities that can be detrimental to LP assets in the aforementioned step 2.

$ALR_0 > 1$, Deallocate $token_0$
eg. $ALR_0=1.1=220/200$, deallocate 100 $\rightarrow$ $ALR_0=1.2=120/100$, $ALR_0$ goes up.

$ALR_0 < 1$, Allocate $token_0$
eg. $ALR_0=0.8=80/100$, allocate 100 $\rightarrow$ $ALR_0=0.9=180/200$, $ALR_0$ goes up.

$ALR_1 > 1$, Allocate $token_1$
eg. $ALR_1=1.2=120/100$, allocate 100 $\rightarrow$ $ALR_1=1.1=220/200$, $ALR_1$ goes down.

$ALR_1 < 1$, Deallocate $token_1$
eg. $ALR_1=0.9=180/200$, deallocate 100 $\rightarrow$ $ALR_1=0.8=80/100$, $ALR_1'$ goes down.
To prevent the harmful arbitrages described above, fees should be applied to liquidity allocation and deallocation. These fees are charged on LPs when $r_{alr}$ is within a certain range ($RRS$), beyond which LPs are exempt from the fees. However, transactions conducted outside this range will incur an additional price penalty.
It's important to note that the example provided above only considers the trading direction from $token_0$ to $token_1$. In the opposite trading direction, there are equivalent allocation and deallocation patterns that will increase $r_{alr_1}$, and fees will also be charged for these actions. As a result, fees are applied to any allocation or deallocation action, regardless of the trading direction.
 $ALR_1 > 1$, Deallocate $token_1$
 $ALR_1 < 1$, Allocate $token_1$
 $ALR_0 > 1$, Allocate $token_0$
 $ALR_0 < 1$, Deallocate $token_0$
For the sake of simplicity in the following analysis, we will focus on the trading direction from $token_0$ to $token_1$.
2. Definition & Precalculation

$L_0$
The amount of liability of $token_0$.

$L_1$
The amount of liability of $token_1$.

$A_0$
The amount of asset of $token_0$.

$A_1$
The amount of asset of $token_1$.

$ALR_0 = \frac{A_0}{L_0}$
The asset liabity ratio of $token_0$.

$ALR_1 = \frac{A_1}{L_1}$
The asset liabity ratio of $token_1$.

$OP_0$
The oracle price of $token_0$.

$OP_1$
The oracle price of $token_1$.

$r_{alr} = r_{alr_0} = \frac{ALR_0}{ALR_1}$ The ratio of the asset
liability ratios: $token_0$ to $token_1$. 
$r_{alr_1} = \frac{ALR_1}{ALR_0} = \frac{1}{r_{alr}}$ The ratio of
the asset liability ratios: $token_1$ to $token_0$. 
$P_{as} = P_{as_0}$
The adjusted starting price from $token_0$ to
$token_1$ before a transaction takes place  oracle price adjusted
by the current $r_{alr}$. 
$P_{as_1}$
The adjusted starting price from $token_1$ to
$token_0$ before a transaction takes place  oracle price adjusted
by the current $r_{alr}$. 
$P_{ae} = P_{ae_0}$
The adjusted end price from $token_0$ to $token_1$
when a transaction is finished. 
$P_{ae_1}$
The adjusted end price from $token_1$ to $token_0$
when a transaction is finished. 
$P_{av} = P_{av_0}$ The average trading price of this transaction
from $token_0$ to $token_1$  $P_{av_0}$  is the weighted average
between $P_{as_0}$ and $P_{ae_0}$. 
$P_{av_1}$ The trading price of a transaction from $token_1$ to
$token_0$. 
$'$ an ' is superscripted to a parameter to denote the new status of this parameter following a transaction
In line with the price calculation derived in Staple's Pricing Mechanism, the table below demonstrates the arbitrage process:
start  step 1  step 2  step 3  

swap $token_0$ to $token_1$  (de)allocate  swap $token_1$ to $token_0$  
$amount_{in}$  $y$  $D$ $token_0$ or $D/P_{as_0}$ $token_1$  $y*P_{av_0}$  
$P_{as_0}$  $P_{as_0}$  $P_{as_0}'$  $P_{as_0}''$  $P_{as_0}'''$ 
swap price  $P_{av_0} =(P_{as_0}*P_{as_0}')^{\frac{1}{2}}$  $P_{av_0}'^{1}=({P_{as_0}''}*{P_{as_0}'''})^{\frac{1}{2}}$  
$amount_{out}$  $y*P_{av_0}$  $y*P_{av_0}*P_{av_0}'^{1}$ 
To symplify the calculation, we further define the parameter $M$:

$M = P_{av_0}*P_{av_1}' = P_{av_0}*P_{av_0}'^{1}$
$M$ is the product of trading prices of step 1 and step 3 defined in the above table. (De)allocation fee applies only if $M>1$, which indicates profit is gained from the above arbitrage.

$AER$
Arbitrage earning rate  the earning rate of (de)allocating $D$ $token_0$ or $D/P_{as_0}$ $token_1$ during the above arbitrage, assuming a swap of $y$ $token_0$ was initiated.
A trader will benefit $y*(M1)$ $token_0$ from the above arbitrage. Therefore
$AER = \begin{cases} \frac{y*(M1)}{D}, & token_0 (de)allocated \\ \frac{y*(M1)}{D/P_{as_0}}, & token_1 (de)allocated \\ \end{cases}$
To discourage the harmful arbitrage, the (de)allocation fee should be charged in a way to cancel out $AER$. Therefore, to calculate the (de)allocation fee, we need to express the maximal value of $AER$ in known parameters. Since the starting point of (de)allocation in the above arbitrage is when a swap of $token_0$ is finished, the maximal value of $AER$ should be expressed with the known parameters at the point the swap is finished. Below we list the relation for some parameters before and after the swap to ease the calculation of (de)allocation fees.
 Liability: $L_0 = L_0', L_1 = L_1'$
 Assets: $A_0 = A_0'y, A_1 = A_1'+y*P_{av_0}$
 RAS: $RAS_0 = RAS_0', RAS_1 = RAS_1'$ (See Reasonable Swap Amount for details.)
Before we get into the calculation of (de)allocation fees, we express $M$, $M^{2}$ and $M^{2n}$ in terms of ratio of assetliability ratios to ease the subsequent calculation.
$M = P_{av_0}*P_{av_0}'^{1} = (\frac{P_{as_0}*P_{as_0}'}{P_{as_0}''*P_{as_0}'''})^{\frac{1}{2}}$
$M^{2} = \frac{P_{as_0}*P_{as_0}'}{P_{as_0}''*P_{as_0}'''} = \frac{1*\frac{P_{as_0}'}{P_{as_0}}}{\frac{P_{as_0}''}{P_{as_0}}*\frac{P_{as_0}'''}{P_{as_0}}} = (\frac{r_{alr_0}'}{r_{alr_0}})^{\frac{1}{n}} * (\frac{r_{alr_0}''}{r_{alr_0}})^{\frac{1}{n}} * (\frac{r_{alr_0}'''}{r_{alr_0}})^{\frac{1}{n}}$
$M^{2n} = (\frac{r_{alr_0}'}{r_{alr_0}}) * (\frac{r_{alr_0}''}{r_{alr_0}}) * (\frac{r_{alr_0}'''}{r_{alr_0}})$
3. Fee Calculation for the 4 (de)allocation patterns
The fees are only needed when the transactions take place within the first segment of the price adjustment curve, beyond which price penalty will turn the arbitrage invalid. Therefore the following condition holds:
$y \leqslant (RAS_0'+ A_0'L_0')$
Within the range of $RAS$ (see Reasonable Swap Amount for details), the (de)allocation fee is typically in the range of 0.0001%  0.02% of the amount of token to sell, depending on how close the current $ALR$ is to $RAS$. Note that in the following calculation, all the (de)allocation charge is expressed in the amount of the token to be (de)allocated.
3.1 $alr_0' > 1$, Deallocate $token_0$
$\frac{r_{alr_0}'}{r_{alr_0}} = \frac{1+\frac{y}{A_0}}{1y*P_{av_0}/A_1}$
$\frac{r_{alr_0}''}{r_{alr_0}} = \frac{1+\frac{y}{A_0}\frac{D}{A_0}}{1y*P_{av_0}/A_1}*\frac{1}{1\frac{D}{L_0}}$
$\frac{r_{alr_0}'''}{r_{alr_0}} = \frac{1+\frac{y}{A_0}(1M)\frac{D}{A_0}}{1}*\frac{1}{1\frac{D}{L_0}}$
$M^{2n} = \frac{1+\frac{y}{A_0}\frac{D}{A_0}}{1+\frac{y}{A_0}}*(1+\frac{y}{A_0}(1M)\frac{D}{A_0})*\frac{1}{(1\frac{D}{L_0})^2}\leqslant (\frac{1\frac{\frac{D}{A_0}}{1+\frac{y}{A_0}}}{1\frac{D}{L_0}})^2$