Zilliqa / marketplace-contracts

GNU General Public License v3.0
2 stars 4 forks source link

Handling expired order #15

Closed bb111189 closed 2 years ago

bb111189 commented 2 years ago

If a buy/sell order is already listed and has expired, it is not possible to replace the buysell order at the same price.

  match is_sell_order with 
  | True => 
    (* Side: Sell *)
    RequireSenderToBeTokenOwner token_address token_id;

    has_sell_order <- exists sell_orders[token_address][token_id][payment_token_address][sale_price];
    match has_sell_order with
    | True =>
      (* It's already listed *)
      error = SellOrderFoundError;
      Throw error
    | False =>
      (* create new sell order *)
      new_order = Order _sender expiration_bnum;
      sell_orders[token_address][token_id][payment_token_address][sale_price] := new_order;

      e = {
        _eventname : "CreateOrder";
        maker: _sender;
        side: side;
        token_address: token_address;
        token_id: token_id;
        payment_token_address: payment_token_address;
        sale_price: sale_price;
        expiration_bnum: expiration_bnum
      };
      event e
    end

One possible way is to allow the user to update it by removing the True branch

    | True =>
      (* It's already listed *)
      error = SellOrderFoundError;
      Throw error

Also, do you want to consider an order that has no expiry? For example, if the user set it to 0, this order will never expire.

ghost commented 2 years ago

ok, I will change CreateOrder to SetOrder such that it can create/update orders.