Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop #263

Merged
merged 16 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding endpoint to edit an ask (#265)
Co-authored-by: porkbrain <[email protected]>
  • Loading branch information
Suficio and porkbrain authored Feb 16, 2023
commit 95ff413d9b6edfc17518f357a2b77408a306b433
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
- `create_safe_and_buy_nft`
- `create_safe_and_buy_generic_nft`
- `cancel_ask_and_discard_transfer_cap`
- `edit_ask`
- Added static `name` and `url` fields to `Nft` for better integration with explorer.
- Added `LimitedFixedPriceMarket`
- `orderbook::list_nft` and `orderbook::list_nft_with_commission` endpoints.
Expand Down
43 changes: 30 additions & 13 deletions sources/trading/orderbook.move
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,8 @@ module nft_protocol::orderbook {
ctx: &mut TxContext,
) {
assert!(!book.protected_actions.cancel_ask, err::action_not_public());
transfer(
cancel_ask_(book, nft_price_level, nft_id, ctx),
tx_context::sender(ctx),
);
let (cap, _) = cancel_ask_(book, nft_price_level, nft_id, ctx);
transfer(cap, tx_context::sender(ctx));
}

/// Same as [`cancel_ask`] but protected by
Expand All @@ -599,11 +597,8 @@ module nft_protocol::orderbook {
ctx: &mut TxContext,
) {
utils::assert_same_module_as_witness<C, W>();

transfer(
cancel_ask_(book, nft_price_level, nft_id, ctx),
tx_context::sender(ctx),
);
let (cap, _) = cancel_ask_(book, nft_price_level, nft_id, ctx);
transfer(cap, tx_context::sender(ctx));
}

/// Same as [`cancel_ask`] but the [`TransferCap`] is burned instead of
Expand All @@ -616,10 +611,32 @@ module nft_protocol::orderbook {
ctx: &mut TxContext,
) {
assert!(!book.protected_actions.cancel_ask, err::action_not_public());
let cap = cancel_ask_(book, nft_price_level, nft_id, ctx);
let (cap, _) = cancel_ask_(book, nft_price_level, nft_id, ctx);
safe::burn_transfer_cap(cap, seller_safe);
}

// === Edit listing ===

/// Removes the old ask and creates a new one with the same NFT.
/// Two events are emitted at least:
/// Firstly, we always emit `AskRemovedEvent` for the old ask.
/// Then either `AskCreatedEvent` or `TradeFilledEvent`.
/// Depends on whether the ask is filled immediately or not.
public entry fun edit_ask<C, FT>(
book: &mut Orderbook<C, FT>,
old_price: u64,
nft_id: ID,
new_price: u64,
seller_safe: &mut Safe,
ctx: &mut TxContext,
) {
assert!(!book.protected_actions.cancel_ask, err::action_not_public());
assert!(!book.protected_actions.create_ask, err::action_not_public());

let (cap, commission) = cancel_ask_(book, old_price, nft_id, ctx);
create_ask_(book, new_price, commission, cap, seller_safe, ctx);
}

// === Buy NFT ===

/// To buy a specific NFT listed in the orderbook, the client provides the
Expand Down Expand Up @@ -1277,14 +1294,14 @@ module nft_protocol::orderbook {
nft_price_level: u64,
nft_id: ID,
ctx: &mut TxContext,
): TransferCap {
): (TransferCap, Option<AskCommission>) {
let sender = tx_context::sender(ctx);

let Ask {
owner,
price: _,
transfer_cap,
commission: _,
commission,
} = remove_ask(
&mut book.asks,
nft_price_level,
Expand All @@ -1300,7 +1317,7 @@ module nft_protocol::orderbook {

assert!(owner == sender, err::order_owner_must_be_sender());

transfer_cap
(transfer_cap, commission)
}

fun buy_nft_<C, FT>(
Expand Down