pragma solidity >=0.8.0 <0.9.0;

import "./MarsBaseCommon.sol";

interface IMarsbaseExchange {
	/// Emitted when an offer is created
    event OfferCreated(
        uint256 offerId,
        address sender,
        uint256 blockTimestamp,
        MarsBaseCommon.MBOffer offer
    );
	
	/// Emitted when an offer has it's parameters or capabilities modified
    event OfferModified(
        uint256 offerId,
        address sender,
        uint256 blockTimestamp,
        MarsBaseCommon.OfferParams offerParameters
    );

    /// Emitted when an offer is accepted.
    /// This includes partial transactions, where the whole offer is not bought out and those where the exchange is not finallized immediatley.
    event OfferAccepted(
        uint256 offerId,
        address sender,
        uint256 blockTimestamp,
        uint256 amountAliceReceived,
        uint256 amountBobReceived,
        address tokenAddressAlice,
        address tokenAddressBob,
        MarsBaseCommon.OfferType offerType,
        uint256 feeAlice,
        uint256 feeBob
    );

    /// Emitted when the offer is cancelled either by the creator or because of an unsuccessful auction
    event OfferCancelled(
        uint256 offerId,
        address sender,
        uint256 blockTimestamp
    );

    event OfferClosed(
        uint256 offerId,
        MarsBaseCommon.OfferCloseReason reason,
        uint256 blockTimestamp
    );

    event ContractMigrated();

    /// Emitted when a buyer cancels their bid for a offer were tokens have not been exchanged yet and are still held by the contract.
    event BidCancelled(uint256 offerId, address sender, uint256 blockTimestamp);

    /// Emitted only for testing usage
    event Log(uint256 log);
	
    struct MBAddresses {
        address offersContract;
        address minimumOffersContract;
    }

	function setCommissionAddress(address wallet) external;
	function setExchangerAddress(address exchangeContract) external;
	function setMinimumFee(uint256 _minimumFee) external;
	function getMinimumFee() external view returns (uint256);
	function setNextOfferId(uint256 _nextOfferId) external;
	function getOffer(uint256 offerId) external view returns (MarsBaseCommon.MBOffer memory);
	function getNextOfferId() external view returns (uint256);
	function getOwner() external view returns (address);
	function changeOwner(address newOwner) external;
	function getAllOffers() external view returns (MarsBaseCommon.MBOffer[] memory);
	function createOffer(
        address tokenAlice,
        address[] calldata tokenBob,
        uint256 amountAlice,
        uint256[] calldata amountBob,
        MarsBaseCommon.OfferParams calldata offerParameters
    ) external payable;
	function cancelOffer(uint256 offerId) external payable;
	function price(
        uint256 amountAlice,
        uint256 offerAmountAlice,
        uint256 offerAmountBob
    ) external pure returns (uint256);
	function acceptOffer(
        uint256 offerId,
        address tokenBob,
        uint256 amountBob
    ) external payable;
	function changeOfferParams(
        uint256 offerId,
        address[] calldata tokenBob,
        uint256[] calldata amountBob,
        MarsBaseCommon.OfferParams calldata offerParameters
    ) external;
	function cancelBid(uint256 offerId) external;
	function cancelExpiredOffers() external payable;
	function migrateContract() external payable;
	function lockContract() external;
	function cancelOffers(uint256 from, uint256 to) external payable;
}
[{"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"}]