Skip to content

Solidity API

SalesOrder

The Sales Order is a trade contract enables tokenized asset sales, supporting both on-chain token payments and off-chain fiat settlements. It allows sellers to deposit tokens for sale, whitelisted buyers to make offers, and manages structured sale processes with mechanisms for refutations and dispute resolution.

A contract to facilitate token sales in exchange for fiat or tokens. Inherits from AbstractTokenExchange, Ownable, and ReentrancyGuard for enhanced functionality and security.

SELLER

solidity
address SELLER

Address of the seller depositing tokens for sale.

Offerors

solidity
mapping(address => bool) Offerors

Tracks authorized offeror addresses.

Status

_Represents the overall status of the SalesOrder.

  • DRAFTING: The sale is awaiting configuration by the owner.
  • INITIATED: The sale has been configured._
solidity
enum Status {
  DRAFTING,
  INITIATED
}

status

solidity
enum SalesOrder.Status status

OfferStatus

_Represents the status of an individual offer.

  • NONE: No offer exists for the given ID.
  • ACTIVE: The offer is active and not accepted yet.
  • ACCEPTED: The offer has been accepted.
  • IN_PROGRESS: The sale has been initiated for the offer.
  • COMPLETED: The sale using this offer is completed.
  • CANCELLED: The offer and corresponding sale was cancelled._
solidity
enum OfferStatus {
  NONE,
  ACTIVE,
  ACCEPTED,
  IN_PROGRESS,
  COMPLETED,
  CANCELLED
}

Offer

Represents an offer made by a potential buyer.

solidity
struct Offer {
  enum SalesOrder.OfferStatus status;
  address offeror;
  uint256 baseValue;
  uint256 quoteValue;
}

offers

solidity
mapping(uint256 => struct SalesOrder.Offer) offers

Mapping of offer IDs to their corresponding Offer data.

SalesOrderInvalidAddress

solidity
error SalesOrderInvalidAddress(address receivedAddress)

SalesOrderInvalidStatus

solidity
error SalesOrderInvalidStatus(enum SalesOrder.Status status)

SalesOrderInvalidOfferId

solidity
error SalesOrderInvalidOfferId(uint256 conditionId)

SalesOrderTransferFailed

solidity
error SalesOrderTransferFailed(address token, address to, uint256 amount)

SalesOrderUnauthorizedCaller

solidity
error SalesOrderUnauthorizedCaller(address sender)

SalesOrderInvalidOfferStatus

solidity
error SalesOrderInvalidOfferStatus(uint256 offerId, enum SalesOrder.OfferStatus status)

StatusUpdated

solidity
event StatusUpdated(enum SalesOrder.Status newStatus)

Emitted when the contract status is updated.

OfferMade

solidity
event OfferMade(uint256 offerId, address offeror, uint256 baseValue, uint256 quoteValue)

Emitted when a new offer is made.

OfferAccepted

solidity
event OfferAccepted(uint256 offerId)

Emitted when an offer is accepted.

SaleInitiated

solidity
event SaleInitiated(uint256 offerId)

Emitted when a sale is initiated for an offer.

SaleCompleted

solidity
event SaleCompleted(uint256 offerId)

Emitted when a sale is completed.

SaleRefuted

solidity
event SaleRefuted(uint256 offerId)

SaleUnRefuted

solidity
event SaleUnRefuted(uint256 offerId)

Emitted when a sale is refuted.

SaleCancelled

solidity
event SaleCancelled(uint256 offerId)

Emitted when a sale is cancelled.

constructor

solidity
constructor(address _initialOwner, address _seller, string _erc1155uri) public

Initializes the contract with the owner, seller and ERC-1155 URI.

Parameters

NameTypeDescription
_initialOwneraddressThe initial owner of the contract.
_selleraddressThe address of the seller.
_erc1155uristringThe metadata URI for the ERC-1155 tokens.

initiate

solidity
function initiate(enum AbstractTokenExchange.ExchangeType _saleType, address _baseToken, address _quoteToken, address[] _offerorWhitelist, uint256 _activeTill, uint256 _refutationWindow, address _disputeResolver) external

Initiates the SalesOrder with the parameters of sales.

Parameters

NameTypeDescription
_saleTypeenum AbstractTokenExchange.ExchangeTypeThe type of exchange (TOKEN_FOR_TOKEN or FIAT_FOR_TOKEN).
_baseTokenaddressThe address of the ERC-20 token being sold (base token).
_quoteTokenaddressThe address of the ERC-20 token used as payment (quote token); required for TOKEN_FOR_TOKEN.
_offerorWhitelistaddress[]A list of addresses permitted to make offers.
_activeTilluint256The timestamp until which the SalesOrder remains active.
_refutationWindowuint256The duration (in seconds) allowed for refuting offers.
_disputeResolveraddressThe address of the account or contract designated to resolve disputes.

deposit

solidity
function deposit(uint256 _value) external

Allows the seller to deposit base tokens and mint equivalent ERC-1155 tokens.

Parameters

NameTypeDescription
_valueuint256The amount of base tokens to deposit.

makeOffer

solidity
function makeOffer(uint256 _offerId, uint256 baseValue, uint256 quoteValue) external

Allows a whitelisted offeror to submit an offer for the SalesOrder.

Parameters

NameTypeDescription
_offerIduint256A unique identifier for the offer.
baseValueuint256The amount of base tokens involved in the offer.
quoteValueuint256The amount of quote tokens (or fiat equivalent) offered.

acceptOffer

solidity
function acceptOffer(uint256 _offerId) external

Allows the seller to accept a submitted offer.

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the offer being accepted.

initiateSale

solidity
function initiateSale(uint256 _offerId) external

Initiates the sale process for an accepted offer.

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the accepted offer for which the sale is being initiated .

completeSale

solidity
function completeSale(uint256 _offerId) external

Completes the sale process for a FIAT_FOR_TOKEN sale.

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the offer for which the sale is being completed.

refuteSale

solidity
function refuteSale(uint256 _offerId) external

Allows the seller to refute an initiated sale. Useful in the event of a failure of payment-terms off-chain .

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the offer for which the sale is being refuted.

unrefuteSale

solidity
function unrefuteSale(uint256 _offerId) external

Allows the dispute resolver to unrefute a sale. Useful in the event on an undue/resolved refutation.

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the offer for which a refute sale is being unrefuted.

cancelSale

solidity
function cancelSale(uint256 _offerId) external

Allows the dispute resolver to cancel a refute sale. Useful in the event of a failed sale.

Parameters

NameTypeDescription
_offerIduint256The unique identifier of the offer for which a refuted sale is being canceled.

withdraw

solidity
function withdraw(uint256 _value, address _to) external

Allows the seller to withdraw unsold deposited base tokens.

Parameters

NameTypeDescription
_valueuint256The amount of base tokens to withdraw.
_toaddressThe address where the withdrawn tokens should be sent.