Skip to content

Commit

Permalink
[review] Damir: 1/N (#30)
Browse files Browse the repository at this point in the history
* adds licenses

* better apis for Coin / Option

- balance.into_coin
- option.fill / option.swap
- minor formatting
- unnecessary return's

* naming convention around getters

* nits + important todo

* [review] Damir: 2/N (#31)

* adds burning

* more coin methods (#32)

- withdraw(num) -> withdraw_base, withdraw_quote etc
- Pool no longer has "store"
  • Loading branch information
damirka authored Apr 18, 2024
1 parent edaea06 commit c7afbcb
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 172 deletions.
25 changes: 18 additions & 7 deletions deepbook/sources/deepbook.move
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module deepbook::deepbook {
use sui::{
balance::Balance,
coin::Coin,
sui::SUI
};

use deepbook::{
state::State,
pool::{Pool, DEEP},
Expand All @@ -22,7 +25,9 @@ module deepbook::deepbook {
creation_fee: Balance<SUI>,
ctx: &mut TxContext
) {
state.create_pool<BaseAsset, QuoteAsset>(tick_size, lot_size, min_size, creation_fee, ctx);
state.create_pool<BaseAsset, QuoteAsset>(
tick_size, lot_size, min_size, creation_fee, ctx
);
}

/// Public facing function to set a pool as stable.
Expand All @@ -42,7 +47,9 @@ module deepbook::deepbook {
pool: &mut Pool<BaseAsset, QuoteAsset>,
ctx: &TxContext,
) {
state.add_deep_price_point<BaseAsset, QuoteAsset>(reference_pool, pool, ctx);
state.add_deep_price_point<BaseAsset, QuoteAsset>(
reference_pool, pool, ctx
);
}

/// Public facing function to remove a deep price point from a specific pool.
Expand Down Expand Up @@ -91,7 +98,9 @@ module deepbook::deepbook {
stake_required: u64,
ctx: &mut TxContext,
) {
state.submit_proposal<BaseAsset, QuoteAsset>(pool, maker_fee, taker_fee, stake_required, ctx);
state.submit_proposal<BaseAsset, QuoteAsset>(
pool, maker_fee, taker_fee, stake_required, ctx
);
}

/// Public facing function to vote on a proposal.
Expand All @@ -115,8 +124,10 @@ module deepbook::deepbook {
quantity: u64,
is_bid: bool,
ctx: &mut TxContext,
): u64 {
pool.place_limit_order(account, client_order_id, price, quantity, is_bid, ctx)
) {
pool.place_limit_order(
account, client_order_id, price, quantity, is_bid, ctx
);
}

// public fun place_market_order()
Expand All @@ -125,4 +136,4 @@ module deepbook::deepbook {
// public fun get_open_orders()
// public fun get_amount_out()
// public fun get_order_book()
}
}
5 changes: 4 additions & 1 deletion deepbook/sources/helper/big_vector.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// BigVector is an arbitrary sized vector-like data structure,
/// implemented using an on-chain B+ Tree to support almost constant
/// time (log base max_fan_out) random access, insertion and removal.
Expand Down Expand Up @@ -1268,4 +1271,4 @@ module deepbook::big_vector {
assert!(slice.bisect_right(10) == 5, 0);
assert!(slice.bisect_right(11) == 5, 0);
}
}
}
5 changes: 4 additions & 1 deletion deepbook/sources/helper/math.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module deepbook::math {
/// scaling setting for float
const FLOAT_SCALING_U128: u128 = 1_000_000_000;
Expand All @@ -23,4 +26,4 @@ module deepbook::math {
assert!(result > 0, EUnderflow);
result
}
}
}
7 changes: 5 additions & 2 deletions deepbook/sources/helper/utils.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/// Deepbook utility functions.
module deepbook::utils {
use std::ascii::{Self, String};
Expand Down Expand Up @@ -29,7 +32,7 @@ module deepbook::utils {
res.reverse();
res
}

/// Compare two ASCII strings, return True if first string is less than or equal to the second string in lexicographic order
public fun compare(str1: &String, str2: &String): bool {
let len1 = str1.length();
Expand Down Expand Up @@ -80,4 +83,4 @@ module deepbook::utils {

ascii::string(result_bytes)
}
}
}
15 changes: 9 additions & 6 deletions deepbook/sources/pool/account.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module deepbook::account {
use sui::{
coin::{Self, Coin},
Expand All @@ -16,7 +19,7 @@ module deepbook::account {
owner: address,
// coin_balances will be represented in dynamic fields
}

/// Identifier for balance
public struct BalanceKey<phantom T> has store, copy, drop {
coin_type: TypeName,
Expand All @@ -33,7 +36,7 @@ module deepbook::account {

/// Deposit funds to an account
public fun deposit<T>(
account: &mut Account,
account: &mut Account,
coin: Coin<T>,
) {
let balance_key = BalanceKey<T> { coin_type: type_name::get<T>() };
Expand All @@ -52,7 +55,7 @@ module deepbook::account {

/// Withdraw funds from an account
public fun withdraw<T>(
account: &mut Account,
account: &mut Account,
amount: u64,
ctx: &mut TxContext,
): Coin<T> {
Expand All @@ -69,7 +72,7 @@ module deepbook::account {
}

/// Returns the owner of the account
public fun get_owner(account: &Account): address {
account.owner
public fun owner(account: &Account): address {
account.owner
}
}
}
7 changes: 5 additions & 2 deletions deepbook/sources/pool/deep_price.move
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module deepbook::deep_price {
// DEEP price points used for trading fee calculations
public struct DeepPrice has store, drop {
Expand All @@ -8,7 +11,7 @@ module deepbook::deep_price {
deep_per_quote: u64,
}

public(package) fun initialize(): DeepPrice {
public(package) fun empty(): DeepPrice {
// Initialize the DEEP price points
DeepPrice {
last_insert_timestamp: 0,
Expand Down Expand Up @@ -37,4 +40,4 @@ module deepbook::deep_price {
public(package) fun deep_per_quote(deep_price: &DeepPrice): u64 {
deep_price.deep_per_quote
}
}
}
Loading

0 comments on commit c7afbcb

Please sign in to comment.