Fees are used to optimize user experience and platform performance, as well as ensuring the integrity and efficiency of swapping.

CURRENTLY IN TESTNET — Should be updated when in mainnet

Swapping

Fees from each swap is deducted by the incoming token quantity.

Liquidity provider (LP) fees are calculated and the incoming token quantity gets adjusted by subtracting the fee from the total quantity:

Let $LPF$ be LPFeePercentage.

Let $Q$ be incomingQtyFeeAdjusted.

Let $T_q$ be transfer.qty.

Let $F_q$ be feeQty.

$$ fee=LPF $$

$$ Q = T_q * \frac{(100 - fee)}{100} $$

$$ F_q = T_q - Q $$

  -- LP fee
  local fee = pool.getLPFeePercentage()

  -- fee adjusted incoming token qty
  local incomingQtyFeeAdjusted = transfer.qty * (100 - fee) / 100

  -- the quantity of tokens sent to the LPs as fees
  local feeQty = transfer.qty - incomingQtyFeeAdjusted

Fee amount is returned and is also printed out in a JSON-encoded message:

-- return result
  ao.send({
    Target = message.From,
    Action = "Order-Confirmation",
    ["From-Token"] = transfer.process,
    ["From-Quantity"] = tostring(transfer.qty),
    ["To-Token"] = outputToken,
    ["To-Quantity"] = tostring(outputQty),
    Fee = tostring(feeQty)
  })
  print(json.encode({
    result = "Swapped tokens",
    from = {
      token = transfer.process,
      quantity = transfer.qty
    },
    to = {
      token = outputToken,
      quantity = outputQty
    },
    fee = feeQty
  }))