// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

/// @title MarsBase Common
/// @author dOTC Marsbase
/// @notice This library contains struct and enum definitions for the MarsBase Exchange and MarsBase Contracts.
library MarsBaseCommon {

  enum OfferType {
    FullPurchase,
    LimitedTime,
    ChunkedPurchase,
    LimitedTimeChunkedPurchase,
    MinimumChunkedPurchase,
    LimitedTimeMinimumPurchase,
    LimitedTimeMinimumChunkedPurchase,
    LimitedTimeMinimumChunkedDeadlinePurchase
  }

  enum OfferCloseReason {
    Success,
    CancelledBySeller,
    DeadlinePassed
  }

  /// @dev Offers is a simple offer type, that does the exchange immediately in all cases.
  /// @dev Minimum Offers can hold tokens until certain criteria are met.
  enum ContractType {
    Offers,
    MinimumOffers
  }

  struct OfferParams {
    bool cancelEnabled;
    bool modifyEnabled;
    bool holdTokens;
    uint256 feeAlice;
    uint256 feeBob;
    uint256 smallestChunkSize;
    uint256 deadline;
    uint256 minimumSize;
  }

/// @notice Primary Offer Data Structure
/// @notice Primary Offer Data Structure
/// @notice smallestChunkSize - Smallest amount that may be purchased in one transaction
  struct MBOffer {
    bool active;
    bool minimumMet;
    OfferType offerType;
    uint256 offerId;
    uint256 amountAlice;
    uint256 feeAlice;
    uint256 feeBob;
    uint256 smallestChunkSize;
    uint256 minimumSize;
    uint256 deadline;
    uint256 amountRemaining;
    address offerer;
    address payoutAddress;
    address tokenAlice;
	
	// capabilities[0] = Modifiable
	// capabilities[1] = Cancel Enabled
	// capabilities[2] = Should not distribute tokens until deadline (for minimum Offers)
    bool[3] capabilities;
    uint256[] amountBob;
    uint256[] minimumOrderAmountsAlice;
    uint256[] minimumOrderAmountsBob;
    address[] minimumOrderAddresses;
    address[] minimumOrderTokens;
    address[] tokenBob;
  }
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"}],"name":"BidCancelled","type":"event"},{"anonymous":false,"inputs":[],"name":"ContractMigrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"log","type":"uint256"}],"name":"Log","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountAliceReceived","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountBobReceived","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenAddressAlice","type":"address"},{"indexed":false,"internalType":"address","name":"tokenAddressBob","type":"address"},{"indexed":false,"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"feeAlice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeBob","type":"uint256"}],"name":"OfferAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"}],"name":"OfferCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"enum MarsBaseCommon.OfferCloseReason","name":"reason","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"}],"name":"OfferClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"},{"components":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"bool[3]","name":"capabilities","type":"bool[3]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsAlice","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsBob","type":"uint256[]"},{"internalType":"address[]","name":"minimumOrderAddresses","type":"address[]"},{"internalType":"address[]","name":"minimumOrderTokens","type":"address[]"},{"internalType":"address[]","name":"tokenBob","type":"address[]"}],"indexed":false,"internalType":"struct MarsBaseCommon.MBOffer","name":"offer","type":"tuple"}],"name":"OfferCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"offerId","type":"uint256"},{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockTimestamp","type":"uint256"},{"components":[{"internalType":"bool","name":"cancelEnabled","type":"bool"},{"internalType":"bool","name":"modifyEnabled","type":"bool"},{"internalType":"bool","name":"holdTokens","type":"bool"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"}],"indexed":false,"internalType":"struct MarsBaseCommon.OfferParams","name":"offerParameters","type":"tuple"}],"name":"OfferModified","type":"event"},{"inputs":[{"internalType":"uint256","name":"amountBeforeFee","type":"uint256"},{"internalType":"uint256","name":"feePercent","type":"uint256"},{"internalType":"uint256","name":"scale","type":"uint256"},{"internalType":"uint256","name":"safeAmount","type":"uint256"}],"name":"_afterFee","outputs":[{"internalType":"uint256","name":"amountAfterFee","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"address","name":"tokenBob","type":"address"},{"internalType":"uint256","name":"amountBob","type":"uint256"}],"name":"acceptOffer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountBeforeFee","type":"uint256"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"afterFee","outputs":[{"internalType":"uint256","name":"amountAfterFee","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"cancelBid","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cancelExpiredOffers","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"cancelOffer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"from","type":"uint256"},{"internalType":"uint256","name":"to","type":"uint256"}],"name":"cancelOffers","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"address[]","name":"tokenBob","type":"address[]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"components":[{"internalType":"bool","name":"cancelEnabled","type":"bool"},{"internalType":"bool","name":"modifyEnabled","type":"bool"},{"internalType":"bool","name":"holdTokens","type":"bool"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"}],"internalType":"struct MarsBaseCommon.OfferParams","name":"offerParameters","type":"tuple"}],"name":"changeOfferParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"changeOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"closeExpiredOffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"address[]","name":"tokenBob","type":"address[]"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"components":[{"internalType":"bool","name":"cancelEnabled","type":"bool"},{"internalType":"bool","name":"modifyEnabled","type":"bool"},{"internalType":"bool","name":"holdTokens","type":"bool"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"}],"internalType":"struct MarsBaseCommon.OfferParams","name":"offerParameters","type":"tuple"}],"name":"createOffer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getAllOffers","outputs":[{"components":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"bool[3]","name":"capabilities","type":"bool[3]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsAlice","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsBob","type":"uint256[]"},{"internalType":"address[]","name":"minimumOrderAddresses","type":"address[]"},{"internalType":"address[]","name":"minimumOrderTokens","type":"address[]"},{"internalType":"address[]","name":"tokenBob","type":"address[]"}],"internalType":"struct MarsBaseCommon.MBOffer[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCommissionAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExchangerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinimumFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNextOfferId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"offerId","type":"uint256"}],"name":"getOffer","outputs":[{"components":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"bool[3]","name":"capabilities","type":"bool[3]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsAlice","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsBob","type":"uint256[]"},{"internalType":"address[]","name":"minimumOrderAddresses","type":"address[]"},{"internalType":"address[]","name":"minimumOrderTokens","type":"address[]"},{"internalType":"address[]","name":"tokenBob","type":"address[]"}],"internalType":"struct MarsBaseCommon.MBOffer","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"bool[3]","name":"capabilities","type":"bool[3]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsAlice","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsBob","type":"uint256[]"},{"internalType":"address[]","name":"minimumOrderAddresses","type":"address[]"},{"internalType":"address[]","name":"minimumOrderTokens","type":"address[]"},{"internalType":"address[]","name":"tokenBob","type":"address[]"}],"internalType":"struct MarsBaseCommon.MBOffer","name":"offer","type":"tuple"}],"name":"isEligibleToPayout","outputs":[{"internalType":"bool","name":"eligible","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"}],"name":"limitMinimumSize9999","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"lockContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"log2","outputs":[{"internalType":"uint8","name":"n","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"max","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"migrateContract","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"a","type":"uint256"},{"internalType":"uint256","name":"b","type":"uint256"}],"name":"min","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"},{"internalType":"bool[3]","name":"capabilities","type":"bool[3]"},{"internalType":"uint256[]","name":"amountBob","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsAlice","type":"uint256[]"},{"internalType":"uint256[]","name":"minimumOrderAmountsBob","type":"uint256[]"},{"internalType":"address[]","name":"minimumOrderAddresses","type":"address[]"},{"internalType":"address[]","name":"minimumOrderTokens","type":"address[]"},{"internalType":"address[]","name":"tokenBob","type":"address[]"}],"internalType":"struct MarsBaseCommon.MBOffer","name":"offer","type":"tuple"}],"name":"minimumCovered","outputs":[{"internalType":"bool","name":"result","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"offers","outputs":[{"internalType":"bool","name":"active","type":"bool"},{"internalType":"bool","name":"minimumMet","type":"bool"},{"internalType":"enum MarsBaseCommon.OfferType","name":"offerType","type":"uint8"},{"internalType":"uint256","name":"offerId","type":"uint256"},{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"feeAlice","type":"uint256"},{"internalType":"uint256","name":"feeBob","type":"uint256"},{"internalType":"uint256","name":"smallestChunkSize","type":"uint256"},{"internalType":"uint256","name":"minimumSize","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"amountRemaining","type":"uint256"},{"internalType":"address","name":"offerer","type":"address"},{"internalType":"address","name":"payoutAddress","type":"address"},{"internalType":"address","name":"tokenAlice","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountAlice","type":"uint256"},{"internalType":"uint256","name":"offerAmountAlice","type":"uint256"},{"internalType":"uint256","name":"offerAmountBob","type":"uint256"}],"name":"price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"}],"name":"setCommissionAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"exchangeContract","type":"address"}],"name":"setExchangerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minimumFee","type":"uint256"}],"name":"setMinimumFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nextOfferId","type":"uint256"}],"name":"setNextOfferId","outputs":[],"stateMutability":"nonpayable","type":"function"}]