Liquidity Provider Fees

There is a 0.3% fee for swapping tokens. This fee is split by liquidity providers proportional to their contribution to liquidity reserves. Swapping fees are immediately deposited into liquidity reserves. This increases the value of liquidity tokens, functioning as a payout to all liquidity providers proportional to their share of the pool. Fees are collected by burning liquidity tokens to remove a proportional share of the underlying reserves. Since fees are added to liquidity pools, the invariant increases at the end of every trade. Within a single transaction, the invariant represents token0_pool * token1_pool at the end of the previous transaction.
The 0.3% fee is automatically applied to all swaps and distributed to liquidity providers based on their proportional share of the pool.

How Fees Work

When a user swaps tokens on Shibaswap v1:
  1. Fee Calculation: A 0.3% fee is calculated on the input amount
  2. Fee Distribution: The fee is added to the liquidity reserves
  3. LP Token Value: This increases the value of all LP tokens in the pool
  4. Proportional Rewards: Each liquidity provider receives rewards proportional to their share
// Example: Swapping 1000 DAI for ETH
uint256 inputAmount = 1000 * 10**18; // 1000 DAI with 18 decimals
uint256 feeAmount = inputAmount * 3000 / 1000000; // 0.3% fee
uint256 amountAfterFee = inputAmount - feeAmount;

// The feeAmount stays in the pool, increasing LP token value

Protocol Fees

At the moment there are no protocol fees in Shibaswap v1. However, it is possible for a 0.05% fee to be turned on in the future.
Protocol fees would be separate from liquidity provider fees and would be collected by the protocol itself, not distributed to liquidity providers.

Protocol Charge Calculation

In the future, it is possible that a protocol-wide charge of 0.05% per trade will take effect. This represents ⅙th (16.6̅%) of the 0.30% fee. The fee is in effect if feeTo is not address(0) (0x0000000000000000000000000000000000000000), indicating that feeTo is the recipient of the charge. This amount would not affect the fee paid by traders, but would affect the amount received by liquidity providers. Rather than calculating this charge on swaps, which would significantly increase gas costs for all users, the charge is instead calculated when liquidity is added or removed.
// Check if protocol fees are enabled
function feeTo() external view returns (address) {
    return _feeTo;
}

// Protocol fee calculation (0.05% = 500 / 1000000)
uint256 protocolFee = amount * 500 / 1000000;

Fee Implementation Details

Factory Contract

The Factory contract manages protocol fees through the feeTo and feeToSetter addresses:
// Address that receives protocol fees
address public feeTo;

// Address that can change feeTo
address public feeToSetter;

// Protocol fee calculation
function getProtocolFee() public view returns (uint256) {
    return feeTo != address(0) ? 500 : 0; // 0.05% if enabled
}

Pair Contract

The Pair contract handles fee collection during swaps:
// Fee constants
uint public constant FEE_DENOMINATOR = 1000000;
uint public constant SWAP_FEE = 3000; // 0.3%

// Calculate swap fee
function getSwapFee(uint256 amountIn) public pure returns (uint256) {
    return amountIn * SWAP_FEE / FEE_DENOMINATOR;
}

// Calculate amount after fees
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) 
    public 
    pure 
    returns (uint256 amountOut) 
{
    require(amountIn > 0, 'Shibaswap: INSUFFICIENT_INPUT_AMOUNT');
    require(reserveIn > 0 && reserveOut > 0, 'Shibaswap: INSUFFICIENT_LIQUIDITY');
    
    uint256 amountInWithFee = amountIn * (FEE_DENOMINATOR - SWAP_FEE);
    uint256 numerator = amountInWithFee * reserveOut;
    uint256 denominator = reserveIn * FEE_DENOMINATOR + amountInWithFee;
    
    amountOut = numerator / denominator;
}

Fee Distribution Mechanics

For Liquidity Providers

  1. Automatic Distribution: Fees are automatically distributed to all LP token holders
  2. Proportional Rewards: Rewards are proportional to LP token ownership
  3. Compounding Effect: Fees compound over time, increasing LP token value
  4. No Claiming Required: No manual claiming process needed

For Traders

  1. Transparent Pricing: Fees are included in swap calculations
  2. Slippage Protection: Set minimum output amounts to account for fees
  3. Gas Efficiency: Fees are calculated efficiently to minimize gas costs
When calculating expected output amounts, always account for the 0.3% fee. The SDK provides helper functions to calculate amounts with fees included.

Fee Optimization

For Traders

  • Batch Transactions: Combine multiple swaps to reduce total fees
  • Optimal Routes: Use the SDK to find the most efficient swap paths
  • Slippage Settings: Set appropriate slippage tolerance to avoid failed transactions

For Liquidity Providers

  • Long-term Holding: Hold LP tokens longer to benefit from fee compounding
  • High-Volume Pairs: Focus on pairs with high trading volume for more fee income
  • Impermanent Loss: Consider impermanent loss vs. fee income
Always verify fee calculations in your smart contract integrations. Incorrect fee handling can lead to failed transactions or unexpected results.

Fee Comparison

ProtocolSwap FeeLP FeeProtocol Fee
Shibaswap v10.3%0.3%0% (potential 0.05%)
Uniswap v20.3%0.3%0% (potential 0.05%)
SushiSwap0.3%0.25%0.05%
Shibaswap v1 currently has the same fee structure as Uniswap v2, with all fees going to liquidity providers.