IBosonExchangeHandler
View Source: contracts/interfaces/handlers/IBosonExchangeHandler.sol
↗ Extends: IBosonExchangeEvents, IBosonFundsLibEvents, IBosonTwinEvents
IBosonExchangeHandler
Handles exchanges associated with offers within the protocol.
The ERC-165 identifier for this interface is: 0xe300dfc1
Functions
- commitToOffer(address payable _buyer, uint256 _offerId)
- commitToPreMintedOffer(address payable _buyer, uint256 _offerId, uint256 _exchangeId)
- completeExchange(uint256 _exchangeId)
- completeExchangeBatch(uint256[] _exchangeIds)
- revokeVoucher(uint256 _exchangeId)
- cancelVoucher(uint256 _exchangeId)
- expireVoucher(uint256 _exchangeId)
- extendVoucher(uint256 _exchangeId, uint256 _validUntilDate)
- redeemVoucher(uint256 _exchangeId)
- onVoucherTransferred(uint256 _exchangeId, address payable _newBuyer)
- isExchangeFinalized(uint256 _exchangeId)
- getExchange(uint256 _exchangeId)
- getExchangeState(uint256 _exchangeId)
- getNextExchangeId()
- getReceipt(uint256 _exchangeId)
commitToOffer
Commits to an offer (first step of an exchange).
Emits a BuyerCommitted event if successful.
Issues a voucher to the buyer address.
Reverts if:
- The exchanges region of protocol is paused
- The buyers region of protocol is paused
- OfferId is invalid
- Offer has been voided
- Offer has expired
- Offer is not yet available for commits
- Offer's quantity available is zero
- Buyer address is zero
- Buyer account is inactive
- Buyer is token-gated (conditional commit requirements not met or already used)
- Offer price is in native token and caller does not send enough
- Offer price is in some ERC20 token and caller also sends native currency
- Contract at token address does not support ERC20 function transferFrom
- Calling transferFrom on token fails for some reason (e.g. protocol is not approved to transfer)
- Received ERC20 token amount differs from the expected value
- Seller has less funds available than sellerDeposit
function commitToOffer(address payable _buyer,
uint256 _offerId)
external
payable
Arguments
Name | Type | Description |
---|---|---|
_buyer | address payable | the buyer's address (caller can commit on behalf of a buyer) |
_offerId | uint256 | the id of the offer to commit to |
commitToPreMintedOffer
Commits to a preminted offer (first step of an exchange).
Emits a BuyerCommitted event if successful.
Reverts if:
- The exchanges region of protocol is paused
- The buyers region of protocol is paused
- Caller is not the voucher contract, owned by the seller
- Exchange exists already
- Offer has been voided
- Offer has expired
- Offer is not yet available for commits
- Buyer account is inactive
- Buyer is token-gated (conditional commit requirements not met or already used)
- Seller has less funds available than sellerDeposit and price
function commitToPreMintedOffer(address payable _buyer,
uint256 _offerId,
uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_buyer | address payable | the buyer's address (caller can commit on behalf of a buyer) |
_offerId | uint256 | the id of the offer to commit to |
_exchangeId | uint256 | the id of the exchange |
completeExchange
Completes an exchange.
Emits an ExchangeCompleted event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in Redeemed state
- Caller is not buyer and offer dispute period has not elapsed
function completeExchange(uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange to complete |
completeExchangeBatch
Completes a batch of exchanges.
Emits an ExchangeCompleted event for every exchange if finalized to the Complete state.
Reverts if:
- The exchanges region of protocol is paused
- Number of exchanges exceeds maximum allowed number per batch
- For any exchange:
- Exchange does not exist
- Exchange is not in Redeemed state
- Caller is not buyer and offer dispute period has not elapsed
function completeExchangeBatch(uint256[] _exchangeIds)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeIds | uint256[] | the array of exchanges ids |
revokeVoucher
Revokes a voucher.
Emits a VoucherRevoked event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in Committed state
- Caller is not seller's assistant
function revokeVoucher(uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
cancelVoucher
Cancels a voucher.
Emits a VoucherCanceled event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in Committed state
- Caller does not own voucher
function cancelVoucher(uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
expireVoucher
Expires a voucher.
Emits a VoucherExpired event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in Committed state
- Redemption period has not yet elapsed
function expireVoucher(uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
extendVoucher
Extends a Voucher's validity period.
Emits a VoucherExtended event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in Committed state
- Caller is not seller's assistant
- New date is not later than the current one
function extendVoucher(uint256 _exchangeId,
uint256 _validUntilDate)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
_validUntilDate | uint256 | the new voucher expiry date |
redeemVoucher
Redeems a voucher.
Emits a VoucherRedeemed event if successful.
Reverts if
- The exchanges region of protocol is paused
- Exchange does not exist
- Exchange is not in committed state
- Caller does not own voucher
- Current time is prior to offer.voucherRedeemableFromDate
- Current time is after voucher.validUntilDate
function redeemVoucher(uint256 _exchangeId)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
onVoucherTransferred
Informs protocol of new buyer associated with an exchange.
Emits a VoucherTransferred event if successful.
Reverts if
- The buyers region of protocol is paused
- Caller is not a clone address associated with the seller
- Exchange does not exist
- Exchange is not in Committed state
- Voucher has expired
- New buyer's existing account is deactivated
function onVoucherTransferred(uint256 _exchangeId,
address payable _newBuyer)
external
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange |
_newBuyer | address payable | the address of the new buyer |
isExchangeFinalized
Checks if the given exchange in a finalized state.
Returns true if
- Exchange state is Revoked, Canceled, or Completed
- Exchange is disputed and dispute state is Retracted, Resolved, Decided or Refused
function isExchangeFinalized(uint256 _exchangeId)
external
view
returns(bool exists, bool isFinalized)
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange to check |
Returns
Name | Type | Description |
---|---|---|
exists | bool | true if the exchange exists |
isFinalized | bool | true if the exchange is finalized |
getExchange
Gets the details about a given exchange.
function getExchange(uint256 _exchangeId)
external
view
returns(bool exists,
BosonTypes.Exchange memory exchange,
BosonTypes.Voucher memory voucher)
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange to check |
Returns
Name | Type | Description |
---|---|---|
exists | bool | true if the exchange exists |
exchange | BosonTypes.Exchange | the exchange details. See {BosonTypes.Exchange} |
voucher | BosonTypes.Voucher | the voucher details. See {BosonTypes.Voucher} |
getExchangeState
Gets the state of a given exchange.
function getExchangeState(uint256 _exchangeId)
external
view
returns(bool exists, enum BosonTypes.ExchangeState state)
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the id of the exchange to check |
Returns
BosonTypes.ExchangeState
getNextExchangeId
Gets the id that will be assigned to the next exchange.Does not increment the counter.
function getNextExchangeId()
external
view
returns(uint256 nextExchangeId)
Returns
Name | Type | Description |
---|---|---|
nextExchangeId | uint256 | the next exchange id |
getReceipt
Gets exchange receipt.
Reverts if:
- Exchange is not in a final state
- Exchange id is invalid
function getReceipt(uint256 _exchangeId)
external
view
returns(BosonTypes.Receipt memory receipt)
Arguments
Name | Type | Description |
---|---|---|
_exchangeId | uint256 | the exchange id |
Returns
Name | Type | Description |
---|---|---|
receipt | BosonTypes.Receipt | the receipt for the exchange. See {BosonTypes.Receipt} |