Skip to content

Commit

Permalink
add eval3 util
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Jul 20, 2024
1 parent 82dd9de commit 987c621
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions src/StrategyTests.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pragma solidity =0.8.25;

import "src/abstract/OrderBookStrategyTest.sol";
import {LibEncodedDispatch} from "rain.interpreter.interface/lib/caller/LibEncodedDispatch.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 Down Expand Up @@ -88,4 +90,62 @@ contract StrategyTests is OrderBookStrategyTest {
assertEq(strategyAmount, strategy.expectedAmount);
}
}

function getNamespace(address orderOwner, address contractAddress) internal pure returns (FullyQualifiedNamespace) {
return LibNamespace.qualifyNamespace(
StateNamespace.wrap(uint256(uint160(orderOwner))),
contractAddress
);
}

function evalExpression(
LibStrategyDeployment.StrategyDeployment memory strategy,
FullyQualifiedNamespace namespace,
uint256[][] memory context,
uint256[] memory inputs,
uint256 sourceIndex

) internal {
bytes memory bytecode = PARSER.parse2(
LibComposeOrders.getComposedOrder(
vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath
)
);

(uint256[] memory stack,) = INTERPRETER.eval3(
STORE,
namespace,
bytecode,
SourceIndexV2.wrap(sourceIndex),
context,
inputs
);

for(uint256 i = 0 ; i < stack.length; i++){
console2.log("stack[%s] : %s",i, stack[i]);
}
}

function getBounty(Vm.Log[] memory entries)
public
view
returns (uint256 inputTokenBounty, uint256 outputTokenBounty)
{
// Array of length 2 to store the input and ouput token bounties.
uint256[] memory bounties = new uint256[](2);

// Count the number of bounties found.
uint256 bountyCount = 0;
for (uint256 j = 0; j < entries.length; j++) {
if (
entries[j].topics[0] == keccak256("Transfer(address,address,uint256)") &&
address(ARB_INSTANCE) == abi.decode(abi.encodePacked(entries[j].topics[1]), (address)) &&
address(APPROVED_EOA) == abi.decode(abi.encodePacked(entries[j].topics[2]), (address))
) {
bounties[bountyCount] = abi.decode(entries[j].data, (uint256));
bountyCount++;
}
}
return (bounties[0], bounties[1]);
}
}
6 changes: 3 additions & 3 deletions src/abstract/OrderBookStrategyTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {IParserV2} from "rain.interpreter.interface/interface/unstable/IParserV2
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/unstable/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 {
IOrderBookV3,
Expand All @@ -22,8 +23,7 @@ import {
ActionV1,
EvaluableV3
}from "rain.orderbook.interface/interface/unstable/IOrderBookV4.sol";
import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/unstable/IOrderBookV4ArbOrderTaker.sol";

import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/unstable/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 All @@ -43,7 +43,7 @@ abstract contract OrderBookStrategyTest is Test {
IInterpreterStoreV2 public STORE;
IOrderBookV4 public ORDERBOOK;
IOrderBookV4ArbOrderTaker public ARB_INSTANCE;
IRouteProcessor public ROUTE_PROCESSOR;
IRouteProcessor public ROUTE_PROCESSOR;

function depositTokens(address owner, address token, uint256 vaultId, uint256 amount, ActionV1[] memory actionV1) internal {
vm.startPrank(owner);
Expand Down

0 comments on commit 987c621

Please sign in to comment.