Skip to content

Commit 36732d1

Browse files
committed
mega refactor
1 parent f38db55 commit 36732d1

34 files changed

+1166
-1126
lines changed

TODO

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
* Better revert messages when a swap fails due to debt-limit/vault utilisation/etc
2-
* currently they are errors thrown by the vaults or arithmetic underflows
3-
1+
* docs
2+
! new flow for activate
3+
! document that periphery depends on non-malicious eulerSwap instances
4+
! limitations of getLimits
5+
* update deploy scripts
6+
* TODOs in UniswapHook.sol
7+
* small cleanups in CurveLib
8+
? tighten up getLimits bounds
49

510
TESTING
611

712
* when exchange rate in vaults != 1
8-
9-
10-
MISC
11-
12-
? A really small swap could fail because deposit() results in 0 shares, which causes EVK to revert. Call convertToShares() first? Seems like overkill...
13-
* Improve the efficiency of on-chain quoting
14-
* Probably necessary for supporting non-zero slippage swaps
15-
* Use fInverse() Closed-form quoting solutions
16-
* "Range hints" for the binary search
17-
13+
* better coverage of swaps done via hooks
1814

1915
IDEAS
2016

2117
* Currently we have only been supporting stable-stable pairs
2218
* What extra considerations would there be for floating pairs?
2319
* Automatically re-invest fees? There are a few options:
24-
* Don't do anything: Re-deploing probably isn't a huge deal
20+
* Don't do anything: Re-deploying probably isn't a huge deal
2521
* Increase the reserves by the fee amount
2622
* Increase the reserves by the extra amount of possible leverage supported by the new fee
2723
* Apply fees to a super-concentrated middle section of the curve (needs R&D)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

script/SwapExactIn.s.sol renamed to script.old/SwapExactIn.s.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
pragma solidity ^0.8.0;
33

4-
import {ScriptUtil} from "./ScriptUtil.s.sol";
5-
import {IERC20, SafeERC20, EulerSwap} from "../src/EulerSwap.sol";
4+
import {SafeERC20, IERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
5+
6+
import {EulerSwap} from "../src/EulerSwap.sol";
67
import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
78

9+
import {ScriptUtil} from "./ScriptUtil.s.sol";
10+
11+
812
contract SwapExactIn is ScriptUtil {
913
using SafeERC20 for IERC20;
1014

src/CtxLib.sol

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.27;
3+
4+
import {IEulerSwap} from "./interfaces/IEulerSwap.sol";
5+
6+
library CtxLib {
7+
struct Storage {
8+
uint112 reserve0;
9+
uint112 reserve1;
10+
uint32 status; // 0 = unactivated, 1 = unlocked, 2 = locked
11+
}
12+
13+
// keccak256("eulerSwap.storage")
14+
bytes32 internal constant CtxStorageLocation = 0xae890085f98619e96ae34ba28d74baa4a4f79785b58fd4afcd3dc0338b79df91;
15+
16+
function getStorage() internal pure returns (Storage storage s) {
17+
assembly {
18+
s.slot := CtxStorageLocation
19+
}
20+
}
21+
22+
/// @dev Unpacks encoded Params from trailing calldata. Loosely based on
23+
/// the implementation from EIP-3448 (except length is hard-coded).
24+
function getParams() internal pure returns (IEulerSwap.Params memory p) {
25+
bytes memory data;
26+
27+
assembly {
28+
let size := 384
29+
let dataPtr := sub(calldatasize(), size)
30+
data := mload(64)
31+
// increment free memory pointer by metadata size + 32 bytes (length)
32+
mstore(64, add(data, add(size, 32)))
33+
mstore(data, size)
34+
let memPtr := add(data, 32)
35+
calldatacopy(memPtr, dataPtr, size)
36+
}
37+
38+
return abi.decode(data, (IEulerSwap.Params));
39+
}
40+
}

0 commit comments

Comments
 (0)