Skip to content
Draft
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
23 changes: 23 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ move-prover-test-utils = { path = "third_party/move/move-prover/test-utils" }
move-prover-lab = { path = "third_party/move/move-prover/lab" }
aptos-move-stdlib = { path = "aptos-move/framework/move-stdlib" }
aptos-table-natives = { path = "aptos-move/framework/table-natives" }
aptos-trading-natives = { path = "aptos-move/framework/trading-natives" }
move-resource-viewer = { path = "third_party/move/tools/move-resource-viewer" }
move-stackless-bytecode = { path = "third_party/move/move-model/bytecode" }
move-stackless-bytecode-test-utils = { path = "third_party/move/move-model/bytecode-test-utils" }
Expand Down
23 changes: 23 additions & 0 deletions aptos-move/aptos-native-interface/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ macro_rules! safely_get_struct_field_as {
}};
}

/// Returns a field value of the specified type from a struct at a given index.
/// If the field access is out of bounds, or type is incorrect, a
/// `SafeNativeError::InvariantViolation` is returned.
#[macro_export]
macro_rules! safely_get_struct_variant_field_as {
($value:expr, $allowed:expr, $idx:expr, $variant_name:expr, $t:ty) => {{
// Note: we remap errors to safe errors in order to avoid implicit
// conversions via `Into`.
$value
.borrow_variant_field(
$allowed,
$idx,
&|_v| ($variant_name).to_string())
.map_err($crate::SafeNativeError::InvariantViolation)?
.value_as::<Reference>()
.map_err($crate::SafeNativeError::InvariantViolation)?
.read_ref()
.map_err($crate::SafeNativeError::InvariantViolation)?
.value_as::<$t>()
.map_err($crate::SafeNativeError::InvariantViolation)?
}};
}

/// Like `assert_eq!` but for safe natives that return `SafeNativeResult<T>`. Instead of panicking,
/// will return a `SafeNativeError::InvariantViolation(UNKNOWN_INVARIANT_VIOLATION_ERROR)`.
#[macro_export]
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm-environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aptos-gas-schedule = { workspace = true }
aptos-move-stdlib = { workspace = true }
aptos-native-interface = { workspace = true }
aptos-table-natives = { workspace = true }
aptos-trading-natives = { workspace = true }
aptos-types = { workspace = true }
aptos-vm-types = { workspace = true }
ark-bn254 = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions aptos-move/aptos-vm-environment/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed pursuant to the Innovation-Enabling Source Code License, available at https://github.com/aptos-labs/aptos-core/blob/main/LICENSE

use aptos_native_interface::SafeNativeBuilder;
use aptos_types::account_config::EXPERIMENTAL_CODE_ADDRESS;
use move_core_types::language_storage::CORE_CODE_ADDRESS;
use move_vm_runtime::native_functions::NativeFunctionTable;
use std::collections::HashSet;
Expand Down Expand Up @@ -42,5 +43,9 @@ pub fn aptos_natives_with_builder(
CORE_CODE_ADDRESS,
builder,
))
.chain(aptos_trading_natives::all_natives(
EXPERIMENTAL_CODE_ADDRESS,
builder,
))
.collect()
}
1 change: 1 addition & 0 deletions aptos-move/aptos-vm-profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ aptos-gas-schedule = { workspace = true }
aptos-move-stdlib = { workspace = true }
aptos-native-interface = { workspace = true }
aptos-table-natives = { workspace = true }
aptos-trading-natives = { workspace = true }
aptos-transaction-simulation = { workspace = true }
aptos-types = { workspace = true }
aptos-vm = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions aptos-move/aptos-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ aptos-metrics-core = { workspace = true }
aptos-mvhashmap = { workspace = true }
aptos-native-interface = { workspace = true }
aptos-table-natives = { workspace = true }
aptos-trading-natives = { workspace = true }
aptos-types = { workspace = true }
aptos-vm-environment = { workspace = true }
aptos-vm-logging = { workspace = true }
Expand Down
265 changes: 265 additions & 0 deletions aptos-move/framework/aptos-experimental/doc/orders_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@

<a id="0x7_orders_index"></a>

# Module `0x7::orders_index`



- [Enum `IndexedOrder`](#0x7_orders_index_IndexedOrder)
- [Enum `OrdersIndex`](#0x7_orders_index_OrdersIndex)
- [Function `new_orders_index`](#0x7_orders_index_new_orders_index)
- [Function `place_maker_order`](#0x7_orders_index_place_maker_order)
- [Function `is_taker_order`](#0x7_orders_index_is_taker_order)
- [Function `get_single_match_for_taker`](#0x7_orders_index_get_single_match_for_taker)


<pre><code><b>use</b> <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option">0x1::option</a>;
<b>use</b> <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table">0x1::table</a>;
<b>use</b> <a href="../../aptos-framework/doc/transaction_context.md#0x1_transaction_context">0x1::transaction_context</a>;
<b>use</b> <a href="bulk_order_book_types.md#0x7_bulk_order_book_types">0x7::bulk_order_book_types</a>;
<b>use</b> <a href="order_book_types.md#0x7_order_book_types">0x7::order_book_types</a>;
<b>use</b> <a href="single_order_book.md#0x7_single_order_book">0x7::single_order_book</a>;
<b>use</b> <a href="single_order_types.md#0x7_single_order_types">0x7::single_order_types</a>;
</code></pre>



<a id="0x7_orders_index_IndexedOrder"></a>

## Enum `IndexedOrder`



<pre><code>enum <a href="orders_index.md#0x7_orders_index_IndexedOrder">IndexedOrder</a>&lt;M: <b>copy</b>, drop, store&gt;
</code></pre>



<details>
<summary>Variants</summary>


<details>
<summary>SingleOrder</summary>


<details>
<summary>Fields</summary>


<dl>
<dt>
<code>unique_priority_idx: <a href="order_book_types.md#0x7_order_book_types_UniqueIdxType">order_book_types::UniqueIdxType</a></code>
</dt>
<dd>

</dd>
<dt>
<code>order_request: <a href="single_order_book.md#0x7_single_order_book_SingleOrderRequest">single_order_book::SingleOrderRequest</a>&lt;M&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

</details>

<details>
<summary>BulkOrder</summary>


<details>
<summary>Fields</summary>


<dl>
<dt>
<code>order_id: <a href="order_book_types.md#0x7_order_book_types_OrderIdType">order_book_types::OrderIdType</a></code>
</dt>
<dd>

</dd>
<dt>
<code>unique_priority_idx: <a href="order_book_types.md#0x7_order_book_types_UniqueIdxType">order_book_types::UniqueIdxType</a></code>
</dt>
<dd>

</dd>
<dt>
<code>order_request: <a href="bulk_order_book_types.md#0x7_bulk_order_book_types_BulkOrderRequest">bulk_order_book_types::BulkOrderRequest</a>&lt;M&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

</details>

</details>

<a id="0x7_orders_index_OrdersIndex"></a>

## Enum `OrdersIndex`



<pre><code>enum <a href="orders_index.md#0x7_orders_index_OrdersIndex">OrdersIndex</a>&lt;M: <b>copy</b>, drop, store&gt; <b>has</b> store
</code></pre>



<details>
<summary>Variants</summary>


<details>
<summary>V1</summary>


<details>
<summary>Fields</summary>


<dl>
<dt>
<code>id: u128</code>
</dt>
<dd>

</dd>
<dt>
<code><a href="../../aptos-framework/doc/version.md#0x1_version">version</a>: u64</code>
</dt>
<dd>

</dd>
<dt>
<code>data: <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_Table">table::Table</a>&lt;<a href="order_book_types.md#0x7_order_book_types_OrderIdType">order_book_types::OrderIdType</a>, <a href="single_order_types.md#0x7_single_order_types_SingleOrder">single_order_types::SingleOrder</a>&lt;M&gt;&gt;</code>
</dt>
<dd>

</dd>
</dl>


</details>

</details>

</details>

<a id="0x7_orders_index_new_orders_index"></a>

## Function `new_orders_index`



<pre><code><b>public</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_new_orders_index">new_orders_index</a>&lt;M: <b>copy</b>, drop, store&gt;(): <a href="orders_index.md#0x7_orders_index_OrdersIndex">orders_index::OrdersIndex</a>&lt;M&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_new_orders_index">new_orders_index</a>&lt;M: store + <b>copy</b> + drop&gt;(): <a href="orders_index.md#0x7_orders_index_OrdersIndex">OrdersIndex</a>&lt;M&gt; {
OrdersIndex::V1 {
id: <a href="../../aptos-framework/doc/transaction_context.md#0x1_transaction_context_monotonically_increasing_counter">transaction_context::monotonically_increasing_counter</a>(),
<a href="../../aptos-framework/doc/version.md#0x1_version">version</a>: 0,
data: <a href="../../aptos-framework/../aptos-stdlib/doc/table.md#0x1_table_new">table::new</a>(),
}
}
</code></pre>



</details>

<a id="0x7_orders_index_place_maker_order"></a>

## Function `place_maker_order`



<pre><code><b>public</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_place_maker_order">place_maker_order</a>&lt;M: <b>copy</b>, drop, store&gt;(self: &<b>mut</b> <a href="orders_index.md#0x7_orders_index_OrdersIndex">orders_index::OrdersIndex</a>&lt;M&gt;, order_req: <a href="single_order_book.md#0x7_single_order_book_SingleOrderRequest">single_order_book::SingleOrderRequest</a>&lt;M&gt;)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_place_maker_order">place_maker_order</a>&lt;M: store + <b>copy</b> + drop&gt;(
self: &<b>mut</b> <a href="orders_index.md#0x7_orders_index_OrdersIndex">OrdersIndex</a>&lt;M&gt;, order_req: SingleOrderRequest&lt;M&gt;
);
</code></pre>



</details>

<a id="0x7_orders_index_is_taker_order"></a>

## Function `is_taker_order`

Checks if the order is a taker order i.e., matched immediately with the active order book.


<pre><code><b>public</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_is_taker_order">is_taker_order</a>&lt;M: <b>copy</b>, drop, store&gt;(self: &<a href="orders_index.md#0x7_orders_index_OrdersIndex">orders_index::OrdersIndex</a>&lt;M&gt;, price: u64, is_bid: bool, trigger_condition: <a href="../../aptos-framework/../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_Option">option::Option</a>&lt;<a href="order_book_types.md#0x7_order_book_types_TriggerCondition">order_book_types::TriggerCondition</a>&gt;): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_is_taker_order">is_taker_order</a>&lt;M: store + <b>copy</b> + drop&gt;(
self: &<a href="orders_index.md#0x7_orders_index_OrdersIndex">OrdersIndex</a>&lt;M&gt;,
price: u64,
is_bid: bool,
trigger_condition: Option&lt;TriggerCondition&gt;
): bool;
</code></pre>



</details>

<a id="0x7_orders_index_get_single_match_for_taker"></a>

## Function `get_single_match_for_taker`



<pre><code><b>public</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_get_single_match_for_taker">get_single_match_for_taker</a>&lt;M: <b>copy</b>, drop, store&gt;(self: &<b>mut</b> <a href="orders_index.md#0x7_orders_index_OrdersIndex">orders_index::OrdersIndex</a>&lt;M&gt;, price: u64, size: u64, is_bid: bool): <a href="order_book_types.md#0x7_order_book_types_OrderMatch">order_book_types::OrderMatch</a>&lt;M&gt;
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>native</b> <b>fun</b> <a href="orders_index.md#0x7_orders_index_get_single_match_for_taker">get_single_match_for_taker</a>&lt;M: store + <b>copy</b> + drop&gt;(
self: &<b>mut</b> <a href="orders_index.md#0x7_orders_index_OrdersIndex">OrdersIndex</a>&lt;M&gt;,
price: u64,
size: u64,
is_bid: bool
): OrderMatch&lt;M&gt;;
</code></pre>



</details>


[move-book]: https://aptos.dev/move/book/SUMMARY
Loading
Loading