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
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ forge doc --serve --port 4000
50
50
51
51
## Deployment Addresses
52
52
53
-
On networks where Uniswap v4 is deployed, EulerSwap is deployed using a factory variant that creates Uniswap v4 hook compatible instances. Elsewhere, the original 'OG' version of EulerSwap factory is deployed. The deployed addresses can be found in [Contract Addresses](https://docs.euler.finance/developers/contract-addresses) section of Euler docs. To check which version is deployed, call `poolManager` on the EulerSwap implementation contract (`eulerSwapV1Implementation`). If it returns zero-address then 'OG' version is deployed.
53
+
Deployed addresses can be found in [Contract Addresses](https://docs.euler.finance/developers/contract-addresses) section of Euler docs.
54
54
55
55
## Getting Started
56
56
@@ -80,11 +80,13 @@ Note that these limits are enforced by the quoting functions, which will revert
80
80
81
81
### Creating and Decomissioning Pools
82
82
83
-
The EulerSwap pools are created by the `EulerSwapFactory` contract, which emits a [PoolDeployed](https://github.com/euler-xyz/euler-swap/blob/1f73f5cb07f2e64e8c9815076749574b1b54e204/src/EulerSwapFactory.sol#L32) event and provides functions to list existing instances.
83
+
EulerSwap pools are created by the `EulerSwapFactory` contract, which emits a `PoolDeployed` event and provides functions to list existing instances.
84
84
85
-
Pools can also be uninstalled by LPs, for example during rebalancing, in which case the factory emits a [PoolUninstalled](https://github.com/euler-xyz/euler-swap/blob/1f73f5cb07f2e64e8c9815076749574b1b54e204/src/EulerSwapFactory.sol#L34) event.
85
+
Afterwards, pools can optionally be registered in the `EulerSwapRegistry` contract, which advertises them as ready for swapping. Doing so may require the posting of a small validity bond.
86
86
87
-
However, note that EulerSwap instances are installed on top of regular accounts within the Euler lending platform—they do not control these accounts. This means an LP can abandon an EulerSwap instance simply by withdrawing their position from the lending vaults. In such cases, the factory has no indication that the pool is no longer operational, but quoting functions or swap simulations will start reverting. If a pool continually fails to return quotes or reverts in simulation, it should likely be blacklisted.
87
+
Note that EulerSwap instances are installed on top of regular accounts within the Euler lending platform. This means an LP can abandon an EulerSwap instance simply by withdrawing their position from the lending vaults. In such cases, the registry has no indication that the pool is no longer operational, but quoting functions or swap simulations will start reverting. If a pool is misconfigured and unable to fulfil swaps it is claiming via its `getLimits()` function, the bond may be forfeit and the misconfigured pool removed from the registry.
88
+
89
+
When a pool is decomissioned, it is recommended to remove from the registry in order to recover the validity bond.
Copy file name to clipboardExpand all lines: docs/architecture.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,37 +15,42 @@ Swapping can be performed by invoking the EulerSwap instance, either through a U
15
15
EulerSwap is split into the following main contracts:
16
16
17
17
*`EulerSwap`: Contract that is installed as an EVC operator by liquidity providers, and is also invoked by swappers in order to execute a swap.
18
-
*`UniswapHook`: The functions required so that the EulerSwap instance can function as a Uniswap4 hook.
19
-
*`EulerSwapFactory`: Factory contract for creating `EulerSwap` instances and for querying existing instances.
20
-
*`EulerSwapPeriphery`: This is a wrapper contract for quoting and performing swaps, while handling approvals, slippage, etc.
18
+
*`UniswapHook`: Internal contract implementing the functionality for EulerSwap instances to function as a Uniswap4 hook.
19
+
*`EulerSwapManagement`: Internal contract that implements management functionality for EulerSwap instances to reduce code size. `EulerSwap` uses delegatecall to this contract.
20
+
*`EulerSwapBase`: Internal base class used to share functionality between `EulerSwap` and `EulerSwapManagement`
21
+
*`EulerSwapFactory`: Factory contract for creating `EulerSwap` instances.
22
+
*`EulerSwapRegistry`: Registry contract for advertising `EulerSwap` instances that are available for swapping.
23
+
*`EulerSwapPeriphery`: Wrapper contract for quoting and performing swaps, while handling approvals, slippage, etc.
24
+
*`EulerSwapProtocolFeeConfig`: A contract queried to determine the protocol fee in effect for a given swap.
21
25
22
26
The above contracts depend on libraries:
23
27
24
28
*`CtxLib`: Allows access to the `EulerSwap` context: Structured storage and the instance parameters
25
29
*`FundsLib`: Moving tokens: approvals and transfers in/out
26
30
*`CurveLib`: Mathematical routines for calculating the EulerSwap curve
27
31
*`QuoteLib`: Computing quotes. This involves invoking the logic from `CurveLib`, as well as taking into account other limitations such as vault utilisation, supply caps, etc.
32
+
*`SwapLib`: Routines for actually performing swaps
*`ProtocolFee`: The factory stores protocol fee parameters that will affect subsequently created `EulerSwap` instances. These can be changed by an owner.
33
37
34
38
## Operational flow
35
39
36
40
The following steps outline how an EulerSwap operator is created and configured:
37
41
38
42
1. Deposit initial liquidity into one or both of the underlying credit vaults to enable swaps.
39
-
1. Choose the desired pool parameters (`IEulerSwap.Params` struct). The `protocolFee`and `protocolFeeRecipient` must be read from the factory.
43
+
1. Choose the desired pool parameters (`IEulerSwap.StaticParams`and `IEulerSwap.DynamicParams` structs)
40
44
1.[Mine](https://docs.uniswap.org/contracts/v4/guides/hooks/hook-deployment#hook-miner) a salt such that the predicted address of the `EulerSwap` instance will be deployed with the correct flags.
41
45
1. Install the above address as an EVC operator, ensuring that any previous `EulerSwap` operators are uninstalled.
42
46
1. Invoke `deployPool()` on the EulerSwap factory.
47
+
1. Optional: Register the pool in the EulerSwapRegistry.
43
48
44
49
## Metaproxies
45
50
46
51
Each `EulerSwap` instance is a lightweight proxy, roughly modelled after [EIP-3448](https://eips.ethereum.org/EIPS/eip-3448). The only difference is that EIP-3448 appends the length of the metadata, whereas we don't, since it is a fixed size.
47
52
48
-
When an `EulerSwap` instance is created, the `IEulerSwap.Params` struct is ABI encoded and provided as the proxy metadata. This is provided to the implementation contract as trailing calldata via `delegatecall`. This allows the parameters to be accessed cheaply when servicing a swap, compared to if they had to be read from storage.
53
+
When an `EulerSwap` instance is created, the `IEulerSwap.StaticParams` struct is ABI encoded and provided as the proxy metadata. This is provided to the implementation contract as trailing calldata via `delegatecall`. This allows the parameters to be accessed cheaply when servicing a swap, compared to if they had to be read from storage.
49
54
50
55
## Curve Parameters
51
56
@@ -78,7 +83,7 @@ Note that there may be a race condition when removing one swap operator and inst
78
83
79
84
Swapping fees are charged by requiring the swapper to pay slightly more of the input token than is required by the curve parameters. This extra amount is simply directly deposited into the vaults on behalf of the EulerSwap account. This means that it has the effect of increasing the account's NAV, but does not change the shape of the curve itself. The curve is always static, per EulerSwap instance.
80
85
81
-
When an EulerSwap instance is created, a **protocol fee** parameter may be installed by the factory. This portion of the collected fees are routed to a protocol fee recipient. An administrator of the factory can change the the protocol fee and recipient for future created EulerSwap instances, although previously created instances will not be updated retroactively.
86
+
When a swap is performed, the `EulerSwapProtocolFeeConfig` contract is queried to determine the protocol fee in effect. This proportion of the LP fees are instead sent to a protocol fee recipient chosen by the Euler DAO. This proportion cannot exceed 15%.
82
87
83
88
84
89
## Reserve desynchronisation
@@ -103,7 +108,7 @@ Although the virtual reserves specify a hard limit for swaps, there may be other
103
108
* The vaults have supply and/or borrow caps
104
109
* The operator may have been uninstalled
105
110
106
-
There is a function `getLimits` that can take these into account. This function itself is an upper-bound and the values it returns may not be swappable either, in particular if the curve shape does not allow it. However, it makes a best effort and this function can be used to rapidly exclude pools that are definitely unable to service a given size swap.
111
+
There is a function `getLimits` that can take these into account. This function is intended to return quotes that are swappable, but under some conditions may not be, if the pool is configured with larger reserves than the underlying Euler account's liquidity can handle. In these cases, the pool is eligible from being removed from the Registry.
0 commit comments