Skip to content

Commit

Permalink
wip on bumping deps
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Aug 22, 2023
1 parent 2ac2cd2 commit 137e2a3
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 87 deletions.
15 changes: 6 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "lib/rain.math.fixedpoint"]
path = lib/rain.math.fixedpoint
url = https://github.com/rainprotocol/rain.math.fixedpoint
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
Expand All @@ -10,12 +7,6 @@
[submodule "lib/rain.erc1820"]
path = lib/rain.erc1820
url = https://github.com/rainprotocol/rain.erc1820
[submodule "lib/rain.interpreter"]
path = lib/rain.interpreter
url = https://github.com/rainprotocol/rain.interpreter
[submodule "lib/rain.factory"]
path = lib/rain.factory
url = https://github.com/rainprotocol/rain.factory
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Expand All @@ -25,3 +16,9 @@
[submodule "lib/rain.datacontract"]
path = lib/rain.datacontract
url = https://github.com/rainprotocol/rain.datacontract
[submodule "lib/rain.factory"]
path = lib/rain.factory
url = https://github.com/rainprotocol/rain.factory
[submodule "lib/rain.interpreter"]
path = lib/rain.interpreter
url = https://github.com/rainprotocol/rain.interpreter
2 changes: 1 addition & 1 deletion lib/rain.factory
2 changes: 1 addition & 1 deletion lib/rain.interpreter
1 change: 0 additions & 1 deletion lib/rain.math.fixedpoint
Submodule rain.math.fixedpoint deleted from 84cb2a
2 changes: 1 addition & 1 deletion script/DeployGenericPoolOrderBookFlashBorrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract DeployGenericPoolOrderBookFlashBorrower is Script {

vm.startBroadcast(deployerPrivateKey);
GenericPoolOrderBookFlashBorrower deployed =
new GenericPoolOrderBookFlashBorrower(DeployerDiscoverableMetaV1ConstructionConfig (
new GenericPoolOrderBookFlashBorrower(DeployerDiscoverableMetaV2ConstructionConfig (
i9rDeployer,
meta
));
Expand Down
2 changes: 1 addition & 1 deletion script/DeployOrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DeployOrderBook is Script {
console2.logBytes32(keccak256(meta));

vm.startBroadcast(deployerPrivateKey);
OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV1ConstructionConfig (
OrderBook deployed = new OrderBook(DeployerDiscoverableMetaV2ConstructionConfig (
i9rDeployer,
meta
));
Expand Down
37 changes: 19 additions & 18 deletions src/abstract/OrderBookFlashBorrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "openzeppelin-contracts/contracts/security/ReentrancyGuard.sol";
import {Initializable} from "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol";
import {
DeployerDiscoverableMetaV1,
DeployerDiscoverableMetaV1ConstructionConfig,
DeployerDiscoverableMetaV2,
DeployerDiscoverableMetaV2ConstructionConfig,
LibMeta
} from "rain.interpreter/abstract/DeployerDiscoverableMetaV1.sol";
} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol";
import "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol";
import "rain.interpreter/src/lib/caller/LibContext.sol";
import "rain.interpreter/src/lib/bytecode/LibBytecode.sol";

import "../interface/IOrderBookV2.sol";
import "../interface/unstable/IOrderBookV3.sol";
import "rain.factory/src/interface/ICloneableV2.sol";
import "rain.interpreter/lib/caller/LibEncodedDispatch.sol";
import "rain.interpreter/lib/caller/LibContext.sol";

/// Thrown when the lender is not the trusted `OrderBook`.
/// @param badLender The untrusted lender calling `onFlashLoan`.
Expand Down Expand Up @@ -48,9 +49,9 @@ error NonZeroBeforeArbStack();
/// @param evaluableConfig The config to eval for access control to arb.
/// @param implementationData Arbitrary bytes to pass to the implementation in
/// the `beforeInitialize` hook.
struct OrderBookFlashBorrowerConfig {
struct OrderBookFlashBorrowerConfigV2 {
address orderBook;
EvaluableConfig evaluableConfig;
EvaluableConfigV2 evaluableConfig;
bytes implementationData;
}

Expand Down Expand Up @@ -97,7 +98,7 @@ abstract contract OrderBookFlashBorrower is
ICloneableV2,
ReentrancyGuard,
Initializable,
DeployerDiscoverableMetaV1,
DeployerDiscoverableMetaV2,
ERC165
{
using Address for address;
Expand All @@ -106,10 +107,10 @@ abstract contract OrderBookFlashBorrower is
/// Emitted when the contract is initialized. Contains the
/// OrderBookFlashBorrowerConfig struct to ensure the type appears in the
/// ABI.
event Initialize(address sender, OrderBookFlashBorrowerConfig config);
event Initialize(address sender, OrderBookFlashBorrowerConfigV2 config);

/// `OrderBook` contract to lend and arb against.
IOrderBookV2 public sOrderBook;
IOrderBookV3 public sOrderBook;

/// The encoded dispatch that will run for access control to `arb`.
EncodedDispatch public sI9rDispatch;
Expand All @@ -118,8 +119,8 @@ abstract contract OrderBookFlashBorrower is
/// The associated store for the interpreter.
IInterpreterStoreV1 public sI9rStore;

constructor(bytes32 metaHash, DeployerDiscoverableMetaV1ConstructionConfig memory config)
DeployerDiscoverableMetaV1(metaHash, config)
constructor(bytes32 metaHash, DeployerDiscoverableMetaV2ConstructionConfig memory config)
DeployerDiscoverableMetaV2(metaHash, config)
{
// Arb contracts are expected to be cloned proxies so allowing
// initialization of the implementation is a security risk.
Expand All @@ -140,26 +141,26 @@ abstract contract OrderBookFlashBorrower is

/// Type hints for the input encoding for the `initialize` function.
/// Reverts ALWAYS with `InitializeSignatureFn` as per ICloneableV2.
function initialize(OrderBookFlashBorrowerConfig memory) external pure returns (bytes32) {
function initialize(OrderBookFlashBorrowerConfigV2 memory) external pure returns (bytes32) {
revert InitializeSignatureFn();
}

/// @inheritdoc ICloneableV2
function initialize(bytes memory data) external initializer nonReentrant returns (bytes32) {
(OrderBookFlashBorrowerConfig memory config) = abi.decode(data, (OrderBookFlashBorrowerConfig));
(OrderBookFlashBorrowerConfigV2 memory config) = abi.decode(data, (OrderBookFlashBorrowerConfigV2));

// Dispatch the hook before any external calls are made.
_beforeInitialize(config.implementationData);

// @todo This could be paramaterised on `arb`.
sOrderBook = IOrderBookV2(config.orderBook);
sOrderBook = IOrderBookV3(config.orderBook);

// Emit events before any external calls are made.
emit Initialize(msg.sender, config);

// If there are sources to eval then initialize the dispatch, otherwise
// it will remain 0 and we can skip evaluation on `arb`.
if (config.evaluableConfig.sources.length > 0 && config.evaluableConfig.sources[0].length > 0) {
if (LibBytecode.sourceCount(config.evaluableConfig.bytecode) > 0) {
address expression;

uint256[] memory entrypoints = new uint256[](1);
Expand All @@ -171,7 +172,7 @@ abstract contract OrderBookFlashBorrower is
// modifier on them so can't be reentered here anyway.
//slither-disable-next-line reentrancy-benign
(sI9r, sI9rStore, expression) = config.evaluableConfig.deployer.deployExpression(
config.evaluableConfig.sources, config.evaluableConfig.constants, entrypoints
config.evaluableConfig.bytecode, config.evaluableConfig.constants, entrypoints
);
sI9rDispatch = LibEncodedDispatch.encode(expression, BEFORE_ARB_SOURCE_INDEX, BEFORE_ARB_MAX_OUTPUTS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/concrete/GenericPoolOrderBookFlashBorrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract GenericPoolOrderBookFlashBorrower is OrderBookFlashBorrower {
using SafeERC20 for IERC20;
using Address for address;

constructor(DeployerDiscoverableMetaV1ConstructionConfig memory config)
constructor(DeployerDiscoverableMetaV2ConstructionConfig memory config)
OrderBookFlashBorrower(CALLER_META_HASH, config)
{}

Expand Down
16 changes: 8 additions & 8 deletions src/concrete/OrderBook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {ReentrancyGuard} from "openzeppelin-contracts/contracts/security/Reentra

import "rain.math.fixedpoint/FixedPointDecimalArithmeticOpenZeppelin.sol";
import "rain.math.fixedpoint/FixedPointDecimalScale.sol";
import "rain.interpreter/lib/caller/LibEncodedDispatch.sol";
import "rain.interpreter/lib/caller/LibContext.sol";
import "rain.interpreter/src/lib/caller/LibEncodedDispatch.sol";
import "rain.interpreter/src/lib/caller/LibContext.sol";
import {
DeployerDiscoverableMetaV1,
DeployerDiscoverableMetaV1ConstructionConfig,
DeployerDiscoverableMetaV2,
DeployerDiscoverableMetaV2ConstructionConfig,
LibMeta
} from "rain.interpreter/abstract/DeployerDiscoverableMetaV1.sol";
} from "rain.interpreter/src/abstract/DeployerDiscoverableMetaV2.sol";

import "../interface/unstable/IOrderBookV3.sol";
import "../lib/LibOrder.sol";
Expand Down Expand Up @@ -157,7 +157,7 @@ struct OrderIOCalculation {

/// @title OrderBook
/// See `IOrderBookV1` for more documentation.
contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLender, DeployerDiscoverableMetaV1 {
contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLender, DeployerDiscoverableMetaV2 {
using LibUint256Array for uint256[];
using SafeERC20 for IERC20;
using LibOrder for Order;
Expand Down Expand Up @@ -188,8 +188,8 @@ contract OrderBook is IOrderBookV3, ReentrancyGuard, Multicall, OrderBookFlashLe
/// Open Zeppelin upgradeable contracts. Orderbook itself does NOT support
/// factory deployments as each order is a unique expression deployment
/// rather than needing to wrap up expressions with proxies.
constructor(DeployerDiscoverableMetaV1ConstructionConfig memory config)
DeployerDiscoverableMetaV1(CALLER_META_HASH, config)
constructor(DeployerDiscoverableMetaV2ConstructionConfig memory config)
DeployerDiscoverableMetaV2(CALLER_META_HASH, config)
{}

/// Guard against read-only reentrancy.
Expand Down
6 changes: 3 additions & 3 deletions src/interface/IOrderBookV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.18;

import "./ierc3156/IERC3156FlashLender.sol";
import "rain.interpreter/lib/caller/LibEvaluable.sol";
import "rain.interpreter/interface/IInterpreterCallerV2.sol";
import "rain.interpreter/src/lib/caller/LibEvaluable.sol";
import "rain.interpreter/src/interface/IInterpreterCallerV2.sol";

/// Configuration for a deposit. All deposits are processed by and for
/// `msg.sender` so the vaults are unambiguous here.
Expand Down Expand Up @@ -321,7 +321,7 @@ interface IOrderBookV2 is IERC3156FlashLender, IInterpreterCallerV2 {
/// @param orderHash The hash of the order as it is recorded onchain. Only
/// the hash is stored in Orderbook storage to avoid paying gas to store the
/// entire order.
event AddOrder(address sender, IExpressionDeployerV1 expressionDeployer, Order order, uint256 orderHash);
event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, uint256 orderHash);

/// An order has been removed from the orderbook. This effectively
/// deactivates it. Orders can be added again after removal.
Expand Down
6 changes: 3 additions & 3 deletions src/interface/deprecated/IOrderBookV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.18;

import "../ierc3156/IERC3156FlashLender.sol";
import "rain.interpreter/lib/caller/LibEvaluable.sol";
import "rain.interpreter/interface/deprecated/IInterpreterCallerV1.sol";
import "rain.interpreter/src/lib/caller/LibEvaluable.sol";
import "rain.interpreter/src/interface/deprecated/IInterpreterCallerV1.sol";

/// Configuration for a deposit. All deposits are processed by and for
/// `msg.sender` so the vaults are unambiguous here.
Expand Down Expand Up @@ -321,7 +321,7 @@ interface IOrderBookV1 is IERC3156FlashLender, IInterpreterCallerV1 {
/// @param orderHash The hash of the order as it is recorded onchain. Only
/// the hash is stored in Orderbook storage to avoid paying gas to store the
/// entire order.
event AddOrder(address sender, IExpressionDeployerV1 expressionDeployer, Order order, uint256 orderHash);
event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, uint256 orderHash);

/// An order has been removed from the orderbook. This effectively
/// deactivates it. Orders can be added again after removal.
Expand Down
8 changes: 4 additions & 4 deletions src/interface/unstable/IOrderBookV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.18;

import "../ierc3156/IERC3156FlashLender.sol";
import "rain.interpreter/lib/caller/LibEvaluable.sol";
import "rain.interpreter/interface/IInterpreterCallerV2.sol";
import "rain.interpreter/src/lib/caller/LibEvaluable.sol";
import "rain.interpreter/src/interface/IInterpreterCallerV2.sol";

/// Configuration for a single input or output on an `Order`.
/// @param token The token to either send from the owner as an output or receive
Expand Down Expand Up @@ -40,7 +40,7 @@ struct IO {
struct OrderConfig {
IO[] validInputs;
IO[] validOutputs;
EvaluableConfig evaluableConfig;
EvaluableConfigV2 evaluableConfig;
bytes meta;
}

Expand Down Expand Up @@ -345,7 +345,7 @@ interface IOrderBookV3 is IERC3156FlashLender, IInterpreterCallerV2 {
/// @param orderHash The hash of the order as it is recorded onchain. Only
/// the hash is stored in Orderbook storage to avoid paying gas to store the
/// entire order.
event AddOrder(address sender, IExpressionDeployerV1 expressionDeployer, Order order, bytes32 orderHash);
event AddOrder(address sender, IExpressionDeployerV2 expressionDeployer, Order order, bytes32 orderHash);

/// An order has been removed from the orderbook. This effectively
/// deactivates it. Orders can be added again after removal.
Expand Down
20 changes: 10 additions & 10 deletions test/concrete/GenericPoolOrderBookFlashBorrower.sender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "test/util/lib/LibTestConstants.sol";
import "test/util/lib/LibGenericPoolOrderBookFlashBorrowerConstants.sol";

import "src/concrete/GenericPoolOrderBookFlashBorrower.sol";
import "src/interface/IOrderBookV2.sol";
import "src/interface/unstable/IOrderBookV3.sol";

contract Token is ERC20 {
constructor() ERC20("Token", "TKN") {}
Expand All @@ -19,7 +19,7 @@ contract Token is ERC20 {
}
}

contract MockOrderBook is IOrderBookV2 {
contract MockOrderBook is IOrderBookV3 {
function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes calldata data)
external
returns (bool)
Expand All @@ -40,13 +40,13 @@ contract MockOrderBook is IOrderBookV2 {
SignedContextV1[] memory aliceSignedContextV1,
SignedContextV1[] memory bobSignedContextV1
) external {}
function deposit(DepositConfig calldata config) external {}
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 vaultBalance(address owner, address token, uint256 id) external view returns (uint256 balance) {}
function withdraw(WithdrawConfig calldata config) external {}
function withdraw(address token, uint256 vaultId, uint256 targetAmount) external {}
}

contract Mock0xProxy {
Expand All @@ -65,13 +65,13 @@ contract GenericPoolOrderBookFlashBorrowerTest is Test {
vm.etch(deployer, REVERTING_MOCK_BYTECODE);
vm.mockCall(
deployer,
abi.encodeWithSelector(IExpressionDeployerV1.deployExpression.selector),
abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector),
abi.encode(address(0), address(0), address(0))
);
bytes memory meta = vm.readFileBinary(GENERIC_POOL_ORDER_BOOK_FLASH_BORROWER_META_PATH);
console2.logBytes32(keccak256(meta));
implementation = address(
new GenericPoolOrderBookFlashBorrower(DeployerDiscoverableMetaV1ConstructionConfig(
new GenericPoolOrderBookFlashBorrower(DeployerDiscoverableMetaV2ConstructionConfig(
deployer,
meta
))
Expand All @@ -88,9 +88,9 @@ contract GenericPoolOrderBookFlashBorrowerTest is Test {
GenericPoolOrderBookFlashBorrower arb_ = GenericPoolOrderBookFlashBorrower(Clones.clone(implementation));
arb_.initialize(
abi.encode(
OrderBookFlashBorrowerConfig(
OrderBookFlashBorrowerConfigV2(
address(ob_),
EvaluableConfig(IExpressionDeployerV1(address(0)), new bytes[](0), new uint256[](0)),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), new bytes[](0), new uint256[](0)),
""
)
)
Expand All @@ -116,9 +116,9 @@ contract GenericPoolOrderBookFlashBorrowerTest is Test {
GenericPoolOrderBookFlashBorrower arb = GenericPoolOrderBookFlashBorrower(Clones.clone(implementation));
arb.initialize(
abi.encode(
OrderBookFlashBorrowerConfig(
OrderBookFlashBorrowerConfigV2(
address(ob),
EvaluableConfig(IExpressionDeployerV1(address(0)), new bytes[](0), new uint256[](0)),
EvaluableConfigV2(IExpressionDeployerV2(address(0)), new bytes[](0), new uint256[](0)),
""
)
)
Expand Down
2 changes: 1 addition & 1 deletion test/concrete/OrderBook.addOrder.mock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ contract OrderBookAddOrderMockTest is OrderBookExternalMockTest {
config.evaluableConfig.deployer = iDeployer;
vm.mockCall(
address(iDeployer),
abi.encodeWithSelector(IExpressionDeployerV1.deployExpression.selector),
abi.encodeWithSelector(IExpressionDeployerV2.deployExpression.selector),
abi.encode(iInterpreter, iStore, expression)
);
vm.expectRevert(abi.encodeWithSelector(NotRainMetaV1.selector, config.meta));
Expand Down
Loading

0 comments on commit 137e2a3

Please sign in to comment.