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.
11 changes: 6 additions & 5 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_DEPOSIT_COLUMN,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_OWNER,
CONTEXT_CALLING_CONTEXT_ROW_ORDER_HASH,
CONTEXT_CALLING_CONTEXT_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_SIGNED_CONTEXT_START_COLUMN + 1] = contextWithdrawContextHandlers;

uint256[][] memory handlersUint256;
assembly ("memory-safe") {
Expand Down Expand Up @@ -275,14 +276,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 @@ -300,7 +301,7 @@ contract RaindexV6SubParser is BaseRainlangSubParser {
withdrawParsers[WITHDRAW_WORD_TARGET_AMOUNT] = LibRaindexSubParser.subParserWithdrawTargetAmount;
withdrawParsers[WITHDRAW_WORD_TOKEN_DECIMALS] = LibRaindexSubParser.subParserWithdrawTokenDecimals;

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

uint256[][] memory parsersUint256;
assembly ("memory-safe") {
Expand Down
7 changes: 5 additions & 2 deletions src/concrete/raindex/RaindexV6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {LibOrder} from "../../lib/LibOrder.sol";
import {
CALLING_CONTEXT_COLUMNS,
CONTEXT_CALLING_CONTEXT_COLUMN,
CONTEXT_DEPOSIT_COLUMN,
CONTEXT_CALCULATIONS_COLUMN,
CONTEXT_CALCULATIONS_ROWS,
CONTEXT_VAULT_IO_BALANCE_DIFF,
Expand Down Expand Up @@ -180,13 +181,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
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(0x1229c3e90ccea550ef1fb1a77f54ff7b8b3339800da312a645093454b964a007);

/// @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(0x7e92d4e954f131b7ce6471bc48157dc3125be0b90c8c9e26855b88218d95eb20);

/// @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"0101180010800082000100010480300038412a001810000010020004200004002038038ff54900cc66c61ff3dcab0616592209895f0b14fec9301b02e0920c5bfe561d21609201e959460b1974270f844db208bcd3bf1e989376171049db11b934301a0ae9a00af82a7805c138f40d28083f0742ef2104d561fd1215a13315716a6119d260cc107b9bfc0eec7ade13cba2891c6b14a518792bdb02e0f14716565589";

/// @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"170617231732174117501760176f177f178e179e17ae17bd17cd17dc17ec17fc180c1880188f189e18ae18be18ce181b1834170617321741175018de18ee18fe";

/// @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"1ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51ca51cce1d6a1ca51ca51ca51ca51ca51ca51ca5";

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

28 changes: 20 additions & 8 deletions src/lib/LibRaindex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import {LibContext} from "rainlang-interface-0.2.13/src/lib/caller/LibContext.so
/// as accounting limits such as current vault balances, etc.
/// The token address and decimals for vault inputs and outputs IS available to
/// the calculate order entrypoint, but not the final vault balances/diff.
uint256 constant CALLING_CONTEXT_COLUMNS = 4;
/// Each entrypoint fills only its own columns and leaves the rest empty, so a
/// word read outside the entrypoints that fill its cell reverts out of bounds
/// instead of reading another entrypoint's value.
uint256 constant CALLING_CONTEXT_COLUMNS = 5;

uint256 constant CONTEXT_COLUMNS = CALLING_CONTEXT_COLUMNS + 1;

/// @dev Total number of context columns including extensions: base columns
/// plus 2 for signers and signed context start, 1 for deposit, 1 for withdraw.
uint256 constant CONTEXT_COLUMNS_EXTENDED = CONTEXT_COLUMNS + 2 + 1 + 1;
/// @dev Number of sub parser word tables: one per context column up to and
/// including the first signed context column, plus the withdraw table.
uint256 constant CONTEXT_COLUMNS_EXTENDED = CONTEXT_SIGNED_CONTEXT_START_COLUMN + 2;

/// @dev Contextual data available to both calculate order and handle IO. The
/// order hash, order owner and order counterparty. IMPORTANT NOTE that the
Expand All @@ -38,13 +41,14 @@ 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;

/// @dev Context rows for the deposit calling context column. Available to the
/// deposit post-action entrypoint.
/// @dev Deposit column. Filled only for deposit tasks.
uint256 constant CONTEXT_DEPOSIT_COLUMN = 5;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN = 0;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_ID = 1;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_BEFORE = 2;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_AFTER = 3;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN_DECIMALS = 4;
uint256 constant CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_DEPOSITOR = 5;

/// @dev Context rows for the withdraw calling context column. Available to the
/// withdraw post-action entrypoint.
Expand Down Expand Up @@ -91,17 +95,25 @@ uint256 constant CONTEXT_VAULT_IO_ROWS = 5;

/// @dev Signed context signer addresses occupy their own column so that each
/// signer can be matched to its corresponding signed context column.
uint256 constant CONTEXT_SIGNED_CONTEXT_SIGNERS_COLUMN = 5;
uint256 constant CONTEXT_SIGNED_CONTEXT_SIGNERS_COLUMN = CONTEXT_COLUMNS;
uint256 constant CONTEXT_SIGNED_CONTEXT_SIGNERS_ROWS = 1;
uint256 constant CONTEXT_SIGNED_CONTEXT_SIGNERS_ROW = 0;

/// @dev Signed context data columns start after the signers column. Each
/// signer's data is a separate column at this offset + signer index.
uint256 constant CONTEXT_SIGNED_CONTEXT_START_COLUMN = 6;
uint256 constant CONTEXT_SIGNED_CONTEXT_START_COLUMN = CONTEXT_SIGNED_CONTEXT_SIGNERS_COLUMN + 1;
uint256 constant CONTEXT_SIGNED_CONTEXT_START_ROWS = 1;
uint256 constant CONTEXT_SIGNED_CONTEXT_START_ROW = 0;

library LibRaindex {
/// @dev Builds a calling context with `values` as context column `column`
/// and every other calling context column empty.
function callingContextColumn(uint256 column, bytes32[] memory values) internal pure returns (bytes32[][] memory) {
bytes32[][] memory callingContext = new bytes32[][](CALLING_CONTEXT_COLUMNS);
callingContext[column - 1] = values;
return callingContext;
}

/// @dev Evaluates each task in `post` against `context` padded with empty
/// columns to `CALLING_CONTEXT_COLUMNS`, so the signers and signed context
/// columns are at `CONTEXT_SIGNED_CONTEXT_SIGNERS_COLUMN` and
Expand Down
50 changes: 26 additions & 24 deletions src/lib/LibRaindexSubParser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
CONTEXT_BASE_ROWS
} from "rainlang-interface-0.2.13/src/lib/caller/LibContext.sol";
import {
CONTEXT_COLUMNS,
CONTEXT_COLUMNS_EXTENDED,
CONTEXT_VAULT_OUTPUTS_COLUMN,
CONTEXT_VAULT_INPUTS_COLUMN,
Expand All @@ -37,6 +36,8 @@ 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_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_ID,
CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_BEFORE,
Expand Down Expand Up @@ -115,6 +116,16 @@ library LibRaindexSubParser {
return LibSubParse.subParserContext(CONTEXT_BASE_COLUMN, CONTEXT_BASE_ROW_SENDER);
}

/// @dev Maps the "depositor" word to the deposit column.
function subParserDepositor(uint256, uint256, OperandV2)
internal
pure
returns (bool, bytes memory, bytes32[] memory)
{
//slither-disable-next-line unused-return
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_DEPOSITOR);
}

/// @dev Maps the "calling-contract" word to the base context column.
function subParserCallingContract(uint256, uint256, OperandV2)
internal
Expand Down Expand Up @@ -287,63 +298,54 @@ library LibRaindexSubParser {
return LibSubParse.subParserContext(CONTEXT_SIGNED_CONTEXT_SIGNERS_COLUMN, uint256(OperandV2.unwrap(operand)));
}

/// @dev Maps the "deposit-token" word to the calling context column.
/// @dev Maps the "deposit-token" word to the deposit column.
function subParserDepositToken(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_DEPOSIT_TOKEN);
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN);
}

/// @dev Maps the "deposit-vault-id" word to the calling context column.
/// @dev Maps the "deposit-vault-id" word to the deposit column.
function subParserDepositVaultId(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_DEPOSIT_VAULT_ID);
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_ID);
}

/// @dev Maps the "deposit-vault-balance-before" word to the calling context column.
/// @dev Maps the "deposit-vault-balance-before" word to the deposit column.
function subParserDepositVaultBalanceBefore(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_DEPOSIT_VAULT_BEFORE
);
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_BEFORE);
}

/// @dev Maps the "deposit-vault-balance-after" word to the calling context column.
/// @dev Maps the "deposit-vault-balance-after" word to the deposit column.
function subParserDepositVaultBalanceAfter(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_DEPOSIT_VAULT_AFTER
);
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_VAULT_AFTER);
}

/// @dev Maps the "deposit-token-decimals" word to the calling context column.
/// @dev Maps the "deposit-token-decimals" word to the deposit column.
function subParserDepositTokenDecimals(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_DEPOSIT_TOKEN_DECIMALS
);
return LibSubParse.subParserContext(CONTEXT_DEPOSIT_COLUMN, CONTEXT_CALLING_CONTEXT_ROW_DEPOSIT_TOKEN_DECIMALS);
}

/// @dev Maps the "withdraw-token" word to the calling context column.
Expand Down Expand Up @@ -432,8 +434,8 @@ 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, signers, signed context,
/// deposit, withdraw). The inner arrays are flattened before encoding.
/// column (base, calling, calculations, vault IO, deposit, signers, signed
/// context, withdraw). 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);
Expand Down Expand Up @@ -615,7 +617,7 @@ library LibRaindexSubParser {
// forge-lint: disable-next-line(unsafe-typecast)
AuthoringMetaV2(bytes32(WORD_DEPOSIT_TOKEN_DECIMALS), "The decimals of the token that is being deposited.");

meta[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 1] = depositMeta;
meta[CONTEXT_DEPOSIT_COLUMN] = depositMeta;

AuthoringMetaV2[] memory withdrawMeta = new AuthoringMetaV2[](WITHDRAW_WORDS_LENGTH);
withdrawMeta[WITHDRAW_WORD_WITHDRAWER] =
Expand Down Expand Up @@ -658,7 +660,7 @@ library LibRaindexSubParser {
// forge-lint: disable-next-line(unsafe-typecast)
AuthoringMetaV2(bytes32(WORD_WITHDRAW_TOKEN_DECIMALS), "The decimals of the token that is being withdrawn.");

meta[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 2] = withdrawMeta;
meta[CONTEXT_SIGNED_CONTEXT_START_COLUMN + 1] = withdrawMeta;

uint256[][] memory metaUint256;
assembly {
Expand Down
Loading
Loading