Skip to content

Commit

Permalink
New tokenIds (#583)
Browse files Browse the repository at this point in the history
* Alternative tokenId

* fix tests

* move id handling to reserve range

* fix integration

* set min exchange id in constructor

* fix deploy

* fix unit tests

* review fixes

* remove extractExchageId + optimize vouchers

* remove transferpremintedFrom

* set _committed in issueVoucher

* Minor optimization

---------

Co-authored-by: Mischa <[email protected]>
  • Loading branch information
zajck and mischat authored Apr 20, 2023
1 parent 43d0ce9 commit 00c26ea
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 587 deletions.
34 changes: 5 additions & 29 deletions contracts/interfaces/clients/IBosonVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IERC721MetadataUpgradeable } from "@openzeppelin/contracts-upgradeable/
*
* @notice This is the interface for the Boson Protocol ERC-721 Voucher contract.
*
* The ERC-165 identifier for this interface is: 0x0db62fa8
* The ERC-165 identifier for this interface is: 0xaf16da6e
*/
interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable {
event ContractURIChanged(string contractURI);
Expand All @@ -33,19 +33,19 @@ interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable {
* Minted voucher supply is sent to the buyer.
* Caller must have PROTOCOL role.
*
* @param _exchangeId - the id of the exchange (corresponds to the ERC-721 token id)
* @param _tokenId - voucher token id corresponds to <<uint128(offerId)>>.<<uint128(exchangeId)>>
* @param _buyer - the buyer address
*/
function issueVoucher(uint256 _exchangeId, address _buyer) external;
function issueVoucher(uint256 _tokenId, address _buyer) external;

/**
* @notice Burns a voucher.
*
* Caller must have PROTOCOL role.
*
* @param _exchangeId - the id of the exchange (corresponds to the ERC-721 token id)
* @param _tokenId - voucher token id corresponds to <<uint128(offerId)>>.<<uint128(exchangeId)>>
*/
function burnVoucher(uint256 _exchangeId) external;
function burnVoucher(uint256 _tokenId) external;

/**
* @notice Gets the seller id.
Expand Down Expand Up @@ -196,30 +196,6 @@ interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable {
*/
function burnPremintedVouchers(uint256 _offerId) external;

/**
* @notice Non-standard ERC721 function to transfer a pre-minted token from one address to another.
*
* Reverts if:
* - TokenId was already used to commit
* - TokenId already exists (i.e. has an owner)
* - TokenId has not been preminted yet
* - TokenId was already burned
* - From is not the owner of the voucher contract
*
* @param _from - the address to transfer from
* @param _to - the address to transfer to
* @param _offerId - the id of the offer
* @param _tokenId - the id of the token
* @param _data - data to pass if receiver is contract
*/
function transferPremintedFrom(
address _from,
address _to,
uint256 _offerId,
uint256 _tokenId,
bytes memory _data
) external;

/**
* @notice Gets the number of vouchers available to be pre-minted for an offer.
*
Expand Down
3 changes: 2 additions & 1 deletion contracts/mock/MockExchangeHandlerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ contract MockExchangeHandlerFacet is BuyerBase, DisputeBase {
// Burn the voucher
(, Offer storage offer) = fetchOffer(_exchange.offerId);
IBosonVoucher bosonVoucher = IBosonVoucher(protocolLookups().cloneAddress[offer.sellerId]);
bosonVoucher.burnVoucher(_exchange.id);
uint256 tokenId = _exchange.id + (_exchange.offerId << 128);
bosonVoucher.burnVoucher(tokenId);
}

/**
Expand Down
12 changes: 0 additions & 12 deletions contracts/protocol/bases/BeaconClientBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,6 @@ abstract contract BeaconClientBase is BosonTypes {
(, offer, offerDates, , , ) = IBosonOfferHandler(protocolDiamond).getOffer(_offerId);
}

/**
* @notice Gets the exchange associated with a voucher
*
* @param _exchangeId - the id of the exchange
* @return exists - the exchange was found
* @return exchange - the exchange associated with the _exchangeId
*/
function getBosonExchange(uint256 _exchangeId) internal view returns (bool exists, Exchange memory exchange) {
address protocolDiamond = IClientExternalAddresses(BeaconClientLib._beacon()).getProtocolAddress();
(exists, exchange, ) = IBosonExchangeHandler(protocolDiamond).getExchange(_exchangeId);
}

/**
* @notice Informs protocol of new buyer associated with an exchange
*
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/bases/OfferBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ contract OfferBase is ProtocolBase, IBosonOfferEvents {
require(offer.quantityAvailable >= _length, INVALID_RANGE_LENGTH);

// Prevent reservation of too large range, since it affects exchangeId
require(_length < (1 << 128), INVALID_RANGE_LENGTH);
require(_length < (1 << 64), INVALID_RANGE_LENGTH);

// Get starting token id
ProtocolLib.ProtocolCounters storage pc = protocolCounters();
Expand Down
Loading

0 comments on commit 00c26ea

Please sign in to comment.