From 5f5da0c97e29a697b92d44a10d73b2d8e1111609 Mon Sep 17 00:00:00 2001 From: Peter <105609241+peterMangrove@users.noreply.github.com> Date: Thu, 29 Jun 2023 12:37:48 +0200 Subject: [PATCH] Fix: Better script structure (#88) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: better script structure * fix: add new ABI * fix: add default MgvArbitrage to ativate script * fix: UNLICENSED to Unlicense Co-authored-by: Espen Højsgaard * fix: correct license on scripts * fix: all UNLICENSED to Unlicense --------- Co-authored-by: Espen Højsgaard --- .../mangrove-arbitrage/abi/MgvArbitrage.json | 39 +++++++++++++++++++ .../script/MgvArbitrageActivateTokens.s.sol | 4 +- .../script/MgvArbitrageTestDeployer.s.sol | 2 +- .../MgvArbitrageDeployer.s.sol | 4 +- .../MumbaiMgvArbitrageDeployer.s.sol | 23 +++++++++++ .../PolygonMgvArbitrageDeployer.s.sol | 23 +++++++++++ .../src/MyPinnedPolygon.sol | 2 +- .../test/MgvArbitrage.t.sol | 2 +- .../test/MgvArbitrageActivateTokensTest.t.sol | 4 +- .../test/MgvArbitrageDeployerTest.t.sol | 25 ------------ .../BaseMgvArbitrageDeployerTest.t.sol | 22 +++++++++++ .../deployers/MgvArbitrageDeployerTest.t.sol | 20 ++++++++++ .../MumbaiMgvArbitrageDeployerTest.t.sol | 24 ++++++++++++ .../PolygonMgvArbitrageDeployerTest.t.sol | 25 ++++++++++++ 14 files changed, 185 insertions(+), 34 deletions(-) rename packages/mangrove-arbitrage/script/{ => deployers}/MgvArbitrageDeployer.s.sol (92%) create mode 100644 packages/mangrove-arbitrage/script/deployers/MumbaiMgvArbitrageDeployer.s.sol create mode 100644 packages/mangrove-arbitrage/script/deployers/PolygonMgvArbitrageDeployer.s.sol delete mode 100644 packages/mangrove-arbitrage/test/MgvArbitrageDeployerTest.t.sol create mode 100644 packages/mangrove-arbitrage/test/deployers/BaseMgvArbitrageDeployerTest.t.sol create mode 100644 packages/mangrove-arbitrage/test/deployers/MgvArbitrageDeployerTest.t.sol create mode 100644 packages/mangrove-arbitrage/test/deployers/MumbaiMgvArbitrageDeployerTest.t.sol create mode 100644 packages/mangrove-arbitrage/test/deployers/PolygonMgvArbitrageDeployerTest.t.sol diff --git a/packages/mangrove-arbitrage/abi/MgvArbitrage.json b/packages/mangrove-arbitrage/abi/MgvArbitrage.json index 4dd46c95..7212244c 100644 --- a/packages/mangrove-arbitrage/abi/MgvArbitrage.json +++ b/packages/mangrove-arbitrage/abi/MgvArbitrage.json @@ -288,6 +288,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "router", + "outputs": [ + { + "internalType": "contract ISwapRouter", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -301,6 +314,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "newArbitrager", + "type": "address" + } + ], + "name": "setArbitrager", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IMangrove", + "name": "newMgv", + "type": "address" + } + ], + "name": "setMgv", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/packages/mangrove-arbitrage/script/MgvArbitrageActivateTokens.s.sol b/packages/mangrove-arbitrage/script/MgvArbitrageActivateTokens.s.sol index 3e6f26d0..84c84c4c 100644 --- a/packages/mangrove-arbitrage/script/MgvArbitrageActivateTokens.s.sol +++ b/packages/mangrove-arbitrage/script/MgvArbitrageActivateTokens.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: Unlicense pragma solidity ^0.8.13; import {Deployer} from "mgv_script/lib/Deployer.sol"; @@ -13,7 +13,7 @@ contract MgvArbitrageActivateTokens is Deployer { innerRun({ tkn1: IERC20(envAddressOrName("TKN1")), tkn2: IERC20(envAddressOrName("TKN2")), - arbitrageContract: envAddressOrName("ARBITRAGECONTRACT") + arbitrageContract: envAddressOrName("ARBITRAGECONTRACT", "MgvArbitrage") }); } diff --git a/packages/mangrove-arbitrage/script/MgvArbitrageTestDeployer.s.sol b/packages/mangrove-arbitrage/script/MgvArbitrageTestDeployer.s.sol index 241717d3..04a69a09 100644 --- a/packages/mangrove-arbitrage/script/MgvArbitrageTestDeployer.s.sol +++ b/packages/mangrove-arbitrage/script/MgvArbitrageTestDeployer.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: Unlicense pragma solidity ^0.8.13; import {Deployer} from "mgv_script/lib/Deployer.sol"; diff --git a/packages/mangrove-arbitrage/script/MgvArbitrageDeployer.s.sol b/packages/mangrove-arbitrage/script/deployers/MgvArbitrageDeployer.s.sol similarity index 92% rename from packages/mangrove-arbitrage/script/MgvArbitrageDeployer.s.sol rename to packages/mangrove-arbitrage/script/deployers/MgvArbitrageDeployer.s.sol index d6a9c57a..8255c7dd 100644 --- a/packages/mangrove-arbitrage/script/MgvArbitrageDeployer.s.sol +++ b/packages/mangrove-arbitrage/script/deployers/MgvArbitrageDeployer.s.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: Unlicense pragma solidity ^0.8.13; import {Deployer} from "mgv_script/lib/Deployer.sol"; @@ -10,7 +10,7 @@ contract MgvArbitrageDeployer is Deployer { function run() public { innerRun({ - admin: envAddressOrName("CHIEF"), + admin: envAddressOrName("CHIEF", broadcaster()), arbitrager: envAddressOrName("ARBITRAGER"), mgv: envAddressOrName("MGV", "Mangrove") }); diff --git a/packages/mangrove-arbitrage/script/deployers/MumbaiMgvArbitrageDeployer.s.sol b/packages/mangrove-arbitrage/script/deployers/MumbaiMgvArbitrageDeployer.s.sol new file mode 100644 index 00000000..61760c06 --- /dev/null +++ b/packages/mangrove-arbitrage/script/deployers/MumbaiMgvArbitrageDeployer.s.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.13; + +import {Deployer} from "mgv_script/lib/Deployer.sol"; +import {MgvArbitrageDeployer} from "script/deployers/MgvArbitrageDeployer.s.sol"; + +contract MumbaiMgvArbitrageDeployer is Deployer { + MgvArbitrageDeployer public arbDeployer; + + function run() public { + runWithChainSpecificParams(); + outputDeployment(); + } + + function runWithChainSpecificParams() public { + arbDeployer = new MgvArbitrageDeployer(); + arbDeployer.innerRun({ + admin: broadcaster(), + arbitrager: envAddressOrName("ARBITRAGER", "Arbitrager"), + mgv: envAddressOrName("MGV", "Mangrove") + }); + } +} diff --git a/packages/mangrove-arbitrage/script/deployers/PolygonMgvArbitrageDeployer.s.sol b/packages/mangrove-arbitrage/script/deployers/PolygonMgvArbitrageDeployer.s.sol new file mode 100644 index 00000000..dcb4d37f --- /dev/null +++ b/packages/mangrove-arbitrage/script/deployers/PolygonMgvArbitrageDeployer.s.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.13; + +import {Deployer} from "mgv_script/lib/Deployer.sol"; +import {MgvArbitrageDeployer} from "script/deployers/MgvArbitrageDeployer.s.sol"; + +contract PolygonMgvArbitrageDeployer is Deployer { + MgvArbitrageDeployer public arbDeployer; + + function run() public { + runWithChainSpecificParams(); + outputDeployment(); + } + + function runWithChainSpecificParams() public { + arbDeployer = new MgvArbitrageDeployer(); + arbDeployer.innerRun({ + admin: broadcaster(), + arbitrager: envAddressOrName("ARBITRAGER", "Arbitrager"), + mgv: envAddressOrName("MGV", "Mangrove") + }); + } +} diff --git a/packages/mangrove-arbitrage/src/MyPinnedPolygon.sol b/packages/mangrove-arbitrage/src/MyPinnedPolygon.sol index 31c22eed..7716d4bf 100644 --- a/packages/mangrove-arbitrage/src/MyPinnedPolygon.sol +++ b/packages/mangrove-arbitrage/src/MyPinnedPolygon.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: AGPL-3.0 +// SPDX-License-Identifier: BSD-2-Clause pragma solidity ^0.8.10; import {GenericFork} from "mgv_test/lib/forks/Generic.sol"; diff --git a/packages/mangrove-arbitrage/test/MgvArbitrage.t.sol b/packages/mangrove-arbitrage/test/MgvArbitrage.t.sol index 92026e49..2bf98814 100644 --- a/packages/mangrove-arbitrage/test/MgvArbitrage.t.sol +++ b/packages/mangrove-arbitrage/test/MgvArbitrage.t.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: AGPL-3.0 +// SPDX-License-Identifier: BSD-2-Clause pragma solidity ^0.8.10; import {MangroveTest} from "mgv_test/lib/MangroveTest.sol"; diff --git a/packages/mangrove-arbitrage/test/MgvArbitrageActivateTokensTest.t.sol b/packages/mangrove-arbitrage/test/MgvArbitrageActivateTokensTest.t.sol index 01e16766..77d45d5c 100644 --- a/packages/mangrove-arbitrage/test/MgvArbitrageActivateTokensTest.t.sol +++ b/packages/mangrove-arbitrage/test/MgvArbitrageActivateTokensTest.t.sol @@ -1,9 +1,9 @@ -// SPDX-License-Identifier: AGPL-3.0 +// SPDX-License-Identifier: BSD-2-Clause pragma solidity ^0.8.10; import {Deployer} from "mgv_script/lib/Deployer.sol"; import {MgvArbitrageActivateTokens} from "script/MgvArbitrageActivateTokens.s.sol"; -import {MgvArbitrageDeployer} from "script/MgvArbitrageDeployer.s.sol"; +import {MgvArbitrageDeployer} from "script/deployers/MgvArbitrageDeployer.s.sol"; import {IERC20} from "mgv_src/IERC20.sol"; import "mgv_test/lib/forks/Polygon.sol"; import {MangroveJsDeploy} from "mgv_script/toy/MangroveJs.s.sol"; diff --git a/packages/mangrove-arbitrage/test/MgvArbitrageDeployerTest.t.sol b/packages/mangrove-arbitrage/test/MgvArbitrageDeployerTest.t.sol deleted file mode 100644 index ec16108b..00000000 --- a/packages/mangrove-arbitrage/test/MgvArbitrageDeployerTest.t.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0 -pragma solidity ^0.8.10; - -import {Deployer} from "mgv_script/lib/Deployer.sol"; -import {MangroveDeployer} from "mgv_script/core/deployers/MangroveDeployer.s.sol"; -import {MgvArbitrageDeployer} from "script/MgvArbitrageDeployer.s.sol"; - -import {Test2, Test} from "mgv_lib/Test2.sol"; - -contract MgvArbitrageDeployerTest is Deployer, Test2 { - MgvArbitrageDeployer mgvArbDeployer; - MangroveDeployer mgvDeployer; - address admin = freshAddress("chief"); - address arbitrager = freshAddress("arbitrager"); - - function setUp() public { - mgvDeployer = new MangroveDeployer(); - mgvDeployer.innerRun({chief: admin, gasprice: 1, gasmax: 2_000_000, gasbot: address(0)}); - mgvArbDeployer = new MgvArbitrageDeployer(); - } - - function test_innerRun() public { - mgvArbDeployer.innerRun({admin: admin, mgv: address(mgvDeployer.mgv()), arbitrager: arbitrager}); - } -} diff --git a/packages/mangrove-arbitrage/test/deployers/BaseMgvArbitrageDeployerTest.t.sol b/packages/mangrove-arbitrage/test/deployers/BaseMgvArbitrageDeployerTest.t.sol new file mode 100644 index 00000000..29794804 --- /dev/null +++ b/packages/mangrove-arbitrage/test/deployers/BaseMgvArbitrageDeployerTest.t.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: BSD-2-Clause +pragma solidity ^0.8.10; + +import {Deployer} from "mgv_script/lib/Deployer.sol"; +import {MangroveDeployer} from "mgv_script/core/deployers/MangroveDeployer.s.sol"; +import {MgvArbitrageDeployer} from "script/deployers/MgvArbitrageDeployer.s.sol"; + +import {Test2, Test} from "mgv_lib/Test2.sol"; + +abstract contract BaseMgvArbitrageDeployerTest is Deployer, Test2 { + MgvArbitrageDeployer mgvArbDeployer; + MangroveDeployer mgvDeployer; + address admin; + address arbitrager; + + function test_toy_ens_has_addresses() public { + assertEq(mgvArbDeployer.mgvArb().arbitrager(), arbitrager, "Wrong arbitrager address"); + assertEq(mgvArbDeployer.mgvArb().admin(), admin, "Wrong admin address"); + assertEq(address(mgvArbDeployer.mgvArb().mgv()), fork.get("Mangrove"), "Wrong mgv address"); + assertEq(fork.get("MgvArbitrage"), address(mgvArbDeployer.mgvArb()), "MgvArbitrage address not correct"); + } +} diff --git a/packages/mangrove-arbitrage/test/deployers/MgvArbitrageDeployerTest.t.sol b/packages/mangrove-arbitrage/test/deployers/MgvArbitrageDeployerTest.t.sol new file mode 100644 index 00000000..e5a354dd --- /dev/null +++ b/packages/mangrove-arbitrage/test/deployers/MgvArbitrageDeployerTest.t.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: BSD-2-Clause +pragma solidity ^0.8.10; + +import {MangroveDeployer} from "mgv_script/core/deployers/MangroveDeployer.s.sol"; +import {MgvArbitrageDeployer} from "script/deployers/MgvArbitrageDeployer.s.sol"; +import {BaseMgvArbitrageDeployerTest} from "test/deployers/BaseMgvArbitrageDeployerTest.t.sol"; + +import {Test2, Test} from "mgv_lib/Test2.sol"; + +contract MgvArbitrageDeployerTest is BaseMgvArbitrageDeployerTest { + function setUp() public { + arbitrager = freshAddress("arbitrager"); + admin = freshAddress("chief"); + + mgvDeployer = new MangroveDeployer(); + mgvDeployer.innerRun({chief: admin, gasprice: 1, gasmax: 2_000_000, gasbot: address(0)}); + mgvArbDeployer = new MgvArbitrageDeployer(); + mgvArbDeployer.innerRun({admin: admin, arbitrager: arbitrager, mgv: address(mgvDeployer.mgv())}); + } +} diff --git a/packages/mangrove-arbitrage/test/deployers/MumbaiMgvArbitrageDeployerTest.t.sol b/packages/mangrove-arbitrage/test/deployers/MumbaiMgvArbitrageDeployerTest.t.sol new file mode 100644 index 00000000..d8fde93d --- /dev/null +++ b/packages/mangrove-arbitrage/test/deployers/MumbaiMgvArbitrageDeployerTest.t.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: BSD-2-Clause +pragma solidity ^0.8.10; + +import {MangroveDeployer} from "mgv_script/core/deployers/MangroveDeployer.s.sol"; +import {MumbaiMgvArbitrageDeployer} from "script/deployers/MumbaiMgvArbitrageDeployer.s.sol"; +import {BaseMgvArbitrageDeployerTest} from "test/deployers/BaseMgvArbitrageDeployerTest.t.sol"; + +import {Test2, Test} from "mgv_lib/Test2.sol"; + +contract MumbaiMgvArbitrageDeployerTest is BaseMgvArbitrageDeployerTest { + function setUp() public { + admin = broadcaster(); + arbitrager = freshAddress("arbitrager"); + fork.set("Arbitrager", arbitrager); + + mgvDeployer = new MangroveDeployer(); + mgvDeployer.innerRun({chief: admin, gasprice: 1, gasmax: 2_000_000, gasbot: address(0)}); + MumbaiMgvArbitrageDeployer mumbaiMgvArbitrageDeployer = new MumbaiMgvArbitrageDeployer(); + + mumbaiMgvArbitrageDeployer.runWithChainSpecificParams(); + + mgvArbDeployer = mumbaiMgvArbitrageDeployer.arbDeployer(); + } +} diff --git a/packages/mangrove-arbitrage/test/deployers/PolygonMgvArbitrageDeployerTest.t.sol b/packages/mangrove-arbitrage/test/deployers/PolygonMgvArbitrageDeployerTest.t.sol new file mode 100644 index 00000000..154a9ef6 --- /dev/null +++ b/packages/mangrove-arbitrage/test/deployers/PolygonMgvArbitrageDeployerTest.t.sol @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: BSD-2-Clause +pragma solidity ^0.8.10; + +import {MangroveDeployer} from "mgv_script/core/deployers/MangroveDeployer.s.sol"; +import {PolygonMgvArbitrageDeployer} from "script/deployers/PolygonMgvArbitrageDeployer.s.sol"; +import {BaseMgvArbitrageDeployerTest} from "test/deployers/BaseMgvArbitrageDeployerTest.t.sol"; + +import {Test2, Test} from "mgv_lib/Test2.sol"; + +contract PolygonMgvArbitrageDeployerTest is BaseMgvArbitrageDeployerTest { + function setUp() public { + admin = broadcaster(); + arbitrager = freshAddress("arbitrager"); + fork.set("Arbitrager", arbitrager); + + mgvDeployer = new MangroveDeployer(); + mgvDeployer.innerRun({chief: admin, gasprice: 1, gasmax: 2_000_000, gasbot: address(0)}); + + PolygonMgvArbitrageDeployer polygonMgvArbitrageDeployer = new PolygonMgvArbitrageDeployer(); + + polygonMgvArbitrageDeployer.runWithChainSpecificParams(); + + mgvArbDeployer = polygonMgvArbitrageDeployer.arbDeployer(); + } +}