Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
Merge master into develop
  • Loading branch information
mangrove-automation authored Jan 11, 2024
2 parents 61f070e + 17c1881 commit aad34ee
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Next version

- feat: Moved MangroveJsDeploy from mangrove-strats to this package. Renamed script to EmptyChainDeployer

# 2.0.0

- Cross-cutting
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion src/util/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down
109 changes: 109 additions & 0 deletions src/util/test/emptyChainDeployer.s.sol
Original file line number Diff line number Diff line change
@@ -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"))
});
}
}
2 changes: 1 addition & 1 deletion src/util/test/mochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mangroveToyENS.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import node from "../../src/util/node";

const defaultServerParams = {
host: "127.0.0.1",
script: "MangroveJsDeploy",
script: "EmptyChainDeployer",
};

describe("Mangrove functionality", () => {
Expand Down
4 changes: 1 addition & 3 deletions test/integration/market.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions test/integration/restingOrder.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down

0 comments on commit aad34ee

Please sign in to comment.