How bridging and swap fees at Synapse Protocol work.
What is a Stableswap, exactly?
Let us assume we are already familiar with Uniswap AMM model:
x * y = k. (learn more here) This model is simple and effective, allowing the prices of the assets in the pool to track supply and demand. However, if we were to attempt a swap that was large relative to the liquidity in the pool, we would get rekt by slippage. Stableswaps are a mathematical improvement that optimize the model for assets that are intended to have prices that remain stable relative to one another. Because of this, stableswap pools can also contain more than two assets, unlike your traditional Uniswap AMM pool. Instead of the simple
x * y = kmodel, a special function
F(a, b, c, ...)is used to relate the prices of the assets contained in a stableswap. This function is more complex, and can also have more than two parameters (as shown by a, b, c, etc.) but the exact formula is not necessary in order to discuss how this model affects the protocol's fee structure.
Let us do so by way of an example. Suppose the stableswap pool has three assets, ACash, BCash, CCash, with the respective balance of each token in the AMM pool represented by A, B, and C, such that
F(A, B, C) = k. Let us say we want to swap x tokens of ACash to CCash. The Pool's new ACash balance is A + x, so now we need to find y, the amount of CCash that we will receive. This is found by solving
F(A + x, B, C - y) = k.
How do fees work?
Let us use an example to describe fees - if the swap fee is 0.04%, that means that 0.04% of y (or CCash, in this example) will be fees and 99.96% of y will be sent to us as a result. We sent x tokens of ACash, received 99.96% * y tokens of CCash, and 0.04% * y tokens of CCash were paid as fees. Swap complete! Notice that the stableswap fee is applied to received assets. In addition, some percentage of this fee is generally reserved for the protocol as an admin fee. This fee can range from 0 to 100%, is applied only to the fee paid on the swap, and does not impact the user performing the swap. It does directly impact how much liquidity providers (LPs) earn from swaps in that pool. For instance, if the admin fee is 60%, the treasury will receive 0.04% * 0.6 * y, and LPs will receive 0.04% * 0.4 * y from this transaction.
How its LPs interact with pools When LPs deposit assets, they receive LP tokens in exchange for their deposit. When a stableswap pool is initialized, each LP token is worth ~1 token of A/B/C, on average. As swaps are performed using the liquidity in the pool, fees from those swaps accrue to the pool. This results in the LP tokens contained in that pool gaining value versus the assets which were deposited. This gain can be quantified by the "virtual price" of each LP token, which increases from a baseline value of 1 as more fees come in. For example, if the virtual price of an LP token is 1.01, that means 1 LP token is worth 1.01 A, B, or C token - in other words, a 1% return on initial deposits.
Mechanics of Depositing
So what happens when we deposit assets into an existing stableswap pool? We can deposit a single asset, or a mix of the assets contained within. Because the pool needs to remain balanced to maintain
F(A, B, C) = k, a deposit actually combines two actions behind the scenes. First, a "virtual swap" is made for us. A virtual swap is made to make the proportion of your supplied assets equal to the ideal proportions of the pool. This means that some of the tokens you deposit are swapped into the other tokens in the pool such that the pool is more balanced after your deposit, regardless of the mix of tokens you deposit.
The fee for the "virtual swap" associated with such a deposit is on average 50% of the usual swap fee, but will depend on the balance of assets in the pool at the time of deposit. Our swapped set of tokens is now deposited into the pool, with no adverse effects on pool balance. Note: If we were to supply a perfectly balanced proportion of [d, e, f] in the first place then no swap would be made and no fees would be charged on deposit.
Mechanics of Withdrawls
Withdrawls function with the same logic, in the reverse direction. Now the mix of tokens is what we will receive, if we withdraw a combo of all three assets. If we want to withdraw only asset x, the other assets part of the basket are "virtually swapped" for the desired asset. We will receive y tokens of the desired asset, and will have to pay fees on this "virtual swap" to do so since it results in the pool becoming unbalanced. The fee associated with withdrawal is also 50% of the usual swap fee, on average, but will again depend on the balance of assets in the pool at the time of deposit. Note: This means if we deposit a single asset in the pool and immediately withdraw liquidity as a different single asset, on average we will pay 50% + 50% = 100% of the usual swap fee. No free swaps!
There are two types of Synapse nUSD pools. There is the "nexus" pool on Ethereum, and there are other nUSD pools that can be found here. The nexus pool is a basic stableswap pool of USDC, USDT, DAI. The LP token for this pool is nUSD, itself, and can be bridged to other chains: whenever a user bridges a stable from Ethereum to another chain, he deposit the stable into the nexus pool on Ethereum and a nUSD token is minted, on the chain he wants to bridge to. The nUSD pools on other chains include nUSD and the base stables on that chain: for example USDC.e, USDT.e and DAI.e on Avalanche.
Given that, what do a bridge transactions look like in terms of the pools and assets used? Let us look at some examples:
- 1.Bridging Avalanche USDC.e to BNB Chain BUSD
- 1.Avalanche USDC.e is swapped for Avalanche nUSD
- 2.Avalanche nUSD is bridged to BNB Chain nUSD (in practice, it is burn on Avalanche and minted back on BNB Chain)
- 3.BNB Chain nUSD is swapped for BNB Chain BUSD.
- 2.Bridging ETH USDT to Avalanche USDC.e
- 1.ETH USDT is supplied to the nexus pool in exchange for nUSD
- 2.ETH nUSD is bridged to Avalanche
- 3.Avalanche nUSD is swapped for Avalanche USDC.e.
- 3.Bridging Avalanche USDC.e to ETH USDC
- 1.Avalanche USDC.e is swapped for Avalanche nUSD
- 2.Avalanche nUSD is bridged to ETH nUSD
- 3.ETH USDT is withdrawn from the nexus pool.
Alright, prepare for some math. Let us divide all Synapse fees into these categories:
a% = swap fee for the "base pools" (nUSD pool on Ethereum, USD-LP on non-Ethereum chains) b% = bridge fee for nUSD from any chain to any other chain
So, what are the costs for the following actions?
- 1.Bridging USDT from Ethereum to non-Ethereum chains (or vice versa)
- 1.ERC-20 USDT is supplied to the nexus pool -> 0.5 * a%
- 2.nUSD is bridged from Ethereum -> b%
- 3.nUSD is swapped for USDT on that chain -> a% Total = (1.5a + b)% charged in fees
- 2.Bridging USDT from non-Ethereum chains to non-Ethereum chains
- 1.Local USDT is swapped for nUSD -> a%
- 2.nUSD is bridged to other chain -> b%
- 3.nUSD is swapped for USDT -> a% Total = (2a + b)% charged in fees
- 3.Swapping USDT for USDC on the same chain
- 1.USDT swapped for USDC -> a% Total: a%
As you can see, the most expensive swap you can make is to swap between stables on non-Ethereum chains - this is because the bridged asset and nUSD must be swapped twice when bridging between non-Ethereum chains but can swapped directly into stables when bridging from or to Ethereum.
Please note that these are average fees, assuming that the pool is balanced already or assuming that enough transactions are occurring that such imbalances even out over time. It is possible to get discounted fees or even get paid for swapping or bridging into assets that are over-supplied; conversely, it can be more expensive than average to swap into a specific asset on a different chain if it is under-supplied. Pay attention to the price impact monitor - it is your friend!