Skip to content
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
2 changes: 1 addition & 1 deletion crates/test_fixtures/abis/RaindexV6.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/test_fixtures/abis/RaindexV6SubParser.json

Large diffs are not rendered by default.

Binary file modified meta/RaindexV6SubParser.rain.meta
Binary file not shown.
Binary file modified meta/RaindexV6SubParserAuthoringMeta.rain.meta
Binary file not shown.
5 changes: 5 additions & 0 deletions src/concrete/parser/RaindexV6SubParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
CONTEXT_CALCULATIONS_ROW_MAX_OUTPUT,
CONTEXT_CALCULATIONS_ROWS,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER,
CONTEXT_DEPOSIT_COLUMN,
CONTEXT_WITHDRAW_COLUMN,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER,
Expand Down Expand Up @@ -121,6 +122,8 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER] = LibParseOperand.handleOperandDisallowed;
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY] =
LibParseOperand.handleOperandDisallowed;
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER] =
LibParseOperand.handleOperandDisallowed;

function(bytes32[] memory) internal pure returns (OperandV2)[] memory contextCalculationsHandlers =
new function(bytes32[] memory) internal pure returns (OperandV2)[](CONTEXT_CALCULATIONS_ROWS);
Expand Down Expand Up @@ -216,6 +219,8 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER] = LibRaindexSubParser.subParserOrderOwner;
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY] =
LibRaindexSubParser.subParserOrderCounterparty;
contextCallingContextParsers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER] =
LibRaindexSubParser.subParserOrderClearer;

function(uint256, uint256, OperandV2) internal view returns (bool, bytes memory, bytes32[] memory)[] memory
contextCalculationsParsers =
Expand Down
34 changes: 25 additions & 9 deletions src/concrete/raindex/RaindexV6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
} from "../../lib/LibRaindex.sol";
import {RaindexV6FlashLender} from "../../abstract/RaindexV6FlashLender.sol";
import {LibBytes32Array} from "rain-solmem-0.1.28/src/lib/LibBytes32Array.sol";
import {LibBytes32Matrix} from "rain-solmem-0.1.28/src/lib/LibBytes32Matrix.sol";

import {LibFormatDecimalFloat} from "rain-math-float-0.3.10/src/lib/format/LibFormatDecimalFloat.sol";
import {
Expand Down Expand Up @@ -319,7 +318,10 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
/// with a context of the order hash and the caller.
function _doOrderPost(bytes32 orderHash, TaskV2[] calldata post) internal {
LibRaindex.doPost(
LibBytes32Matrix.matrixFrom(LibBytes32Array.arrayFrom(orderHash, bytes32(uint256(uint160(msg.sender))))),
LibRaindex.callingContextColumn(
CONTEXT_CALLING_CONTEXT_COLUMN,
LibBytes32Array.arrayFrom(orderHash, bytes32(uint256(uint160(msg.sender))))
),
post
);
}
Expand Down Expand Up @@ -351,6 +353,7 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
msg.sender,
quoteConfig.signedContext,
new bytes32[](0),
false,
false
);
// true is quote2's "order is live" result required by IRaindexV6.
Expand Down Expand Up @@ -441,7 +444,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
msg.sender,
takeOrderConfig.signedContext,
new bytes32[](0),
true
true,
false
);

// Skip orders that are too expensive rather than revert as we have
Expand Down Expand Up @@ -635,7 +639,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
bobOrder.owner,
bobSignedContext,
new bytes32[](0),
false
false,
true
);
(, OrderIOCalculationV4 memory bobOrderIOCalculation) = calculateOrderIO(
bobOrder,
Expand All @@ -644,7 +649,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
aliceOrder.owner,
aliceSignedContext,
new bytes32[](0),
false
false,
true
);

// Each side must be one `takeOrders4` would take. Given this, each
Expand Down Expand Up @@ -720,6 +726,8 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
/// single-order callers (`quote`, `clear3`).
/// @param skipFailure If true, a reverting calculate eval or a stack shorter
/// than `CALCULATE_ORDER_MIN_OUTPUTS` returns false instead of reverting.
/// @param clearing Whether the order column includes the clearer row; true
/// only for `clear3`.
/// @return False if `skipFailure` caught a failure, in which case the
/// calculation is zeroed and MUST NOT be used.
/// @return The order IO calculation.
Expand All @@ -730,15 +738,23 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
address counterparty,
SignedContextV1[] memory signedContext,
bytes32[] memory stateOverlay,
bool skipFailure
bool skipFailure,
bool clearing
) internal view returns (bool, OrderIOCalculationV4 memory) {
unchecked {
bytes32[][] memory context;
{
bytes32[][] memory callingContext = new bytes32[][](CALLING_CONTEXT_COLUMNS);
callingContext[CONTEXT_CALLING_CONTEXT_COLUMN - 1] = LibBytes32Array.arrayFrom(
order.hash(), bytes32(uint256(uint160(order.owner))), bytes32(uint256(uint160(counterparty)))
);
callingContext[CONTEXT_CALLING_CONTEXT_COLUMN - 1] = clearing
? LibBytes32Array.arrayFrom(
order.hash(),
bytes32(uint256(uint160(order.owner))),
bytes32(uint256(uint160(counterparty))),
bytes32(uint256(uint160(msg.sender)))
)
: LibBytes32Array.arrayFrom(
order.hash(), bytes32(uint256(uint160(order.owner))), bytes32(uint256(uint160(counterparty)))
);

// The calculations column holds the calculated max output and IO
// ratio, which only become known after the calculate eval below.
Expand Down
10 changes: 5 additions & 5 deletions src/generated/RaindexV6SubParserPointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pragma solidity ^0.8.25;
// THIS FILE IS AUTOGENERATED BY THE BUILD SCRIPT. DO NOT EDIT BY HAND.

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0xabceaad67b2bfb22234dced976036095d341129762d317512657852774711ece);
bytes32 constant BYTECODE_HASH = bytes32(0xbb26d1e20a8360e1508cbc0938a2ed1ad7af70827261928c041de84987ca731e);

/// @dev The hash of the meta that describes the contract.
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xa18bcfb6026768fff923ba3f6d2ab7c37c7a6ab3f226e540ca92278af8d56f2c);
bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0x8336a7fad53960ed41ca79692ce772de758261a38ddecfa23983c3b89d00aaba);

/// @dev The parse meta that is used to lookup word definitions.
/// The structure of the parse meta is:
Expand All @@ -27,7 +27,7 @@ bytes32 constant DESCRIBED_BY_META_HASH = bytes32(0xa18bcfb6026768fff923ba3f6d2a
/// bit count of the previous bloom filter. If we reach the end of the bloom
/// filters then we have a miss.
bytes constant PARSE_META =
hex"0101180010800082000100010480300038412a001810000010020004200004002038038ff54900cc66c61df3dcab0616592209895f0b14fec9301902e0920c5bfe561b21609201e959460b1974270f844db208bcd3bf1c9893761e1049db11b93430180ae9a00af82a7805c138f40d28083f0742ef2104d561fd1215a13315716a6117d260cc107b9bfc0eec7ade13cba2891a6b14a51f792bdb02e0f14716565589";
hex"0101180010a00082000100010480300038412a001810000010020004200004002038038ff54905cc66c61ef3dcab071659220a895f0b15fec9301a02e0920d5bfe561c21609201e959460c19742710844db209bcd3bf1d9893761f1049db12b93430190ae9a00bf82a7806c138f40e28083f0842ef2104d561fd1315a13316716a6118d260cc117b9bfc0fec7ade14cba28900a422961b6b14a520792bdb02e0f14717565589";

/// @dev The build depth of the parser meta.

Expand All @@ -39,13 +39,13 @@ uint8 constant PARSE_META_BUILD_DEPTH = 1;
/// to things that happen entirely on the interpreter such as well known
/// constants and references to the context grid.
bytes constant SUB_PARSER_WORD_PARSERS =
hex"16ee170b171a1729173817481757176717761786179617a517b517c417d417e417f4186818771886189618a618b618c618d518e418f41904191419241803181c";
hex"175a17771786179517a417b417c417d317e317f21802181218211831184018501860187018e418f3190219121922193219421951196019701980199019a0187f1898";

/// @dev Every two bytes is a function pointer for an operand handler.
/// These positional indexes all map to the same indexes looked up in the parse
/// meta.
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS =
hex"1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1ccb1cf41d90";
hex"1d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d471d701e0c";

/// @dev Every two bytes is a function pointer for a literal parser.
/// Literal dispatches are determined by the first byte(s) of the literal
Expand Down
10 changes: 5 additions & 5 deletions src/generated/candidate/GenericPoolRaindexV6ArbOrderTaker.sol

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/generated/candidate/GenericPoolRaindexV6FlashBorrower.sol

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/generated/candidate/RaindexV6.sol

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/generated/candidate/RaindexV6SubParser.sol

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/generated/candidate/RouteProcessorRaindexV6ArbOrderTaker.sol

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/lib/LibRaindex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ uint256 constant CONTEXT_COLUMNS = CALLING_CONTEXT_COLUMNS + 1;
/// including the first signed context column.
uint256 constant CONTEXT_COLUMNS_EXTENDED = CONTEXT_SIGNED_CONTEXT_START_COLUMN + 1;

/// @dev Contextual data available to both calculate order and handle IO. The
/// order hash, order owner and order counterparty. IMPORTANT NOTE that the
/// typical base context of an order with the caller will often be an unrelated
/// clearer of the order rather than the owner or counterparty.
/// @dev Order column. Clear gets all rows; take and quote omit the clearer;
/// add and remove order tasks get only the order hash and owner. IMPORTANT NOTE
/// that the clearer will often be unrelated to the owner or counterparty.
uint256 constant CONTEXT_CALLING_CONTEXT_COLUMN = 1;
uint256 constant CONTEXT_CALLING_CONTEXT_ROWS = 3;
uint256 constant CONTEXT_CALLING_CONTEXT_ROWS = 4;

uint256 constant CONTEXT_CALLING_CONTEXT_ROW_ORDER_HASH = 0;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER = 1;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_ORDER_COUNTERPARTY = 2;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER = 3;

/// @dev Deposit column. Filled only for deposit tasks.
uint256 constant CONTEXT_DEPOSIT_COLUMN = 5;
Expand Down
43 changes: 30 additions & 13 deletions src/lib/LibRaindexSubParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import {
CONTEXT_BASE_ROWS
} from "rainlang-interface-0.2.13/src/lib/caller/LibContext.sol";
import {
CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER,
CONTEXT_DEPOSIT_COLUMN,
CONTEXT_WITHDRAW_COLUMN,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_DEPOSITOR,
CONTEXT_CALLING_CONTEXT_ROW_WITHDRAW_WITHDRAWER,
CONTEXT_COLUMNS_EXTENDED,
CONTEXT_VAULT_OUTPUTS_COLUMN,
CONTEXT_VAULT_INPUTS_COLUMN,
Expand All @@ -36,10 +41,6 @@ import {
CONTEXT_SIGNED_CONTEXT_START_COLUMN,
CONTEXT_SIGNED_CONTEXT_START_ROW,
CONTEXT_SIGNED_CONTEXT_START_ROWS,
CONTEXT_DEPOSIT_COLUMN,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_DEPOSITOR,
CONTEXT_WITHDRAW_COLUMN,
CONTEXT_CALLING_CONTEXT_ROW_WITHDRAW_WITHDRAWER,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_ID,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_BEFORE,
Expand All @@ -56,6 +57,7 @@ import {
uint256 constant SUB_PARSER_WORD_PARSERS_LENGTH = 2;
uint8 constant EXTERN_PARSE_META_BUILD_DEPTH = 1;

bytes constant WORD_SENDER = "sender";
bytes constant WORD_ORDER_CLEARER = "order-clearer";
bytes constant WORD_RAINDEX = "raindex";
bytes constant WORD_ORDER_HASH = "order-hash";
Expand Down Expand Up @@ -118,6 +120,16 @@ library LibRaindexSubParser {
return LibSubParse.subParserContext(CONTEXT_BASE_COLUMN, CONTEXT_BASE_ROW_SENDER);
}

/// @dev Maps the "order-clearer" word to the calling context column.
function subParserOrderClearer(uint256, uint256, OperandV2)
internal
pure
returns (bool, bytes memory, bytes32[] memory)
{
//slither-disable-next-line unused-return
return LibSubParse.subParserContext(CONTEXT_CALLING_CONTEXT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER);
}

/// @dev Maps the "depositor" word to the deposit column.
function subParserDepositor(uint256, uint256, OperandV2)
internal
Expand Down Expand Up @@ -436,20 +448,18 @@ library LibRaindexSubParser {

/// @dev Builds the complete authoring metadata for all raindex context
/// words. Returns ABI-encoded `AuthoringMetaV2[]` covering every context
/// column (base, calling, calculations, vault IO, deposit, withdraw,
/// signers, signed context). The inner arrays are flattened before encoding.
/// column (base, order, calculations, vault IO, deposit, withdraw, signers,
/// signed context). The inner arrays are flattened before encoding.
//slither-disable-next-line dead-code
function authoringMetaV2() internal pure returns (bytes memory) {
AuthoringMetaV2[][] memory meta = new AuthoringMetaV2[][](CONTEXT_COLUMNS_EXTENDED);

AuthoringMetaV2[] memory contextBaseMeta = new AuthoringMetaV2[](CONTEXT_BASE_ROWS);
contextBaseMeta[CONTEXT_BASE_ROW_SENDER] = AuthoringMetaV2(
// constant WORD_ORDER_CLEARER defined above is less than 32 bytes,
// so this conversion is safe.
// forge-lint: disable-next-line(unsafe-typecast)
bytes32(WORD_ORDER_CLEARER),
"The order clearer is the address that submitted the transaction that is causing the order to execute. This MAY be the counterparty, e.g. when an order is being taken directly, but it MAY NOT be the counterparty if a third party is clearing two orders against each other."
);
contextBaseMeta[CONTEXT_BASE_ROW_SENDER] =
// constant WORD_SENDER defined above is less than 32 bytes, so this
// conversion is safe.
// forge-lint: disable-next-line(unsafe-typecast)
AuthoringMetaV2(bytes32(WORD_SENDER), "The address that called the raindex entrypoint.");
contextBaseMeta[CONTEXT_BASE_ROW_CALLING_CONTRACT] =
// constant WORD_RAINDEX defined above is less than 32 bytes, so
// this conversion is safe.
Expand All @@ -474,6 +484,13 @@ library LibRaindexSubParser {
bytes32(WORD_ORDER_COUNTERPARTY),
"The address of the owner of the counterparty order. Will be the order taker if there is no counterparty order."
);
contextCallingContextMeta[CONTEXT_CALLING_CONTEXT_ROW_ORDER_CLEARER] = AuthoringMetaV2(
// constant WORD_ORDER_CLEARER defined above is less than 32 bytes,
// so this conversion is safe.
// forge-lint: disable-next-line(unsafe-typecast)
bytes32(WORD_ORDER_CLEARER),
"The address that called clear, matching this order against a counterparty order. Only available in clears; reverts when the order is taken or quoted."
);

AuthoringMetaV2[] memory contextCalculationsMeta = new AuthoringMetaV2[](CONTEXT_CALCULATIONS_ROWS);
contextCalculationsMeta[CONTEXT_CALCULATIONS_ROW_MAX_OUTPUT] = AuthoringMetaV2(
Expand Down
11 changes: 11 additions & 0 deletions test/concrete/parser/RaindexV6SubParser.contextSender.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity =0.8.25;

import {RaindexV6SubParserContextTest} from "test/util/abstract/RaindexV6SubParserContextTest.sol";

contract RaindexV6SubParserContextSenderTest is RaindexV6SubParserContextTest {
function word() internal pure override returns (string memory) {
return "sender";
}
}
Loading
Loading