Skip to content

Commit ce830b9

Browse files
committed
docs wip
1 parent 0bdc428 commit ce830b9

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,45 @@ Since the level of acceptable borrowing risk is not be the same for every user,
3636

3737
Maglev is a contract designed to be used as an [EVC operator](https://evc.wtf/docs/whitepaper/#operators). This means that the user, known as the *holder*, does not give up control over their funds to a smart contract, but instead retains it in their wallet. The holder can be any compatible address, including standard multisig wallets or even an EOA.
3838

39-
FIXME owner
40-
4139
### Usage
4240

4341
The following are the high-level steps required to use Maglev:
4442

4543
* Deposit funds into one or both of the vaults in proportion of the initial price
4644
* Deploy the desired Maglev contract, choosing parameters such as the vaults, debt limits, and the desired `fee`
45+
* Note
4746
* Install the Maglev contract as an operator for your account
48-
* Invoke the `configure()` function on the Maglev contract
47+
* Invoke the `configure()` function on the Maglev contract. This function can be invoked by anyone, and it is harmless to re-invoke it.
4948

5049
At this point, anyone can invoke `swap()` on the Maglev contract, and this will perform borrowing and transferring activity between the two vaults.
5150

5251
### Reconfiguration
5352

54-
All user-configurable parameters are stored in immutable variables, meaning they cannot be changed after the AMM is deployed. Instead, the AMM should be uninstalled as an EVC operator, and a new Maglev instance should be created and installed in its place.
53+
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.
5554

56-
In order to temporarily disable a Maglev instance, `pause()` and `unpause()`
55+
### Debt Limits
5756

58-
### Fees
57+
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.
5958

60-
FIXME
59+
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.
6160

62-
### Virtual Reserves
61+
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.
6362

64-
The initial deposits in the vaults represent the initial investment, and are swapped back and forth in response to swapping activity. In a conventional AMM such as Uniswap, these balance are called *reserves*. However, if swapping was constrained to these assets alone, then this would imply a hard limit on the size of swaps that can be serviced. To increase the effective funds, Maglev AMMs are configured with *virtual reserves*. These are typically larger than the size of the conventional reserves, which signifies that not only can all the assets be swapped from one vault to another, but even more assets can be borrowed on the Maglev's account.
63+
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.
6564

66-
Virtual reserves control the maximum debt that the Maglev contract will attempt to acquire on each of its two vaults. Each vault can be configured independently.
65+
Each vault can have its own independent debt limit, which may be useful in case of vaults configured with asymmetric LTVs.
6766

68-
For example, if the initial investment has a NAV of $1000, and virtual reserves are configured at $5000 for each vault, 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 select a maximum LTV that is below the borrowing LTV of the vault.
67+
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.
6968

70-
Note that it depends on the [curve](#curves) if the maximum LTV can actually be achieved. A constant product will only approach these reserve levels asymptotically, since each unit will get more and more expensive. However, with constant sum, this LTV can be achieved directly.
69+
### Desynchronised Reserves
7170

72-
### Desynchronised Virtual Reserves
73-
74-
The Maglev contract tracks what it believes the reserves to be by caching their values 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 balances may get out of sync. This can happen gradually as interest is accrued, or suddenly if the holder moves funds or the position is liquidated.
71+
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 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.
7572

7673
When this occurs, the `syncVirtualReserves()` should be invoked. This determines the actual balances (and debts) of the holder, and adjusts them by the configured virtual reserve levels.
7774

75+
### Fees
76+
77+
FIXME
7878

7979

8080
## Curves
@@ -93,6 +93,11 @@ This is the traditional Uniswap2 curve that preserves the product of the two res
9393

9494

9595

96+
## Todo
97+
98+
* Can/should current reserves be calculated dynamically based on balances/debts/debt limits?
99+
100+
96101
## License
97102

98103
(c) 2024 Euler Labs Ltd.

TODO

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
* pause guardian
2-
* events
1+
! events
32
* reserve change on each swap
3+
! Better revert messages when a swap cannot be satisifed due to debt-limit/utilisation/etc
4+
* currently it's an arithmetic underflow
45
* ConstantSum: incorporate price multipliers in quote methods
56
* natspec
67
* permit2 instead of regular approval: measure gas savings
7-
? onlyEVCAccountOwner
8-
? should uniswapV2Call take _msgSender instead of msg.sender?
9-
- I think no, since swap isn't intended to be EVC-compatible
10-
? alternate curves
11-
? registry contract
12-
? transparent proxy so AMM address can stay constant
8+
? pause guardian
9+
? how should aggregators find instances
10+
? registry contract
11+
? fake registry contract that looks at the actually installed operators for a list of accounts
12+
? transparent proxy so AMM address can stay constant
1313

1414
docs
1515
low-level detail of how system works for auditors
1616
how to add a curve
1717
information for aggregators
1818
how to maintain quotes off-chain, including tracking cash from VaultStatus logs of underlying vaults
19+
note how EVK stores balance and debt in same storage slot
1920

2021
tests
2122
prices/alternate decimals
2223
especially quoting
2324
when exchange rate in vaults != 1
2425
uniswap callback, flash swaps
2526
hitting reserve/utilisation limits
26-
changing reserves
27-
changing fees/prices
28-
onlyOwner methods can't be called by others

0 commit comments

Comments
 (0)