Lesson 4 - Open/Close Positions With 0 Swap Fees
Last updated
Last updated
This is a pro tip but it isn’t complicated. The only thing necessary for doing this is some reserve capital. As long as you have that, you’ll soon be able to open and close leveraged yield farming positions of any size with 0 trading fees and 0 price impact.
Let’s preface a bit by going over how swapping when opening and closing a leveraged position works. If you already understand this, you can skip ahead to the next section.
When opening a farming position using > 2x leverage, you are borrowing more tokens than you are depositing as collateral. Since the integrated DEX you’ll be farming on needs the tokens in your pair to be in a 50:50 ratio, Alpaca has to swap a portion of the borrowed tokens into non-borrowed tokens to achieve this split.
Likewise, when closing a position with >2x leverage, Alpaca has to do this in reverse to pay back the borrowed tokens. So the protocol removes the liquidity and swaps some of the non-borrowed token into the borrowed tokens, and returns those borrowed tokens to the lending pool. Below is an example.
Joe deposits 10k BUSD as collateral in the BUSD-USDT pool and chooses to open a 4x leveraged yield farming position, borrowing USDT.
The protocol loans him 30k USDT. Now, he’s holding 10k BUSD + 30k USDT, but he needs these in a 50:50 ratio. So Alpaca sells 10k USDT -> BUSD, which makes his Position Value 20k BUSD + 20k USDT.
Joe starts farming and earning yields.
Sometime in the future, Joe decides to close his position. He owes Alpaca 30k USDT(he also owes accumulated borrowing interest but we will forego including that here, in order to simplify this example). Yet, Joe’s position consists of only 20k USDT + 20k BUSD. As a result, Alpaca has to sell back 10k BUSD -> USDT, bringing his position to his original 10k BUSD + 30k USDT.
5. Alpaca pays back the 30k USDT from Joe to the lending pool and closes his position. Joe receives 10k BUSD + the yields he’s earned thus far.
Simple enough, right? However, unfortunately for Joe, each of those swaps has some costs: trading fees and price impacts. While these are a small % of his added 10k collateral, for large positions, they can be quite substantial.
Luckily, we can show anyone how to avoid these swap fees both when opening and closing positions! This is possible because of two features we’ve added recently:
Partial Closing: You can now remove collateral from a position, while having an option to return some debt, or not. We’ve just added this.
Adjust Position: You can now add collateral to an open position, while having the option to borrow more funds to maintain your leverage, or not. We added this some weeks ago.
Now, let us show you how to use the above features to open and close positions without any fees.
Say you want to deposit 10k BUSD into a BUSD-USDT farming position like Joe did earlier, using 4x leverage and borrowing USDT.
The straightforward way would be to deposit the 10k BUSD and borrow 30k USDT. The protocol would then swap 10K USDT->BUSD to give you a 50:50 ratio. However, as Joe did before, you’d incur trading fees and price impact costs.
To avoid these costs is actually quite simple though. It involves taking advantage of the Partial Closing feature. For this, you’ll need some spare capital. How many spare funds you’ll need at the start will be exactly the same as how many funds you want to borrow from the protocol for your chosen final position, but in the non-borrowed asset. In the above case, you would be borrowing 30k USDT at 4x. So you will also need a corresponding 30k BUSD on hand in order to open a 4x position with 10k BUSD collateral, with no fees.
(1) Now, what you’re going to do is borrow that same 30k USDT, but open the position at 2x. In other words, your starting position will be 30k BUSD collateral + 30k USDT borrowed.
At 2x, as long as you deposit 100% of your collateral as the non-borrowed asset(BUSD), then when the protocol loans you the borrowed asset(USDT), no swap fees will be necessary because the tokens will already be in a 50:50 ratio.
However, this is only the first step. After all, you want a 4x position, right?
(2) So after your position is opened, what you do next is click the Close Position button in the Your Positions dashboard.
There, you can use the new Partial Closing feature at the top left. Also make sure that you are selecting the Minimize Trading strategy.
(One thing that’s important you keep in mind is that once your position was opened, the protocol stopped differentiating between the collateral you added and the tokens you borrowed. This is relevant for the next step.)
(3) Next, without borrowing more, you will select to remove 33.33% of your Position Value (20k total: 10k BUSD+10k USDT) until what remains in the position is 20k BUSD + 20k USDT.The numbers are slightly off due to BUSD:USDT not having been exactly 1:1 at position opening. USDT was worth slightly more than BUSD while making this tutorial.
After you receive 10k BUSD and 10k USDT, you can open more 2x position using 10k BUSD, and partially close the position by removing 3.3k BUSD and 3.3k USDT to make the position 4x leverage as intended. You can loop like this until the leftover fund is minimal.
(4) You will also select to not pay back any debt.
As you can see at the bottom right of the image above, your position will become close to 4x, with slight variation being the result of rounding and asset price movements while making this tutorial.
The most important thing, however, is that to perform this partial close in this manner and convert this position to 4x, you will pay no swap fees!
Because you’ll remove collateral in a 50:50 ratio and your remaining position will have a 50:50 ratio, no swaps will occur. As a result, your position will be the exact same as if you had opened it by depositing 10k BUSD and borrowing 30k USDT, allowing the protocol to swap 10k USDT->BUSD for you. You’ll have the exact same long/short exposures too. Except now, there will be no swaps! You’ll open this position with 0 trading fees and 0 price impact!
Pretty cool, right? So what are you waiting for? Go ahead and press the Close Position button at the bottom right!
Once you’ve finished that, congratulations, you’ve opened your 4x position with no swap fees.
However, we know what you might be thinking:
Ok, I’m in this position and that’s great, but won’t I still have to pay swap fees when I pay back the 30k USDT?
The answer is no! You won’t! Not if you do the exact thing you did above, but in reverse!
You can also efficiently open a position with 0 swap fees and price impact without needing spare funds by looping as follows:
After you receive 10k BUSD and 10k USDT from Step 3, you can open more 2x position using 10k BUSD, and partially close the position by removing 3.3k BUSD and 3.3k USDT to make the position 4x leverage as intended. You can loop like this until the leftover fund is minimal.
Pros:
You can open the position with 0 swap fees and price impact with minimal spare funds left.
Cons:
You need to open many positions instead of just one to loop the funds meaning more gas fee will be incurred.
The leverage will not be exactly as intended.
Continuing from the previous position, you’re in a 4x BUSD-USDT position where you deposited 10k BUSD as collateral. Your position consists of 20k BUSD + 20k USDT, but you owe the protocol 30k USDT.
You can’t use partial closing anymore to remove collateral because you’re already at max leverage. So typically, you’d close the entire position here. Yet, if you do so directly, the protocol will have to sell 10k BUSD -> USDT in order to have the 30k it needs to pay back the lending pool.
What can you do?
The answer is: you follow the same process as when you opened a position with 0 swap fees, but in reverse. The only difference this time is that instead of using Partial Closing, we’ll be using the feature Add Collateral.
(1) Here’s what you do. On the Your Positions dashboard, click the Adjust Position button.
Now, what you’re going to do is return your position from 4x -> 2x leverage. The simple way to do that is to add collateral. At the moment, you have 10k BUSD collateral(Equity Value) and are borrowing 30k USDT in a Position Value of 40k total. So what you have to do is add collateral until you have 30k collateral + 30k borrowed; a total Position Value of 60k. (Notice this is the same as when you first opened your position in the previous section 😉)
You have to make sure to add an equal amount of collateral to both assets in order to maintain the 50:50 ratio or the protocol will have to perform swaps. From the last section, if you still have that 10k BUSD + 10k USDT you withdrew from your position, that will come in very handy now because that’s exactly what you need.
So add collateral of 10k BUSD + 10k USDT, without borrowing anything, and your position will become 30k BUSD + 30k USDT — a 2x position.
(2) Now, all you have to do is click the Back button. Then go to Close Position, and fully close your 2x position using Minimize Trading, and you will incur no swap fees!
Congratulations, you opened and closed a leveraged yield farming position, earning those juicy yields with 0 fees!
What if I want to open or close a 4x position with 10k BUSD collateral, and no fees, but I don’t have another 20k in spare stablecoins?
There’s a solution to that as well, or a bit of a workaround. Let’s say you only have 10k BUSD total. To utilize almost all of that in 4x positions but not pay fees, you can do the following:
Following the earlier instructions, open a 4x position without fees with 3k BUSD collateral (9k total required, 6k remaining after)
Open a 4x position without fees with 2k BUSD collateral (6k total required, 4k remaining after)
Open a 4x position without fees with 1.3k BUSD collateral(3.9k total required, 2.7k remaining after)
And so on…
Eventually, you will have deployed most of your 10k in 4x positions. To close them, you just work backwards, closing the smaller positions first as your spare capital grows and you’re able to close all of them.
Some of you may have noticed one issue between the above steps 1 and 2 which is that when you finish step 1, you’ll have 3k BUSD and 3k USDT, so since you need 6k BUSD, how that does work?
Well, you have a few ways to deal with this if you’d like to minimize your swap fees.
First, you can swap stables cheaply on a stablecoin exchange like https://belt.fi/. A stablecoin exchange like this has lower trading fees than a DEX like PancakeSwap.
For other tokens, you can trade them on centralized exchanges if you absolutely want to get the cheapest rates, or use a decentralized aggregator like 1inch and partition your trades down into multiple smaller ones.
If you don’t want to trade at all, another option is to use a smaller amount for step 2; You can use 1k BUSD as collateral, and decrease the sizes of your follow up positions to be 1/3 of the previous one. Of course, in this way, you’ll still end up with unused USDT at the end, but you’ll utilize about half of your total capital rather than 1/3. In this scenario, with the spare USDT, you can also choose to then open a BUSD-USDT position borrowing BUSD instead. It can get a bit tiresome switching around like this 😅 but if you don’t have spare capital and absolutely don’t want to pay swap fees, this is what you can do.
Now, we’ve shown you how to open and close positions of any size, without fees. Some of you may be thinking:
This is great! But why doesn’t Alpaca automate this for me?
Well, the answer is: we can’t because to do this requires reserve capital and the protocol can’t access reserve capital that’s sitting in your wallet. We’re decentralized and non-custodial, after all. So we can only instruct you on how to do this on your own. However, as you can see, it isn’t complicated. It only requires some reserve funds on hand, or even no reserve funds if you’re willing to do some extra steps. Then, you can have positions of any size, with no entry or exit costs, and farm high yields!
Besides opening and closing positions without fees, using the methods of adding and removing collateral with a 50:50 ratio is also a way to re-balance your positions to a desired leverage level. This can be useful if you are, for example, using a pseudo delta-neutral strategy.
So we hope you enjoy this guide and these new features. We‘re also working on ways to make processes like this even easier. For now though, happy farming.