From 4f106ae393652943714c6e5359c0de2a2446a082 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Wed, 21 Feb 2024 23:40:34 +0530 Subject: [PATCH] wip tests --- lib/h20.pubstrats | 2 +- src/TrancheMirror.sol | 26 ++++++++++++++------------ src/abstract/RainContracts.sol | 1 - test/TrancheMirrorTest.t.sol | 23 +++++++++++++++++++++-- test/util/TrancheMirrorUtils.sol | 8 ++++---- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/lib/h20.pubstrats b/lib/h20.pubstrats index 0c11382..fbe6e56 160000 --- a/lib/h20.pubstrats +++ b/lib/h20.pubstrats @@ -1 +1 @@ -Subproject commit 0c11382c885eb75493eb506344b3a0299b9a5990 +Subproject commit fbe6e56124b7b8d8e22e1cffd60ebe779f47456f diff --git a/src/TrancheMirror.sol b/src/TrancheMirror.sol index 82a4ec9..ab8a89a 100644 --- a/src/TrancheMirror.sol +++ b/src/TrancheMirror.sol @@ -72,7 +72,7 @@ function uint2str(uint256 _i) pure returns (string memory _uintAsString) { library LibTrancheSpreadOrders { using Strings for address; - function getTrancheSpreadBuyOrder(Vm vm, address orderBookSubparser, address uniswapWords) + function getTrancheSpreadBuyOrder(Vm vm, address orderBookSubparser) internal returns (bytes memory trancheRefill) { @@ -91,27 +91,29 @@ library LibTrancheSpreadOrders { ffi[11] = "--bind"; ffi[12] = "reserve-token=0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"; ffi[13] = "--bind"; - ffi[14] = string.concat("tranche-reserve-amount-base=", uint2str(1e18)); + ffi[14] = "get-tranche-space='get-real-tranche-space"; ffi[15] = "--bind"; - ffi[16] = string.concat("tranche-reserve-io-ratio-base=", uint2str(111e16)); + ffi[16] = "set-tranche-space='set-real-tranche-space"; ffi[17] = "--bind"; - ffi[18] = string.concat("spread-ratio=", uint2str(101e16)); + ffi[18] = "tranche-reserve-amount-growth='tranche-reserve-amount-growth-constant"; ffi[19] = "--bind"; - ffi[20] = string.concat("tranche-space-edge-guard-threshold=", uint2str(1e16)); + ffi[20] = string.concat("tranche-reserve-amount-base=", uint2str(1e18)); ffi[21] = "--bind"; - ffi[22] = "get-tranche-space='get-real-tranche-space"; + ffi[22] = "tranche-reserve-io-ratio-growth='tranche-reserve-io-ratio-linear"; ffi[23] = "--bind"; - ffi[24] = "set-tranche-space='set-real-tranche-space"; + ffi[24] = string.concat("tranche-reserve-io-ratio-base=", uint2str(111e16)); ffi[25] = "--bind"; - ffi[26] = "tranche-reserve-amount-growth='tranche-reserve-amount-growth-constant"; + ffi[26] = string.concat("spread-ratio=", uint2str(101e16)); ffi[27] = "--bind"; - ffi[28] = "tranche-reserve-io-ratio-growth='tranche-reserve-io-ratio-linear"; - trancheRefill = bytes.concat(getSubparserPrelude(orderBookSubparser, uniswapWords), vm.ffi(ffi)); + ffi[28] = string.concat("tranche-space-edge-guard-threshold=", uint2str(1e16)); + + + trancheRefill = bytes.concat(getSubparserPrelude(orderBookSubparser), vm.ffi(ffi)); } - function getSubparserPrelude(address obSubparser, address uniswapWords) internal pure returns (bytes memory) { + function getSubparserPrelude(address obSubparser) internal pure returns (bytes memory) { bytes memory RAINSTRING_OB_SUBPARSER = - bytes(string.concat("using-words-from ", obSubparser.toHexString(), " ", uniswapWords.toHexString(), " ")); + bytes(string.concat("using-words-from ", obSubparser.toHexString(), " ")); return RAINSTRING_OB_SUBPARSER; } } diff --git a/src/abstract/RainContracts.sol b/src/abstract/RainContracts.sol index cf7c8bd..fad94a9 100644 --- a/src/abstract/RainContracts.sol +++ b/src/abstract/RainContracts.sol @@ -70,7 +70,6 @@ abstract contract RainContracts { function deployOrderBook() public { ORDERBOOK = new OrderBook(); - ORDERBOOK_SUPARSER = new OrderBookSubParser(); } function deployOrderBookSubparser() public { diff --git a/test/TrancheMirrorTest.t.sol b/test/TrancheMirrorTest.t.sol index 21ebadc..8439f65 100644 --- a/test/TrancheMirrorTest.t.sol +++ b/test/TrancheMirrorTest.t.sol @@ -9,13 +9,32 @@ import "src/TrancheMirror.sol"; contract TrancheMirrorTest is TrancheMirrorUtils { function testParseOrder() public { + console2.log("PARSER : ",address(PARSER)); + console2.log("INTERPRETER : ",address(INTERPRETER)); + console2.log("STORE : ",address(STORE)); + console2.log("EXPRESSION_DEPLOYER : ",address(EXPRESSION_DEPLOYER)); + console2.log("ORDERBOOK_SUPARSER : ",address(ORDERBOOK_SUPARSER)); + + PARSER.parse( LibTrancheSpreadOrders.getTrancheSpreadBuyOrder( vm, - address(ORDERBOOK_SUPARSER), - address(UNISWAP_WORDS) + address(ORDERBOOK_SUPARSER) ) ); } + + function testParseOrderRainlang() public { + console2.log("PARSER : ",address(PARSER)); + console2.log("INTERPRETER : ",address(INTERPRETER)); + console2.log("STORE : ",address(STORE)); + console2.log("EXPRESSION_DEPLOYER : ",address(EXPRESSION_DEPLOYER)); + console2.log("ORDERBOOK_SUPARSER : ",address(ORDERBOOK_SUPARSER)); + + bytes memory rainlang = "_: decimal18-saturating-sub(1e18 2e18);"; + PARSER.parse( + rainlang + ); + } } diff --git a/test/util/TrancheMirrorUtils.sol b/test/util/TrancheMirrorUtils.sol index e78952b..f57e5a1 100644 --- a/test/util/TrancheMirrorUtils.sol +++ b/test/util/TrancheMirrorUtils.sol @@ -47,9 +47,9 @@ contract TrancheMirrorUtils is RainContracts, Test { deployExpressionDeployer(vm, address(INTERPRETER), address(STORE), address(PARSER)); deployOrderBookSubparser(); - deployUniswapWords(vm); - - // PARSER = IParserV1(0xc2D7890077F3EA75c2798D8624E1E0E6ef8C41e6); + deployUniswapWords(vm); + + // PARSER = IParserV1(0xc2D7890077F3EA75c2798D8624E1E0E6ef8C41e6); // INTERPRETER = IInterpreterV2(0xB7d691B7E3676cb70dB0cDae95797F24Eab6980D); // STORE = IInterpreterStoreV2(0x0b5a2b0aCFc5B52bf341FAD638B63C9A6f82dcb9); // EXPRESSION_DEPLOYER = IExpressionDeployerV3(0xE1E250a234aF6F343062873bf89c9D1a0a659c0b); @@ -59,7 +59,7 @@ contract TrancheMirrorUtils is RainContracts, Test { ORDERBOOK = IOrderBookV3(0xDE5aBE2837bc042397D80E37fb7b2C850a8d5a6C); ARB_IMPLEMENTATION = IOrderBookV3ArbOrderTaker(0x8F29083140559bd1771eDBfB73656A9f676c00Fd); ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0x0D7896d70FE84e88CC8e8BaDcB14D612Eee4Bbe0); - CLONE_FACTORY = ICloneableFactoryV2(0x6d0c39093C21dA1230aCDD911420BBfA353A3FBA); + CLONE_FACTORY = ICloneableFactoryV2(0x6d0c39093C21dA1230aCDD911420BBfA353A3FBA); } } \ No newline at end of file