You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-15Lines changed: 24 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3

4
4
5
-
Maglev is an Automated Market Maker (AMM) that uses [Euler Vaults](https://docs.euler.finance/euler-vault-kit-white-paper/) to *mag*nify capital efficiency using *lev*erage. By borrowing assets as needed, Maglev AMMs can extend the range of their reserves and earn fees on trades several times larger than their liquidity outlay.
5
+
Maglev is an Automated Market Maker (AMM) that uses [Euler Vaults](https://docs.euler.finance/euler-vault-kit-white-paper/) to **mag**nify capital efficiency using **lev**erage. By borrowing assets as needed, Maglev AMMs can extend the range of their reserves and earn fees on trades several times larger than their actual liquidity.
6
6
7
-
To swappers, Maglev presents a conventional Uniswap2-style interface but internally it supports custom pricing curves and other advanced functionality. Although useable by anyone, the primary swapper user-base is intended to be aggregators, intents solvers, and MEV bots.
7
+
To swappers, Maglev presents a conventional Uniswap2-style interface but internally it supports borrow and repaying, custom pricing curves, and other advanced functionality. Although invokeable by anyone, the primary swapper user-base is intended to be aggregators, intents solvers, and MEV bots.
8
8
9
9
<!-- TOC FOLLOWS -->
10
10
<!-- START OF TOC -->
@@ -22,17 +22,19 @@ To swappers, Maglev presents a conventional Uniswap2-style interface but interna
22
22
*[Constant Product](#constant-product)
23
23
*[EulerSwap Curve](#eulerswap-curve)
24
24
*[Todo](#todo)
25
+
*[See Also](#see-also)
26
+
*[Prior Art](#prior-art)
25
27
*[License](#license)
26
28
27
29
<!-- END OF TOC -->
28
30
29
31
## Concept
30
32
31
-
Given a fixed size investment, Maglev aims to increase the size of trades that can be serviced relative to a conventional AMM such as Uniswap. It does this by borrowing the "out token" and collateralising this loan with the received "in token". Later on, when somebody wishes to swap in the reverse direction, they repay the loan and receive the excess collateral, unwinding the borrow position.
33
+
Given a fixed size investment, Maglev aims to increase the size of trades that can be serviced relative to a conventional AMM such as Uniswap. It does this by borrowing the "out token" and collateralising this loan with the received "in token". Later on, when somebody wishes to swap in the reverse direction, their "in token" repays the loan and the excess collateral is sent as the "out token", thereby unwinding the position.
32
34
33
-
Because the total size of the position can be many times larger than the initial investment (depending on how much LTV/leverage is allowed on the underlying lending pools), the swap fees earned can be magnified.
35
+
Because the total size of the position can be many times larger than the initial investment (depending on how much LTV/leverage is allowed on the underlying lending pools), the swap fees earned are multiplied.
34
36
35
-
The down-side is that while the AMM holds this leveraged position, it is paying interest on the loan. Fortunately, this is partially compensated by the fact that the AMM is simultaneously earning interest on the collateral. In some cases, this interest rate spread can be reduced further by taking advantage of incentives such as points/rewards.
37
+
The down-side is that while the AMM holds this leveraged position, it is paying interest on the loan. Fortunately, this is partially compensated by the fact that the AMM is simultaneously earning interest on the collateral. In some cases, this interest rate spread can be reduced further (occasionally even going negative) by taking advantage of incentives such as points/rewards.
36
38
37
39
## Operation
38
40
@@ -46,7 +48,7 @@ The following are the high-level steps required to use Maglev:
46
48
47
49
* Deposit funds into one or both of the vaults in proportion of the initial price
48
50
* Deploy the desired Maglev contract, choosing parameters such as the vaults, debt limits, and the desired `fee`
49
-
* Note that the Maglev contract must be created after the funds are deposited, because its constructor will read the current debt and balances to setup its reserves cache
51
+
* Note that the Maglev contract must be created after the funds are deposited, because its constructor will read the current debts and balances to setup its reserves cache
50
52
* Install the Maglev contract as an operator for your account
51
53
* Invoke the `configure()` function on the Maglev contract
52
54
* This function can be invoked by anyone, and it is harmless to re-invoke it
@@ -55,27 +57,27 @@ At this point, anyone can invoke `swap()` on the Maglev contract, and this will
55
57
56
58
### Reconfiguration
57
59
58
-
All user-configurable parameters are stored in immutable variables, meaning they cannot be changed after the AMM is deployed. Instead, the holder should be uninstalled it from its EVC operator set, and a new Maglev instance should be created and installed in its place.
60
+
All user-configurable parameters are stored in immutable variables, meaning they cannot be changed after the AMM is deployed. Instead, the holder should uninstalled it from its EVC operator set, and a new Maglev instance should be created and installed in its place.
59
61
60
62
### Debt Limits
61
63
62
64
The initial deposits in the two vaults represent the initial investment, and are swapped back and forth in response to swapping activity. In order to prevent loss to arbitrage, the initial investment should be made in proportion to the price of the assets.
63
65
64
-
In a conventional AMM such as Uniswap, the balances held by the contract are called *reserves*, and these represent a hard upper-bound on the amounts that can be swapped: In other words, no matter how much you are willing to pay, you can never receive more than the current reserve.
66
+
In a conventional AMM such as Uniswap, the balances held by the contract are called *reserves*, and these represent a hard upper-bound on the amounts that can be swapped: In other words, no matter how much you are willing to pay, you can never receive more than the amount currently held in reserve.
65
67
66
68
To increase the effective swappable amounts, not only will Maglev AMMs swap all their reserves, but they will internally borrow *more* of the desired token in order to service a swap. How much debt the AMM is willing to take depends on the configured debt limits.
67
69
68
70
For example, if the initial investment has a NAV of $1000, and the debt limit is configured at $5000, then the maximum LTV loan that the AMM will support will be `5000/6000 = 0.8333`. In order to leave a safety buffer, it is recommended to choose a maximum LTV that is below the borrowing LTV of the vault.
69
71
70
-
Each vault can have its own independent debt limit, which may be useful in case of vaults configured with asymmetric LTVs.
72
+
Each vault can have its own independent debt limit, which may be useful in case of vaults configured with asymmetric LTVs. A debt limit of 0 could be specified for one of the vaults if the holder only ever wants a borrow position in one of the assets. In the future we may add a debt minimum, allowing the holder to retain a position within a certain leverage range while continuing to profit off swapping activity.
71
73
72
74
Note that it depends on the [curve](#curves) if the maximum LTV can actually be achieved. A constant product curve will only approach these reserve levels asymptotically, since each unit will get more and more expensive. With a constant sum curve, the LTV can be achieved precisely.
73
75
74
76
### Desynchronised Reserves
75
77
76
78
The Maglev contract tracks what it believes the reserves (amount available plus borrowable) to be by caching in storage. These reserves are updated on each swap. However, since the balance is not actually held by the Maglev contract (it is simply an operator), the actual underlying debts and balances may get out of sync. This can happen gradually as interest and fees are accrued, or suddenly if the holder moves funds or the position is liquidated.
77
79
78
-
Normally this is not a problem, because swapping will still occur on the static curve. However, if there is a significant decrease in NAV then the desired LTVs may be exceeded (since the debt limit becomes higher relative to the NAV). If there is a significant increase in NAV then the AMM may become less capital efficient. To reset this, the Maglev instance should be uninstalled as an EVC operator, and a new one created and installed in its place.
80
+
Normally this is not a problem, because swapping will still occur on the static curve (such actions do not change the offered prices). However, if there is a significant decrease in NAV then the desired LTVs may be exceeded (since the debt limit becomes higher relative to the NAV). If there is a significant increase in NAV then the AMM may become less capital efficient. To resynchronise, the Maglev instance should be uninstalled as an EVC operator, and a new one created and installed in its place.
79
81
80
82
### Fees
81
83
@@ -85,7 +87,7 @@ When quoting exact input swaps the effective input amount is decreased by the fe
85
87
86
88
After depositing but prior to verifying the curve invariant, all input amounts are adjusted down (rounding down).
87
89
88
-
Since the full amount including fees is actually deposited (or repayed), fees have the effect of increasing the NAV of the position. However, they are not currently "fed back" into the reserves to be used by future swaps. If fees build up significantly, the Maglev instance should be [replaced](#desynchronised-reserves).
90
+
Since the full amount including fees is actually deposited (or repaid), fees have the effect of increasing the NAV of the position. However, they are not currently "fed back" into the reserves to be used by future swaps. If fees build up significantly, the Maglev instance should be [replaced](#desynchronised-reserves).
89
91
90
92
91
93
## Curves
@@ -96,7 +98,7 @@ This "curve" simply adds the values of the two reserves together and ensures tha
96
98
97
99
This curve supports a price fraction so that the two tokens can have different relative values, which can be useful if the peg is other than 1:1, or if the tokens have differing decimals.
98
100
99
-
In this curve, the entire virtual reserves can be consumed, and since each marginal unit of the swap has the same price, there is no direct incentive to deleverage the position. However, for the same reason this does allow fixed-size fees for swaps of any supported size (fixed price impact).
101
+
In this curve, the entire virtual reserves can be consumed, and since each marginal unit of the swap has the same price, there is no direct incentive for arbitrageurs to deleverage the position. However, for the same reason this does allow fixed-size fees for swaps of any supported size (fixed price impact).
100
102
101
103
### Constant Product
102
104
@@ -106,7 +108,7 @@ This is the traditional Uniswap2 curve that preserves the product of the two res
106
108
107
109
This is a new curve developed by Euler. It can be thought of as a hybrid between constant sum and constant product. The curve is defined piecewise: A piece to the left of an "initial reserves" point, and a piece to the right.
108
110
109
-
Each piece has a `concentration` parameter that determines the trade-off between constant sum and constant product. The higher the concentration (closer to 1), the more it is similar to a constant sum, and the lower (closer to 0), constant product. The curve is also parameterise by a `price` parameter which determines the slope at the initial reserves point. There are actually two price parameters which can be considered the numerator and denominator of the price fraction.
111
+
Each piece has a `concentration` parameter that determines the trade-off between constant sum and constant product. The higher the concentration (closer to 1), the more it is similar to a constant sum, and the lower (closer to 0), a constant product. The curve is also parameterised by a `price` parameter which determines the slope at the initial reserves point. There are actually two price parameters which can be considered the numerator and denominator of the price fraction.
110
112
111
113
With careful parameter selection, the EulerSwap curve supports optimal tradeoffs between capital efficiency and arbitrage incentives.
112
114
@@ -115,15 +117,15 @@ With careful parameter selection, the EulerSwap curve supports optimal tradeoffs
115
117
## Todo
116
118
117
119
* The EulerSwap curve has some numerical instability that we believe is caused by rounding
118
-
* We think the biggest effect is that it may cause some swaps to fail even if the the quoted amount is provided. Also, it may result in users slightly overpaying for swaps.
120
+
* We think the biggest effect is that it may cause some swaps to fail even if the exact quoted amount is sent. Also, it may result in users slightly overpaying for swaps.
119
121
* The code currently has a roundingCompensation adjustment that seems to prevent this, but since we don't know a hard upper-bound it's hard to say if this solves it in all cases
120
122
* Currently we have only been supporting stable-stable pairs
121
123
* What extra considerations would there be for floating pairs?
122
124
* Automatically re-invest fees. There are a few options:
123
125
* Don't do anything: Re-deploing probably isn't a huge deal
124
126
* Increase the reserves by the fee amount
125
127
* Increase the reserves by the extra amount of possible leverage supported by the new fee
126
-
* Apply fees to a super-concentrated section of the curve (needs R&D)
128
+
* Apply fees to a super-concentrated middle section of the curve (needs R&D)
127
129
* Could current reserves be calculated dynamically based on balances/debts/debt limits?
128
130
* I guess you would lose a chunk of interest to arbitrage
129
131
* Donation attacks?
@@ -134,6 +136,13 @@ With careful parameter selection, the EulerSwap curve supports optimal tradeoffs
134
136
* Other misc stuff (see `TODO` file)
135
137
136
138
139
+
## See Also
140
+
141
+
### Prior Art
142
+
143
+
*[Blackhole swap](https://blackholeswap.com/documents/en.pdf): Essentially the same concept, but using a less optimal curve and hardcoded to two Compound pools.
0 commit comments