Skip to content
Closed
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.
42 changes: 22 additions & 20 deletions src/concrete/parser/RaindexV6SubParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {LibUint256Matrix} from "rain-solmem-0.1.28/src/lib/LibUint256Matrix.sol"
import {
LibRaindexSubParser,
SUB_PARSER_WORD_PARSERS_LENGTH,
BASE_WORD_RAINDEX,
BASE_WORDS_LENGTH,
DEPOSIT_WORD_VAULT_ID,
DEPOSIT_WORD_TOKEN,
DEPOSIT_WORD_DEPOSITOR,
Expand All @@ -30,12 +32,7 @@ import {
WITHDRAW_WORD_TOKEN_DECIMALS,
WITHDRAW_WORDS_LENGTH
} from "../../lib/LibRaindexSubParser.sol";
import {
CONTEXT_BASE_COLUMN,
CONTEXT_BASE_ROW_SENDER,
CONTEXT_BASE_ROW_CALLING_CONTRACT,
CONTEXT_BASE_ROWS
} from "rainlang-interface-0.2.13/src/lib/caller/LibContext.sol";
import {CONTEXT_BASE_COLUMN} from "rainlang-interface-0.2.13/src/lib/caller/LibContext.sol";
import {
CONTEXT_COLUMNS_EXTENDED,
CONTEXT_VAULT_OUTPUTS_COLUMN,
Expand All @@ -51,6 +48,9 @@ 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,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_HASH,
CONTEXT_CALLING_CONTEXT_ROWS,
Expand All @@ -72,8 +72,8 @@ import {IDescribedByMetaV1} from "rain-metadata-0.1.43/src/interface/IDescribedB
import {ISubParserToolingV1} from "rain-sol-codegen-0.1.39/src/interface/ISubParserToolingV1.sol";

/// @title RaindexV6SubParser
/// @notice Sub-parser that provides raindex-specific context words (sender,
/// order hash, vault IO, deposit/withdraw, signed context, etc.) to the
/// @notice Sub-parser that provides raindex-specific context words (raindex,
/// order hash, clearer, vault IO, deposit/withdraw, signed context, etc.) to the
/// Rain interpreter.
contract RaindexV6SubParser is BaseRainlangSubParser {
using LibUint256Matrix for uint256[][];
Expand Down Expand Up @@ -109,16 +109,17 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
new function(bytes32[] memory) internal pure returns (OperandV2)[][](CONTEXT_COLUMNS_EXTENDED);

function(bytes32[] memory) internal pure returns (OperandV2)[] memory contextBaseHandlers =
new function(bytes32[] memory) internal pure returns (OperandV2)[](CONTEXT_BASE_ROWS);
contextBaseHandlers[CONTEXT_BASE_ROW_SENDER] = LibParseOperand.handleOperandDisallowed;
contextBaseHandlers[CONTEXT_BASE_ROW_CALLING_CONTRACT] = LibParseOperand.handleOperandDisallowed;
new function(bytes32[] memory) internal pure returns (OperandV2)[](BASE_WORDS_LENGTH);
contextBaseHandlers[BASE_WORD_RAINDEX] = LibParseOperand.handleOperandDisallowed;

function(bytes32[] memory) internal pure returns (OperandV2)[] memory contextCallingContextHandlers =
new function(bytes32[] memory) internal pure returns (OperandV2)[](CONTEXT_CALLING_CONTEXT_ROWS);
contextCallingContextHandlers[CONTEXT_CALLING_CONTEXT_ROW_ORDER_HASH] = LibParseOperand.handleOperandDisallowed;
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 @@ -167,7 +168,7 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
contextDepositContextHandlers[DEPOSIT_WORD_VAULT_AFTER] = LibParseOperand.handleOperandDisallowed;
contextDepositContextHandlers[DEPOSIT_WORD_TOKEN_DECIMALS] = LibParseOperand.handleOperandDisallowed;

handlers[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 1] = contextDepositContextHandlers;
handlers[CONTEXT_DEPOSIT_COLUMN] = contextDepositContextHandlers;

function(bytes32[] memory) internal pure returns (OperandV2)[] memory contextWithdrawContextHandlers =
new function(bytes32[] memory) internal pure returns (OperandV2)[](WITHDRAW_WORDS_LENGTH);
Expand All @@ -179,7 +180,7 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
contextWithdrawContextHandlers[WITHDRAW_WORD_TARGET_AMOUNT] = LibParseOperand.handleOperandDisallowed;
contextWithdrawContextHandlers[WITHDRAW_WORD_TOKEN_DECIMALS] = LibParseOperand.handleOperandDisallowed;

handlers[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 2] = contextWithdrawContextHandlers;
handlers[CONTEXT_WITHDRAW_COLUMN] = contextWithdrawContextHandlers;

uint256[][] memory handlersUint256;
assembly ("memory-safe") {
Expand All @@ -201,9 +202,8 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
contextBaseParsers =
new function(uint256, uint256, OperandV2)
internal
view returns (bool, bytes memory, bytes32[] memory)[](CONTEXT_BASE_ROWS);
contextBaseParsers[CONTEXT_BASE_ROW_SENDER] = LibRaindexSubParser.subParserSender;
contextBaseParsers[CONTEXT_BASE_ROW_CALLING_CONTRACT] = LibRaindexSubParser.subParserCallingContract;
view returns (bool, bytes memory, bytes32[] memory)[](BASE_WORDS_LENGTH);
contextBaseParsers[BASE_WORD_RAINDEX] = LibRaindexSubParser.subParserCallingContract;

function(uint256, uint256, OperandV2) internal view returns (bool, bytes memory, bytes32[] memory)[] memory
contextCallingContextParsers =
Expand All @@ -214,6 +214,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 Expand Up @@ -275,14 +277,14 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
internal
view returns (bool, bytes memory, bytes32[] memory)[](DEPOSIT_WORDS_LENGTH);

depositParsers[DEPOSIT_WORD_DEPOSITOR] = LibRaindexSubParser.subParserSender;
depositParsers[DEPOSIT_WORD_DEPOSITOR] = LibRaindexSubParser.subParserDepositor;
depositParsers[DEPOSIT_WORD_TOKEN] = LibRaindexSubParser.subParserDepositToken;
depositParsers[DEPOSIT_WORD_VAULT_ID] = LibRaindexSubParser.subParserDepositVaultId;
depositParsers[DEPOSIT_WORD_VAULT_BEFORE] = LibRaindexSubParser.subParserDepositVaultBalanceBefore;
depositParsers[DEPOSIT_WORD_VAULT_AFTER] = LibRaindexSubParser.subParserDepositVaultBalanceAfter;
depositParsers[DEPOSIT_WORD_TOKEN_DECIMALS] = LibRaindexSubParser.subParserDepositTokenDecimals;

parsers[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 1] = depositParsers;
parsers[CONTEXT_DEPOSIT_COLUMN] = depositParsers;

// Withdraws

Expand All @@ -292,15 +294,15 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
internal
view returns (bool, bytes memory, bytes32[] memory)[](WITHDRAW_WORDS_LENGTH);

withdrawParsers[WITHDRAW_WORD_WITHDRAWER] = LibRaindexSubParser.subParserSender;
withdrawParsers[WITHDRAW_WORD_WITHDRAWER] = LibRaindexSubParser.subParserWithdrawer;
withdrawParsers[WITHDRAW_WORD_TOKEN] = LibRaindexSubParser.subParserWithdrawToken;
withdrawParsers[WITHDRAW_WORD_VAULT_ID] = LibRaindexSubParser.subParserWithdrawVaultId;
withdrawParsers[WITHDRAW_WORD_VAULT_BEFORE] = LibRaindexSubParser.subParserWithdrawVaultBalanceBefore;
withdrawParsers[WITHDRAW_WORD_VAULT_AFTER] = LibRaindexSubParser.subParserWithdrawVaultBalanceAfter;
withdrawParsers[WITHDRAW_WORD_TARGET_AMOUNT] = LibRaindexSubParser.subParserWithdrawTargetAmount;
withdrawParsers[WITHDRAW_WORD_TOKEN_DECIMALS] = LibRaindexSubParser.subParserWithdrawTokenDecimals;

parsers[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 2] = withdrawParsers;
parsers[CONTEXT_WITHDRAW_COLUMN] = withdrawParsers;

uint256[][] memory parsersUint256;
assembly ("memory-safe") {
Expand Down
46 changes: 29 additions & 17 deletions src/concrete/raindex/RaindexV6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import {LibOrder} from "../../lib/LibOrder.sol";
import {
CALLING_CONTEXT_COLUMNS,
CONTEXT_CALLING_CONTEXT_COLUMN,
CONTEXT_DEPOSIT_COLUMN,
CONTEXT_WITHDRAW_COLUMN,
CONTEXT_CALCULATIONS_COLUMN,
CONTEXT_CALCULATIONS_ROWS,
CONTEXT_VAULT_IO_BALANCE_DIFF,
Expand All @@ -62,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 @@ -175,13 +176,15 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex

if (post.length != 0) {
LibRaindex.doPost(
LibBytes32Matrix.matrixFrom(
LibRaindex.callingContextColumn(
CONTEXT_DEPOSIT_COLUMN,
LibBytes32Array.arrayFrom(
bytes32(uint256(uint160(token))),
bytes32(vaultId),
Float.unwrap(beforeBalance),
Float.unwrap(afterBalance),
bytes32(uint256(decimals))
bytes32(uint256(decimals)),
bytes32(uint256(uint160(msg.sender)))
)
),
post
Expand Down Expand Up @@ -212,19 +215,22 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
emit WithdrawV2(msg.sender, token, vaultId, targetAmount, withdrawAmount, withdrawAmountUint256);
}

bytes32[] memory contextColumn = LibBytes32Array.arrayFrom(
bytes32(uint256(uint160(token))),
vaultId,
Float.unwrap(beforeBalance),
Float.unwrap(afterBalance),
Float.unwrap(targetAmount),
bytes32(uint256(decimals))
);

bytes32[][] memory context = LibBytes32Matrix.matrixFrom(contextColumn);

if (post.length != 0) {
LibRaindex.doPost(context, post);
LibRaindex.doPost(
LibRaindex.callingContextColumn(
CONTEXT_WITHDRAW_COLUMN,
LibBytes32Array.arrayFrom(
bytes32(uint256(uint160(token))),
vaultId,
Float.unwrap(beforeBalance),
Float.unwrap(afterBalance),
Float.unwrap(targetAmount),
bytes32(uint256(decimals)),
bytes32(uint256(uint160(msg.sender)))
)
),
post
);
}
}

Expand Down Expand Up @@ -307,7 +313,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 @@ -713,7 +722,10 @@ contract RaindexV6 is IRaindexV6, IMetaV1_2, ReentrancyGuard, Multicall, Raindex
{
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)))
order.hash(),
bytes32(uint256(uint160(order.owner))),
bytes32(uint256(uint160(counterparty))),
bytes32(uint256(uint160(msg.sender)))
);

// The calculations column holds the calculated max output and IO
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(0xb5f18596862c369ecb1bc3cf69399785a578427214d9372d94d0fde2ed0ecaeb);
bytes32 constant BYTECODE_HASH = bytes32(0xfaadc632ff51c921c614024250a4da3c52780d22d85a928ec8e2f32b21a84ebd);

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

/// @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(0xf2d0eca454c544ab10f9991c0193
/// 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"0101180010800082000100010480300038412a001810000010020004200004002038038ff54900cc66c61ff3dcab0616592209895f0b16fec9301b02e0920c5bfe561d21609201e959460b1974270f844db208bcd3bf1e989376111049db13b934301a0ae9a00af82a7805c138f40d28083f0742ef2104d561fd1415a13317716a6119d260cc107b9bfc0eec7ade15cba2891c6b14a512792bdb02e0f14718565589";
hex"0101180010800082000100010480300038412a001810000010020004200004002038028ff54904cc66c61df3dcab0616592209895f0b14fec9301902e0920c5bfe561b21609200e959460b1974270f844db208bcd3bf1c9893761e1049db11b93430180ae9a00af82a7805c138f40d28083f0742ef2103d561fd1215a13315716a6117d260cc107b9bfc0eec7ade13cba2891a6b14a51f792bdb01e0f14716565589";

/// @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"16cc16e916f8170717161726173517451754176417741783179317a217b217c217d217e117f016cc16f8170717161825183516cc16f817071716182518351845";
hex"16ec170a17191728173817481757176717761786179617a517b517c417d417e417f4186518741883189318a318b318c318d218e118f11901191119211803181c";

/// @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"1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1c151cb11bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec1bec";
hex"1cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cc81cf11d8d";

/// @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.

Loading
Loading