Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Action Source #14

Merged
merged 11 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ jobs:
with:
submodules: recursive
fetch-depth: 0

# https://github.com/actions/runner-images/issues/2840#issuecomment-2272410832
- run: |
sudo rm -rf \
"$AGENT_TOOLSDIRECTORY" \
/opt/google/chrome \
/opt/microsoft/msedge \
/opt/microsoft/powershell \
/opt/pipx \
/usr/lib/mono \
/usr/local/julia* \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift
df -h

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@ libs = ["lib"]

solc = "0.8.25"

# Try to make sure the optimizer doesn't touch the output in a way that can break
# source maps for debugging.
# via_ir = false
# optimizer = false
# optimizer_runs = 0
# optimizer_steps = 0

# These settings should be used for snapshots
optimizer = true
optimizer_runs = 1000000

evm_version = "cancun"
bytecode_hash = "none"
cbor_metadata = false

# Needed for dotrain compose
ffi = true

[fuzz]
runs = 1024

remappings = [
"rain.math.fixedpoint/=lib/rain.orderbook/lib/rain.interpreter/lib/rain.math.fixedpoint/src/",
]
runs = 1024
2 changes: 1 addition & 1 deletion lib/rain.orderbook
Submodule rain.orderbook updated 228 files
27 changes: 20 additions & 7 deletions src/StrategyTests.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
pragma solidity =0.8.25;

import "src/abstract/OrderBookStrategyTest.sol";
import {LibEncodedDispatch} from "rain.interpreter.interface/lib/caller/LibEncodedDispatch.sol";
import {LibEncodedDispatch} from "rain.interpreter.interface/lib/deprecated/caller/LibEncodedDispatch.sol";
import {ActionV1} from "rain.orderbook.interface/interface/IOrderBookV4.sol";
import {StateNamespace, LibNamespace, FullyQualifiedNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.sol";
import {LibStrategyDeployment} from "src/lib/LibStrategyDeployment.sol";
import {LibComposeOrders} from "src/lib/LibComposeOrder.sol";
Expand All @@ -11,7 +12,7 @@ contract StrategyTests is OrderBookStrategyTest {
// Function to add OrderBook order and deposit tokens.
// Input and Output tokens are extracted from `inputVaults` and `outputVaults`,
// indexed by `inputTokenIndex` and `outputTokenIndex`.
function addOrderDepositOutputTokens(LibStrategyDeployment.StrategyDeployment memory strategy)
function addOrderDepositOutputTokens(LibStrategyDeployment.StrategyDeploymentV4 memory strategy)
internal
returns (OrderV3 memory order)
{
Expand All @@ -35,19 +36,31 @@ contract StrategyTests is OrderBookStrategyTest {
{
depositTokens(ORDER_OWNER, outputToken, outputTokenVaultId, strategy.takerAmount, new ActionV1[](0));
}
{
{
ActionV1[] memory postAddOrderTasks;
{
bytes memory postOrderCompose = iParser.parse2(
LibComposeOrders.getComposedPostAddOrder(
vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath
)
);
EvaluableV3 memory postOrderEvaluable = EvaluableV3(iInterpreter, iStore, postOrderCompose);
ActionV1 memory postOrderAction = ActionV1(postOrderEvaluable,strategy.postAddOrderTaskSignedContext);
postAddOrderTasks = new ActionV1[](1);
postAddOrderTasks[0] = postOrderAction;
}
bytes memory bytecode = iParser.parse2(
LibComposeOrders.getComposedOrder(
vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath
)
);
order = placeOrder(ORDER_OWNER, bytecode, strategy.inputVaults, strategy.outputVaults, new ActionV1[](0));
order = placeOrder(ORDER_OWNER, bytecode, strategy.inputVaults, strategy.outputVaults, postAddOrderTasks);
}
}

// Function to assert OrderBook calculations context by calling 'takeOrders' function
// directly from the OrderBook contract.
function checkStrategyCalculations(LibStrategyDeployment.StrategyDeployment memory strategy) internal {
function checkStrategyCalculations(LibStrategyDeployment.StrategyDeploymentV4 memory strategy) internal {
OrderV3 memory order = addOrderDepositOutputTokens(strategy);
{
vm.recordLogs();
Expand All @@ -65,7 +78,7 @@ contract StrategyTests is OrderBookStrategyTest {

// Function to assert OrderBook calculations context by calling 'arb' function
// from the OrderBookV3ArbOrderTaker contract.
function checkStrategyCalculationsArbOrder(LibStrategyDeployment.StrategyDeployment memory strategy) internal {
function checkStrategyCalculationsArbOrder(LibStrategyDeployment.StrategyDeploymentV4 memory strategy) internal {
OrderV3 memory order = addOrderDepositOutputTokens(strategy);

// Move external pool price in opposite direction that of the order
Expand All @@ -92,7 +105,7 @@ contract StrategyTests is OrderBookStrategyTest {
}

function evalExpression(
LibStrategyDeployment.StrategyDeployment memory strategy,
LibStrategyDeployment.StrategyDeploymentV4 memory strategy,
FullyQualifiedNamespace namespace,
uint256[][] memory context,
uint256[] memory inputs,
Expand Down
18 changes: 8 additions & 10 deletions src/abstract/OrderBookStrategyTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ pragma solidity =0.8.25;

import {Vm} from "forge-std/Vm.sol";
import {Test, console2, stdError} from "forge-std/Test.sol";
import {IParserV1} from "rain.interpreter.interface/interface/IParserV1.sol";
import {IParserV2} from "rain.interpreter.interface/interface/unstable/IParserV2.sol";
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/unstable/IInterpreterV3.sol";
import {IParserV2} from "rain.interpreter.interface/interface/IParserV2.sol";
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/deprecated/IExpressionDeployerV3.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/IInterpreterV3.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {SourceIndexV2} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol";
import {SourceIndexV2} from "rain.interpreter.interface/interface/deprecated/IInterpreterV2.sol";
import {EvaluableConfigV3, SignedContextV1} from "rain.interpreter.interface/interface/deprecated/IInterpreterCallerV2.sol";
import {
IOrderBookV3,
IO
} from "rain.orderbook.interface/interface/IOrderBookV3.sol";
} from "rain.orderbook.interface/interface/deprecated/v3/IOrderBookV3.sol";
import {
IOrderBookV4,
OrderV3,
Expand All @@ -22,8 +21,8 @@ import {
TakeOrdersConfigV3,
ActionV1,
EvaluableV3
}from "rain.orderbook.interface/interface/unstable/IOrderBookV4.sol";
import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/unstable/IOrderBookV4ArbOrderTaker.sol";
}from "rain.orderbook.interface/interface/IOrderBookV4.sol";
import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/IOrderBookV4ArbOrderTaker.sol";
import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import {IRouteProcessor} from "src/interface/IRouteProcessor.sol";
Expand Down Expand Up @@ -77,7 +76,6 @@ abstract contract OrderBookStrategyTest is Test {
vm.recordLogs();
(bool stateChanged) = iOrderBook.addOrder2(orderV3Config,actionV1);
Vm.Log[] memory entries = vm.getRecordedLogs();
assertEq(entries.length, 1);
(,, order) = abi.decode(entries[0].data, (address, bytes32, OrderV3));
assertEq(order.owner, orderOwner);
assertEq(stateChanged, true);
Expand Down
33 changes: 31 additions & 2 deletions src/lib/LibComposeOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ library LibComposeOrders {
string memory scenario,
string memory buildPath,
string memory manifestPath
) internal returns (bytes memory trancheOrder) {
) internal returns (bytes memory composedOrder) {
string[] memory ffi = new string[](16);
ffi[0] = "nix";
ffi[1] = "develop";
Expand All @@ -33,6 +33,35 @@ library LibComposeOrders {
ffi[14] = "-s";
ffi[15] = scenario;

trancheOrder = vm.ffi(ffi);
composedOrder = vm.ffi(ffi);
}

function getComposedPostAddOrder(
Vm vm,
string memory filePath,
string memory scenario,
string memory buildPath,
string memory manifestPath
) internal returns (bytes memory composedSource) {
string[] memory ffi = new string[](17);
ffi[0] = "nix";
ffi[1] = "develop";
ffi[2] = buildPath;
ffi[3] = "--command";
ffi[4] = "cargo";
ffi[5] = "run";
ffi[6] = "--manifest-path";
ffi[7] = manifestPath;
ffi[8] = "--package";
ffi[9] = "rain_orderbook_cli";
ffi[10] = "order";
ffi[11] = "compose";
ffi[12] = "-f";
ffi[13] = filePath;
ffi[14] = "-s";
ffi[15] = scenario;
ffi[16] = "-p";

composedSource = vm.ffi(ffi);
}
}
2 changes: 1 addition & 1 deletion src/lib/LibProcessStream.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ library LibProcessStream {
}

/// Log the processed route data.
function logRoute(RouteProcessor4Route[] memory routeData) internal pure {
function logRoute(RouteProcessor4Route[] memory routeData) internal view {
if(routeData.length > 0){
for(uint256 i = 0 ; i < routeData.length; i++){
console2.log("----------------------Processed Route----------------------");
Expand Down
6 changes: 4 additions & 2 deletions src/lib/LibStrategyDeployment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
pragma solidity =0.8.25;

import {Vm} from "forge-std/Vm.sol";
import {IO} from "rain.orderbook.interface/interface/IOrderBookV3.sol";
import {IO} from "rain.orderbook.interface/interface/deprecated/v3/IOrderBookV3.sol";
import {SignedContextV1} from "rain.interpreter.interface/interface/deprecated/IInterpreterCallerV2.sol";

library LibStrategyDeployment {
struct StrategyDeployment {
struct StrategyDeploymentV4 {
bytes makerRoute;
bytes takerRoute;
uint256 inputTokenIndex;
Expand All @@ -20,5 +21,6 @@ library LibStrategyDeployment {
string manifestPath;
IO[] inputVaults;
IO[] outputVaults;
SignedContextV1[] postAddOrderTaskSignedContext;
}
}
Loading
Loading