Skip to content

Commit

Permalink
bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Aug 22, 2023
1 parent 137e2a3 commit 67dc06f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/rain.factory
2 changes: 1 addition & 1 deletion lib/rain.interpreter
10 changes: 6 additions & 4 deletions src/concrete/OrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DeployerDiscoverableMetaV2ConstructionConfig,
LibMeta
} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol";
import "rain.interpreter/src/lib/bytecode/LibBytecode.sol";

import "../interface/unstable/IOrderBookV3.sol";
import "../lib/LibOrder.sol";
Expand Down Expand Up @@ -255,10 +256,11 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLe

/// @inheritdoc IOrderBookV3
function addOrder(OrderConfig calldata config) external nonReentrant returns (bool stateChanged) {
if (config.evaluableConfig.sources.length == 0) {
uint256 sourceCount = LibBytecode.sourceCount(config.evaluableConfig.bytecode);
if (sourceCount == 0) {
revert OrderNoSources(msg.sender);
}
if (config.evaluableConfig.sources.length == 1) {
if (sourceCount == 1) {
revert OrderNoHandleIO(msg.sender);
}
if (config.validInputs.length == 0) {
Expand All @@ -271,7 +273,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLe
.evaluableConfig
.deployer
.deployExpression(
config.evaluableConfig.sources,
config.evaluableConfig.bytecode,
config.evaluableConfig.constants,
LibUint256Array.arrayFrom(CALCULATE_ORDER_MIN_OUTPUTS, HANDLE_IO_MIN_OUTPUTS)
);
Expand All @@ -281,7 +283,7 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLe
// order.
Order memory order = Order(
msg.sender,
config.evaluableConfig.sources[SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT)].length > 0,
LibBytecode.sourceOpsLength(config.evaluableConfig.bytecode, SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT)) > 0,
Evaluable(interpreter, store, expression),
config.validInputs,
config.validOutputs
Expand Down
19 changes: 11 additions & 8 deletions test/concrete/GenericPoolOrderBookFlashBorrower.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ contract MockOrderBook is IOrderBookV3 {
return (0, 0);
}

function addOrder(OrderConfig calldata config) external {}
function addOrder(OrderConfig calldata) external pure returns (bool stateChanged) {
return false;
}

function orderExists(bytes32) external pure returns (bool exists) {
return false;
}

function clear(
Order memory alice,
Order memory bob,
Expand All @@ -43,7 +50,7 @@ contract MockOrderBook is IOrderBookV3 {
function deposit(address token, uint256 vaultId, uint256 amount) external {}
function flashFee(address token, uint256 amount) external view returns (uint256) {}
function maxFlashLoan(address token) external view returns (uint256) {}
function removeOrder(Order calldata order) external {}
function removeOrder(Order calldata order) external returns (bool stateChanged) {}

function vaultBalance(address owner, address token, uint256 id) external view returns (uint256 balance) {}
function withdraw(address token, uint256 vaultId, uint256 targetAmount) external {}
Expand Down Expand Up @@ -89,9 +96,7 @@ contract GenericPoolOrderBookFlashBorrowerTest is Test {
arb_.initialize(
abi.encode(
OrderBookFlashBorrowerConfigV2(
address(ob_),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), new bytes[](0), new uint256[](0)),
""
address(ob_), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), ""
)
)
);
Expand All @@ -117,9 +122,7 @@ contract GenericPoolOrderBookFlashBorrowerTest is Test {
arb.initialize(
abi.encode(
OrderBookFlashBorrowerConfigV2(
address(ob),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), new bytes[](0), new uint256[](0)),
""
address(ob), EvaluableConfigV2(IExpressionDeployerV2(address(0)), "", new uint256[](0)), ""
)
)
);
Expand Down
12 changes: 6 additions & 6 deletions test/concrete/OrderBook.addOrder.mock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
/// Adding an order without calculations MUST revert.
function testAddOrderWithoutCalculationsReverts(address owner, OrderConfig memory config) public {
vm.prank(owner);
config.evaluableConfig.sources = new bytes[](0);
config.evaluableConfig.bytecode = "";
vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector, owner));
iOrderbook.addOrder(config);
(Order memory order, bytes32 orderHash) =
Expand All @@ -22,7 +22,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
/// Adding an order without inputs MUST revert.
function testAddOrderWithoutInputsReverts(address owner, OrderConfig memory config) public {
vm.prank(owner);
vm.assume(config.evaluableConfig.sources.length > 1);
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
config.validInputs = new IO[](0);
vm.expectRevert(abi.encodeWithSelector(OrderNoInputs.selector, owner));
iOrderbook.addOrder(config);
Expand All @@ -35,7 +35,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
/// Adding an order without outputs MUST revert.
function testAddOrderWithoutOutputsReverts(address owner, OrderConfig memory config) public {
vm.prank(owner);
vm.assume(config.evaluableConfig.sources.length > 1);
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
vm.assume(config.validInputs.length > 0);
config.validOutputs = new IO[](0);
vm.expectRevert(abi.encodeWithSelector(OrderNoOutputs.selector, owner));
Expand All @@ -54,7 +54,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
OrderConfig memory config,
address expression
) public {
vm.assume(config.evaluableConfig.sources.length >= 2);
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
vm.assume(config.validInputs.length > 0);
vm.assume(config.validOutputs.length > 0);
config.meta = new bytes(0);
Expand All @@ -67,7 +67,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
/// not self describing as a rain meta document.
function testAddOrderWithNonEmptyMetaReverts(address owner, OrderConfig memory config, address expression) public {
vm.prank(owner);
vm.assume(config.evaluableConfig.sources.length >= 2);
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
vm.assume(config.validInputs.length > 0);
vm.assume(config.validOutputs.length > 0);
vm.assume(!LibMeta.isRainMetaV1(config.meta));
Expand All @@ -93,7 +93,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
function testAddOrderWithNonEmptyMetaEmitsMetaV1(address owner, OrderConfig memory config, address expression)
public
{
vm.assume(config.evaluableConfig.sources.length >= 2);
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
vm.assume(config.validInputs.length > 0);
vm.assume(config.validOutputs.length > 0);
vm.assume(config.meta.length > 0);
Expand Down
30 changes: 15 additions & 15 deletions test/concrete/OrderBook.addOrder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest {
/// No sources reverts as we need at least a calculate expression.
function testAddOrderRealNoSourcesReverts(address owner, OrderConfig memory config) public {
LibTestAddOrder.conformConfig(config, iDeployer);
config.evaluableConfig.sources = new bytes[](0);
config.evaluableConfig.bytecode = hex"";
vm.expectRevert(abi.encodeWithSelector(OrderNoSources.selector, owner));
vm.prank(owner);
iOrderbook.addOrder(config);
Expand All @@ -19,9 +19,9 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest {
/// No handle IO reverts.
function testAddOrderRealNoHandleIOReverts(address owner, OrderConfig memory config) public {
LibTestAddOrder.conformConfig(config, iDeployer);
(bytes[] memory sources, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;");
(constants);
config.evaluableConfig.sources = sources;
(bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;");
config.evaluableConfig.bytecode = bytecode;
config.evaluableConfig.constants = constants;
vm.expectRevert(abi.encodeWithSelector(OrderNoHandleIO.selector, owner));
vm.prank(owner);
iOrderbook.addOrder(config);
Expand All @@ -33,41 +33,41 @@ contract OrderBookAddOrderTest is OrderBookExternalRealTest {
(bytes memory bytecode, uint256[] memory constants) = IParserV1(address(iDeployer)).parse(":;:;");
config.evaluableConfig.constants = constants;
config.evaluableConfig.bytecode = bytecode;
// vm.expectRevert(abi.encodeWithSelector(MinFinalStack.selector, 2, 0));
vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 0, 2));
vm.prank(owner);
iOrderbook.addOrder(config);
}

/// A stack of 1 for calculate order reverts.
function testAddOrderRealOneStackCalculateReverts(address owner, OrderConfig memory config) public {
LibTestAddOrder.conformConfig(config, iDeployer);
(bytes memory sources, uint256[] memory constants) =
(bytes memory bytecode, uint256[] memory constants) =
IParserV1(address(iDeployer)).parse("_:block-timestamp();:;");
(constants);
config.evaluableConfig.sources = sources;
// vm.expectRevert(abi.encodeWithSelector(MinFinalStack.selector, 2, 1));
config.evaluableConfig.constants = constants;
config.evaluableConfig.bytecode = bytecode;
vm.expectRevert(abi.encodeWithSelector(EntrypointMinOutputs.selector, 0, 1, 2));
vm.prank(owner);
iOrderbook.addOrder(config);
}

/// A stack of 2 for calculate order deploys.
function testAddOrderRealTwoStackCalculateReverts(address owner, OrderConfig memory config) public {
LibTestAddOrder.conformConfig(config, iDeployer);
(bytes[] memory sources, uint256[] memory constants) =
(bytes memory bytecode, uint256[] memory constants) =
IParserV1(address(iDeployer)).parse("_ _:block-timestamp() chain-id();:;");
(constants);
config.evaluableConfig.sources = sources;
config.evaluableConfig.constants = constants;
config.evaluableConfig.bytecode = bytecode;
vm.prank(owner);
iOrderbook.addOrder(config);
}

/// A stack of 3 for calculate order deploys.
function testAddOrderRealThreeStackCalculate(address owner, OrderConfig memory config) public {
LibTestAddOrder.conformConfig(config, iDeployer);
(bytes[] memory sources, uint256[] memory constants) =
(bytes memory bytecode, uint256[] memory constants) =
IParserV1(address(iDeployer)).parse("_ _ _:block-timestamp() chain-id() block-number();:;");
(constants);
config.evaluableConfig.sources = sources;
config.evaluableConfig.constants = constants;
config.evaluableConfig.bytecode = bytecode;
vm.prank(owner);
iOrderbook.addOrder(config);
}
Expand Down
16 changes: 4 additions & 12 deletions test/util/lib/LibTestAddOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ library LibTestAddOrder {
Evaluable memory expectedEvaluable = Evaluable(interpreter, store, expression);
Order memory order = Order(
owner,
config.evaluableConfig.sources.length > 1
&& config.evaluableConfig.sources[SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT)].length > 0,
LibBytecode.sourceCount(config.evaluableConfig.bytecode) > 1
&& LibBytecode.sourceOpsLength(config.evaluableConfig.bytecode, SourceIndex.unwrap(HANDLE_IO_ENTRYPOINT))
> 0,
expectedEvaluable,
config.validInputs,
config.validOutputs
Expand All @@ -46,15 +47,6 @@ library LibTestAddOrder {
config.validOutputs = new IO[](1);
config.validOutputs[0] = IO(address(0), 0, 0);
}
if (config.evaluableConfig.sources.length == 0) {
config.evaluableConfig.sources = new bytes[](2);
config.evaluableConfig.sources[0] = new bytes(0);
config.evaluableConfig.sources[1] = new bytes(0);
} else if (config.evaluableConfig.sources.length == 1) {
bytes[] memory sources = new bytes[](2);
sources[0] = config.evaluableConfig.sources[0];
sources[1] = new bytes(0);
config.evaluableConfig.sources = sources;
}
config.evaluableConfig.bytecode = hex"02000000040000000000000000";
}
}

0 comments on commit 67dc06f

Please sign in to comment.