diff --git a/TODO b/TODO index bdd7da9..1375f26 100644 --- a/TODO +++ b/TODO @@ -9,8 +9,6 @@ * ConstantSum: incorporate price multipliers in quote methods * natspec * permit2 instead of regular approval: measure gas savings -* in constructor, check the two vaults have the correct EVC() return value - * maybe even that they were created by the EVK factory? ? a really small swap could fail because deposit() results in 0 shares, which EVK fails on. call convertToShares() first? Seems like overkill ? pause guardian ? how should aggregators find instances diff --git a/src/MaglevBase.sol b/src/MaglevBase.sol index 2357348..9091ef1 100644 --- a/src/MaglevBase.sol +++ b/src/MaglevBase.sol @@ -27,6 +27,7 @@ abstract contract MaglevBase is IMaglevBase, EVCUtil { error BadFee(); error InsufficientReserves(); error InsufficientCash(); + error DifferentEVC(); modifier nonReentrant() { require(locked == 0, Locked()); @@ -48,6 +49,10 @@ abstract contract MaglevBase is IMaglevBase, EVCUtil { constructor(BaseParams memory params) EVCUtil(params.evc) { require(params.fee < 1e18, BadFee()); + address vault0Evc = IEVault(params.vault0).EVC(); + require(vault0Evc == IEVault(params.vault1).EVC(), DifferentEVC()); + require(vault0Evc == params.evc, DifferentEVC()); + vault0 = params.vault0; vault1 = params.vault1; asset0 = IEVault(vault0).asset(); diff --git a/test/EulerSwap.t.sol b/test/EulerSwap.t.sol index 2e81b00..c5c3b18 100644 --- a/test/EulerSwap.t.sol +++ b/test/EulerSwap.t.sol @@ -8,7 +8,7 @@ import {TestERC20} from "evk-test/unit/evault/EVaultTestBase.t.sol"; import {IEVault} from "evk/EVault/IEVault.sol"; import {MaglevTestBase} from "./MaglevTestBase.t.sol"; -import {MaglevEulerSwap as Maglev} from "../src/MaglevEulerSwap.sol"; +import {MaglevEulerSwap as Maglev, MaglevBase} from "../src/MaglevEulerSwap.sol"; contract EulerSwapTest is MaglevTestBase { Maglev public maglev; @@ -41,6 +41,23 @@ contract EulerSwapTest is MaglevTestBase { maglev.configure(); } + function test_different_EVC() public { + vm.expectRevert(MaglevBase.DifferentEVC.selector); + + new Maglev( + MaglevBase.BaseParams({ + evc: address(makeAddr("RANDOM_EVC")), + vault0: address(eTST), + vault1: address(eTST2), + myAccount: holder, + debtLimit0: 50e18, + debtLimit1: 50e18, + fee: 0 + }), + Maglev.EulerSwapParams({priceX: 1e18, priceY: 1e18, concentrationX: 4e18, concentrationY: 0.85e18}) + ); + } + function test_basicSwap_exactIn() public monotonicHolderNAV { uint256 amountIn = 1e18; uint256 amountOut = maglev.quoteExactInput(address(assetTST), address(assetTST2), amountIn);