diff --git a/flake.lock b/flake.lock index b98d53f..7711e00 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -95,11 +95,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", "type": "github" }, "original": { @@ -351,17 +351,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1706634492, - "narHash": "sha256-9wg1OQET7oCzzMsktGufJmfr2ylecL8T8YYqQo+qNSc=", + "lastModified": 1709953170, + "narHash": "sha256-No8j4LmDbFmYfh0NXapQDQeoGHXhvnwBkW1usamu8oQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "dad88c029e2644adfde882f73e9338fd39058a3f", + "rev": "de66856bf823415928efe2088c1cc125fce7fffc", "type": "github" }, "original": { "owner": "nixos", "repo": "nixpkgs", - "rev": "dad88c029e2644adfde882f73e9338fd39058a3f", "type": "github" } }, @@ -477,11 +476,11 @@ "rainix": "rainix_2" }, "locked": { - "lastModified": 1708279784, - "narHash": "sha256-82RoHRXrMcPdHp3aaye6xmapmZMO88WTha/JIG3a2uM=", + "lastModified": 1709330445, + "narHash": "sha256-fNBo/pmPOkTbkKZRFnxR6QBQEk1QSL13iIdfPQN6jpg=", "owner": "rainlanguage", "repo": "rain.cli", - "rev": "29f4c82c699128bc264b1077d00bb6ae4e496cae", + "rev": "0f882121f9f26208c1ae062c368ee817b2ca1363", "type": "github" }, "original": { @@ -538,11 +537,11 @@ "rust-overlay": "rust-overlay_3" }, "locked": { - "lastModified": 1708280322, - "narHash": "sha256-NSHBJ/a73wFH+H8CLhj8BRjmK4/k+dNBqmobwxATyFw=", + "lastModified": 1710225842, + "narHash": "sha256-wfRe+fwM2pKQehO5WlRIv07dT8/IhyfDwWphcfk1x1w=", "owner": "rainprotocol", "repo": "rainix", - "rev": "59ea7fa7eab0bd70841df3b09ca18e6d036146d0", + "rev": "1a927a908746931deb2c79c5cedb72f0f1b6f922", "type": "github" }, "original": { @@ -645,11 +644,11 @@ "nixpkgs": "nixpkgs_11" }, "locked": { - "lastModified": 1708241671, - "narHash": "sha256-zSulX9tP4R35Y8A842dGSzaHMVP91W2Ry0SXvQKD2BQ=", + "lastModified": 1709950089, + "narHash": "sha256-JjZINymxtnDY9EDdxnVPideZvHPR2Cm/GdKAptCWLI4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "d500e370b26f9b14303cb39bf1509df0a920c8b0", + "rev": "d3a05d053b145349b8ad395741c5951f332280ef", "type": "github" }, "original": { diff --git a/src/TrancheMirror.sol b/src/TrancheMirror.sol index b1c946e..c76a85a 100644 --- a/src/TrancheMirror.sol +++ b/src/TrancheMirror.sol @@ -16,7 +16,7 @@ import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol"; // Strategy Params uint256 constant TRANCHE_RESERVE_BASE_AMOUNT = 1000e18 ; -uint256 constant TRANCHE_RESERVE_BASE_IO_RATIO = 242e18; +uint256 constant TRANCHE_RESERVE_BASE_IO_RATIO = 315e18; uint256 constant SPREAD_RATIO = 101e16; uint256 constant TRANCHE_EDGE_THRESHOLD = 2e17; uint256 constant INITIAL_TRANCHE_SPACE = 0; diff --git a/test/TrancheMirrorTest.t.sol b/test/TrancheMirrorTest.t.sol index 9fa6387..1a57d96 100644 --- a/test/TrancheMirrorTest.t.sol +++ b/test/TrancheMirrorTest.t.sol @@ -15,9 +15,10 @@ contract TrancheMirrorTest is TrancheMirrorUtils { using LibFixedPointDecimalArithmeticOpenZeppelin for uint256; using LibFixedPointDecimalScale for uint256; - using SafeERC20 for IERC20; + using SafeERC20 for IERC20; function testSellBuyOrderHappyFork() public { + // Deposit Tokens { uint256 depositAmount = 400000e18; @@ -39,12 +40,11 @@ contract TrancheMirrorTest is TrancheMirrorUtils { vm, address(ORDERBOOK_SUPARSER) ) - ); + ); trancheOrder = placeOrder(ORDER_OWNER, bytecode, constants, tokenVaults, tokenVaults); } - // Take Order - { - // Move external market so the order clears + // Take Sell Order + { moveExternalPrice( address(WETH_TOKEN), address(IEON_TOKEN), @@ -58,6 +58,23 @@ contract TrancheMirrorTest is TrancheMirrorUtils { Vm.Log[] memory entries = vm.getRecordedLogs(); (,distributorTokenOut) = getContextInputOutput(entries); } + // Take Buy Order + { + // Move external market so the order clears + moveExternalPrice( + address(IEON_TOKEN), + address(WETH_TOKEN), + POLYGON_IEON_HOLDER, + 10000000e18, + SELL_ROUTE + ); + vm.recordLogs(); + takeOrder(trancheOrder, BUY_ROUTE,0,1); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + (distributorTokenIn,) = getContextInputOutput(entries); + } + assertGe(distributorTokenIn,distributorTokenOut); } function giveTestAccountsTokens(IERC20 token, address from, address to, uint256 amount) internal { @@ -136,7 +153,7 @@ contract TrancheMirrorTest is TrancheMirrorUtils { vm.stopPrank(); } - function getContextInputOutput(Vm.Log[] memory entries) public returns(uint256 input, uint256 output){ + function getContextInputOutput(Vm.Log[] memory entries) internal pure returns(uint256 input, uint256 output){ for (uint256 j = 0; j < entries.length; j++) { if (entries[j].topics[0] == keccak256("Context(address,uint256[][])")) { (, uint256[][] memory context) = abi.decode(entries[j].data, (address, uint256[][])); diff --git a/test/util/TrancheMirrorUtils.sol b/test/util/TrancheMirrorUtils.sol index c4afb68..519317d 100644 --- a/test/util/TrancheMirrorUtils.sol +++ b/test/util/TrancheMirrorUtils.sol @@ -21,7 +21,7 @@ contract TrancheMirrorUtils is RainContracts, Test { using LibFixedPointDecimalArithmeticOpenZeppelin for uint256; using LibFixedPointDecimalScale for uint256; - uint256 constant FORK_BLOCK_NUMBER = 54140734; + uint256 constant FORK_BLOCK_NUMBER = 54561421; uint256 constant CONTEXT_VAULT_IO_ROWS = 5; function selectPolygonFork() internal { @@ -135,6 +135,7 @@ contract TrancheMirrorUtils is RainContracts, Test { function evalDeployedExpression(address expression, bytes32 orderHash, uint256[][] memory context) public view returns (uint256[] memory) { + (orderHash); FullyQualifiedNamespace namespace = LibNamespace.qualifyNamespace(StateNamespace.wrap(uint256(uint160(ORDER_OWNER))), address(ORDERBOOK));