From 17c18811f9f51fac730ae2c1378b1a73c2853cdb Mon Sep 17 00:00:00 2001 From: Lasse <16150076+lnist@users.noreply.github.com> Date: Thu, 11 Jan 2024 12:36:01 +0100 Subject: [PATCH] feat(test): Move MangroveJs deploy script from strats to this repo (#1714) --- CHANGELOG.md | 2 + foundry.toml | 2 +- src/util/node.ts | 2 +- src/util/test/emptyChainDeployer.s.sol | 109 ++++++++++++++++++ src/util/test/mochaHooks.ts | 2 +- .../mangroveToyENS.integration.test.ts | 2 +- test/integration/market.integration.test.ts | 4 +- .../restingOrder.integration.test.ts | 2 - 8 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 src/util/test/emptyChainDeployer.s.sol diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e385407..1c33bc876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Next version +- feat: Moved MangroveJsDeploy from mangrove-strats to this package. Renamed script to EmptyChainDeployer + # 2.0.0 - Cross-cutting diff --git a/foundry.toml b/foundry.toml index c18abd2a8..85dd8007c 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,7 +2,7 @@ [profile.default] src='src' broadcast='broadcast' -script='./node_modules/@mangrovedao/mangrove-strats/script' +script='./src/util/test' test='test' out='out' libs=['lib'] diff --git a/src/util/node.ts b/src/util/node.ts index bc272db37..981f40b34 100644 --- a/src/util/node.ts +++ b/src/util/node.ts @@ -161,7 +161,7 @@ export const builder = (yargs: yargs.Argv<{}>) => { }) .option("script", { describe: "Path to forge script (contract or path or path:contract)", - default: "MangroveJsDeploy", + default: "EmptyChainDeployer", requiresArg: true, type: "string", }) diff --git a/src/util/test/emptyChainDeployer.s.sol b/src/util/test/emptyChainDeployer.s.sol new file mode 100644 index 000000000..66f98abb0 --- /dev/null +++ b/src/util/test/emptyChainDeployer.s.sol @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.13; + +import {MangroveDeployer} from "@mgv/script/core/deployers/MangroveDeployer.s.sol"; + +import {OLKey} from "@mgv/src/core/MgvLib.sol"; +import {TestToken} from "@mgv/test/lib/tokens/TestToken.sol"; +import {MangroveOrderDeployer} from "@mgv-strats/script/strategies/mangroveOrder/deployers/MangroveOrderDeployer.s.sol"; +import {KandelSeederDeployer} from "@mgv-strats/script/strategies/kandel/deployers/KandelSeederDeployer.s.sol"; +import {MangroveOrder} from "@mgv-strats/src/strategies/MangroveOrder.sol"; +import {MgvReader} from "@mgv/src/periphery/MgvReader.sol"; +import {SimpleTestMaker} from "@mgv/test/lib/agents/TestMaker.sol"; +import {Mangrove} from "@mgv/src/core/Mangrove.sol"; +import {IMangrove} from "@mgv/src/IMangrove.sol"; +import {Deployer} from "@mgv/script/lib/Deployer.sol"; +import {ActivateMarket, Market} from "@mgv/script/core/ActivateMarket.s.sol"; +import {PoolAddressProviderMock} from "@mgv-strats/script/toy/AaveMock.sol"; +import {IERC20} from "@mgv/lib/IERC20.sol"; + +/* +This script prepares a local chain for testing by mangrove.js. +*/ + +contract EmptyChainDeployer is Deployer { + TestToken public tokenA; + TestToken public tokenB; + address public dai; + address public usdc; + address public weth; + SimpleTestMaker public simpleTestMaker; + MangroveOrder public mgo; + + function run() public { + innerRun({gasprice: 1000, gasmax: 2_000_000, gasbot: broadcaster()}); + outputDeployment(); + } + + function innerRun(uint gasprice, uint gasmax, address gasbot) public { + MangroveDeployer mgvDeployer = new MangroveDeployer(); + + mgvDeployer.innerRun({chief: broadcaster(), gasprice: gasprice, gasmax: gasmax, gasbot: gasbot}); + + IMangrove mgv = mgvDeployer.mgv(); + MgvReader mgvReader = mgvDeployer.reader(); + + broadcast(); + mgv.setUseOracle(false); + + broadcast(); + tokenA = new TestToken({admin: broadcaster(), name: "Token A", symbol: "TokenA", _decimals: 18}); + + broadcast(); + tokenA.setMintLimit(type(uint).max); + fork.set("TokenA", address(tokenA)); + + broadcast(); + tokenB = new TestToken({admin: broadcaster(), name: "Token B", symbol: "TokenB", _decimals: 6}); + + broadcast(); + tokenB.setMintLimit(type(uint).max); + fork.set("TokenB", address(tokenB)); + + broadcast(); + dai = address(new TestToken({admin: broadcaster(), name: "DAI", symbol: "DAI", _decimals: 18})); + fork.set("DAI", dai); + + broadcast(); + usdc = address(new TestToken({admin: broadcaster(), name: "USD Coin", symbol: "USDC", _decimals: 6})); + fork.set("USDC", usdc); + + broadcast(); + weth = address(new TestToken({admin: broadcaster(), name: "Wrapped Ether", symbol: "WETH", _decimals: 18})); + fork.set("WETH", weth); + + broadcast(); + simpleTestMaker = + new SimpleTestMaker({_mgv: IMangrove(payable(mgv)), _ol: OLKey(address(tokenA), address(tokenB), 1)}); + fork.set("SimpleTestMaker", address(simpleTestMaker)); + + ActivateMarket activateMarket = new ActivateMarket(); + + activateMarket.innerRun(mgv, mgvReader, Market(address(tokenA), address(tokenB), 1), 2 * 1e12, 3 * 1e12, 250); + activateMarket.innerRun(mgv, mgvReader, Market(dai, usdc, 1), 1e12 / 1000, 1e12 / 1000, 0); + activateMarket.innerRun(mgv, mgvReader, Market(weth, dai, 1), 1e12, 1e12 / 1000, 0); + activateMarket.innerRun(mgv, mgvReader, Market(weth, usdc, 1), 1e12, 1e12 / 1000, 0); + + MangroveOrderDeployer mangroveDeployer = new MangroveOrderDeployer(); + mangroveDeployer.innerRun({admin: broadcaster(), mgv: IMangrove(payable(mgv))}); + MangroveOrder mangroveOrder = MangroveOrder(fork.get("MangroveOrder")); + broadcast(); + mangroveOrder.activate(dynamic([IERC20(tokenA), IERC20(tokenB)])); + + address[] memory underlying = dynamic([address(tokenA), address(tokenB), dai, usdc, weth]); + broadcast(); + address aaveAddressProvider = address(new PoolAddressProviderMock(underlying)); + + KandelSeederDeployer kandelSeederDeployer = new KandelSeederDeployer(); + kandelSeederDeployer.innerRun({ + mgv: IMangrove(payable(mgv)), + addressesProvider: aaveAddressProvider, + aaveKandelGasreq: 629000, // see CoreKandelGasreqBaseTest + kandelGasreq: 126000, // see CoreKandelGasreqBaseTest + deployKandel: true, + deployAaveKandel: true, + testBase: IERC20(fork.get("WETH")), + testQuote: IERC20(fork.get("DAI")) + }); + } +} diff --git a/src/util/test/mochaHooks.ts b/src/util/test/mochaHooks.ts index 6ff7dc75c..cac4a4639 100644 --- a/src/util/test/mochaHooks.ts +++ b/src/util/test/mochaHooks.ts @@ -11,7 +11,7 @@ const serverParams = { host: "127.0.0.1", port: 8546, // use 8546 for the actual node, but let all connections go through proxies to be able to cut the connection before snapshot revert. pipe: false, - script: "MangroveJsDeploy", + script: "EmptyChainDeployer", deploy: false, setMulticallCodeIfAbsent: false, // mangrove.js is supposed to work against servers that only have ToyENS deployed but not Multicall, so we don't deploy Multicall in tests. However mangrove.js needs ToyENS so we let the node ensure it's there. }; diff --git a/test/integration/mangroveToyENS.integration.test.ts b/test/integration/mangroveToyENS.integration.test.ts index ec6212db6..f1319c5e1 100644 --- a/test/integration/mangroveToyENS.integration.test.ts +++ b/test/integration/mangroveToyENS.integration.test.ts @@ -13,7 +13,7 @@ import node from "../../src/util/node"; const defaultServerParams = { host: "127.0.0.1", - script: "MangroveJsDeploy", + script: "EmptyChainDeployer", }; describe("Mangrove functionality", () => { diff --git a/test/integration/market.integration.test.ts b/test/integration/market.integration.test.ts index 6dcfedf24..883566c4a 100644 --- a/test/integration/market.integration.test.ts +++ b/test/integration/market.integration.test.ts @@ -1044,12 +1044,10 @@ describe("Market integration tests suite", () => { const overrides = { gasLimit }; if (forceRouting) { - const orderLogic = mgvAdmin.offerLogic(mgv.orderContract.address); + const orderLogic = mgv.offerLogic(mgv.orderContract.address); const router = await orderLogic.contract.router(); await market.quote.approve(router); await market.base.approve(router); - - await orderLogic.activate(["TokenA", "TokenB"]); } const maker = await mgvTestUtil.getAccount( diff --git a/test/integration/restingOrder.integration.test.ts b/test/integration/restingOrder.integration.test.ts index e77a081bd..0b2fe1758 100644 --- a/test/integration/restingOrder.integration.test.ts +++ b/test/integration/restingOrder.integration.test.ts @@ -92,8 +92,6 @@ describe("RestingOrder", () => { ); router = (await orderLogic.router()) as AbstractRouter; - await w(orderLogic.activate(["TokenA", "TokenB"])); - // minting As and Bs for test runner const me = await mgv.signer.getAddress(); await w(tokenA.contract.mintTo(me, utils.parseUnits("100", 18)));