ACoconutSwap/acSwap is a decentralized exchange for ERC20 BTC tokens. It manages a basket of ERC20 BTC tokens, including WBTC and renBTC, and bootstraps the value of acBTC.
acSwap is built on top of the infamous StableSwap algorithm which originated from Curve.fi. Unlike Curve.fi where users can deposit underlying tokens into swap and receive LP tokens which represent shares of the swap pool, acSwap users receive acBTC which is a synthetic ERC20 BTC token. acBTC can maintain good peg with native BTC and is not affected by the price fluctuation of the underlying ERC20 BTC tokens.
Users can mint new acBTC by depositing any amount of ERC20 BTC tokens, which is similar to adding liquidity into Curve.fi’s swap pool.
After receiving the deposited ERC20 BTC tokens, acSwap computes the value of D before and after the deposit, noted as D1 and D2, according to the StableSwap invariant. acSwap then mints (D2 - D1) new acBTC to the user.
acSwap defines a parameter named mint fee, which is the proportion charged in minting new acBTC. Since all transaction fees in acSwap are charged with acBTC, if the mint fee is non-zero, acSwap subtracts the fee out of the minted acBTC and forwards it to the fee recipient of acSwap(i.e. acVault).
Currently, the mint fee is zero which means that users are not charged in minting new acBTC.
Users can redeem their acBTC to reclaim underlying ERC20 BTC tokens. acSwap defines three ways to redeem acBTC:
- Users define the number of acBTC to redeem as well as the minimum number of underlying tokens to receive. It’s also called proportional redemption as users will get a combination of all underlying tokens according to the current basket composition;
- Users define the number of acBTC to redeem, and want to redeem to a single token. Users can define the minimum number of tokens to receive. It’s also called single-asset redemption;
- Users define the number of underlying tokens to receive as well as maximum acBTC to burn.
In either case, the amount of acBTC to burn should be equal to the change of value D after withdrawing the underlying tokens.
acSwap defines a parameter named redeem fee, which is the proportion charged in redeeming acBTC. Since all transaction fees in acSwap are charged with acBTC, if the redeem fee is non-zero, acSwap subtracts the fee before redeeming the remaining acBTC to underlying tokens.
Currently, the redemption fee is set to 0.1%.
Similar to Curve.fi, acSwap allows swap between any pair of underlying ERC20 BTC tokens. acSwap ensures that the value D is unchanged before and after the swap.
acSwap defines a parameter named swap fee, which is the proportion charged in swapping underlying tokens. If the swap fee is non-zero, it’s subtracted from the output token so that the output amount is slightly less than what’s expected to return.
Currently, the swap fee is set to 0.02%. Since Curve.fi has a protocol fee of 0.04% while 50% of the fee is subtracted for administrative purposes, LP’s expected return becomes 0.02% without locking CRV tokens. Therefore, a swap fee of 0.02% combined with a redemption fee of 0.1% ensures that LP receives no less fees from the acSwap pool than from Curve.fi, while acSwap users can enjoy an even lower protocol fee.
Both mint and redeem fees are collected as acBTC and forwarded to acVault right in the mint and redeem transaction. For swap fee, in order to minimize gas cost, they are not converted into acBTC in the swap transaction. Instead, acSwap is sending less output tokens than the expected amount. This effectively makes the swap token balance slightly more than the cached token balance in the contract.
To collect swaps in acBTC, a periodic invocation of collectFee() method on acSwap is required to compute the difference between swap token balance and the cached token balance, updates the cached token balance and mints acBTC as fee out of the token balance difference.