Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
ConfigHandlerFacet
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 100 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import "../../domain/BosonConstants.sol";
import { IBosonConfigHandler } from "../../interfaces/handlers/IBosonConfigHandler.sol";
import { IAccessControl } from "../../interfaces/IAccessControl.sol";
import { DiamondLib } from "../../diamond/DiamondLib.sol";
import { ProtocolBase } from "../bases/ProtocolBase.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { EIP712Lib } from "../libs/EIP712Lib.sol";
import { BeaconClientProxy } from "../../protocol/clients/proxy/BeaconClientProxy.sol";
/**
* @title ConfigHandlerFacet
*
* @notice Handles management and queries of various protocol-related settings.
*/
contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
/**
* @notice Initializes facet.
* This function is callable only once.
*
* @param _addresses - struct of Boson Protocol addresses (Boson Token (ERC-20) contract, treasury, and Voucher contract)
* @param _limits - struct with Boson Protocol limits
* @param defaultFeePercentage - efault percentage that will be taken as a fee from the net of a Boson Protocol exchange.
* @param flatBosonFee - flat fee taken for exchanges in $BOSON
* @param buyerEscalationDepositPercentage - buyer escalation deposit percentage
*/
function initialize(
ProtocolLib.ProtocolAddresses calldata _addresses,
ProtocolLib.ProtocolLimits calldata _limits,
uint256 defaultFeePercentage,
uint256 flatBosonFee,
uint256 buyerEscalationDepositPercentage
) public onlyUninitialized(type(IBosonConfigHandler).interfaceId) {
// Register supported interfaces
DiamondLib.addSupportedInterface(type(IBosonConfigHandler).interfaceId);
// Initialize protocol config params
// _addresses.beaconProxy is ignored, since it's deployed later in this function
setTokenAddress(_addresses.token);
setTreasuryAddress(_addresses.treasury);
setVoucherBeaconAddress(_addresses.voucherBeacon);
setPriceDiscoveryAddress(_addresses.priceDiscovery);
setProtocolFeePercentage(defaultFeePercentage); // this sets the default fee percentage if fee table is not configured for the exchange token
setProtocolFeeFlatBoson(flatBosonFee);
setMaxEscalationResponsePeriod(_limits.maxEscalationResponsePeriod);
setBuyerEscalationDepositPercentage(buyerEscalationDepositPercentage);
setMaxTotalOfferFeePercentage(_limits.maxTotalOfferFeePercentage);
setMaxRoyaltyPercentage(_limits.maxRoyaltyPercentage);
setMaxResolutionPeriod(_limits.maxResolutionPeriod);
setMinResolutionPeriod(_limits.minResolutionPeriod);
setMinDisputePeriod(_limits.minDisputePeriod);
setMutualizerGasStipend(_limits.mutualizerGasStipend);
// Initialize protocol counters
ProtocolLib.ProtocolCounters storage pc = protocolCounters();
pc.nextAccountId = 1;
pc.nextBundleId = 1;
pc.nextExchangeId = 1;
pc.nextGroupId = 1;
pc.nextOfferId = 1;
pc.nextTwinId = 1;
// Initialize reentrancyStatus
protocolStatus().reentrancyStatus = NOT_ENTERED;
// Initialize protocol meta-transaction config params
ProtocolLib.ProtocolMetaTxInfo storage pmti = protocolMetaTxInfo();
pmti.domainSeparator = EIP712Lib.buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION);
pmti.cachedChainId = block.chainid;
// Deploy Boson Voucher proxy contract
address beaconProxy = address(new BeaconClientProxy{ salt: VOUCHER_PROXY_SALT }());
setBeaconProxyAddress(beaconProxy);
}
/**
* @notice Sets the Boson Token (ERC-20 contract) address.
*
* Emits a TokenAddressChanged event if successful.
*
* Reverts if _tokenAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _tokenAddress - the Boson Token (ERC-20 contract) address
*/
function setTokenAddress(address payable _tokenAddress) public override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_tokenAddress);
protocolAddresses().token = _tokenAddress;
emit TokenAddressChanged(_tokenAddress, _msgSender());
}
/**
* @notice Gets the Boson Token (ERC-20 contract) address.
*
* @return the Boson Token (ERC-20 contract) address
*/
function getTokenAddress() external view override returns (address payable) {
return protocolAddresses().token;
}
/**
* @notice Sets the Boson Protocol multi-sig wallet address.
*
* Emits a TreasuryAddressChanged event if successful.
*
* Reverts if _treasuryAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _treasuryAddress - the the multi-sig wallet address
*/
function setTreasuryAddress(address payable _treasuryAddress) public override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_treasuryAddress);
protocolAddresses().treasury = _treasuryAddress;
emit TreasuryAddressChanged(_treasuryAddress, _msgSender());
}
/**
* @notice Gets the Boson Protocol multi-sig wallet address.
*
* @return the Boson Protocol multi-sig wallet address
*/
function getTreasuryAddress() external view override returns (address payable) {
return protocolAddresses().treasury;
}
/**
* @notice Sets the Boson Voucher beacon contract address.
*
* Emits a VoucherBeaconAddressChanged event if successful.
*
* Reverts if _voucherBeaconAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _voucherBeaconAddress - the Boson Voucher beacon contract address
*/
function setVoucherBeaconAddress(address _voucherBeaconAddress) public override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_voucherBeaconAddress);
protocolAddresses().voucherBeacon = _voucherBeaconAddress;
emit VoucherBeaconAddressChanged(_voucherBeaconAddress, _msgSender());
}
/**
* @notice Gets the Boson Voucher beacon contract address.
*
* @return the Boson Voucher beacon contract address
*/
function getVoucherBeaconAddress() external view override returns (address) {
return protocolAddresses().voucherBeacon;
}
/**
* @notice Sets the Boson Voucher reference proxy implementation address.
*
* Emits a BeaconProxyAddressChanged event if successful.
*
* Reverts if _beaconProxyAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _beaconProxyAddress - reference proxy implementation address
*/
function setBeaconProxyAddress(address _beaconProxyAddress) public override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_beaconProxyAddress);
protocolAddresses().beaconProxy = _beaconProxyAddress;
emit BeaconProxyAddressChanged(_beaconProxyAddress, _msgSender());
}
/**
* @notice Gets the beaconProxy address.
*
* @return the beaconProxy address
*/
function getBeaconProxyAddress() external view override returns (address) {
return protocolAddresses().beaconProxy;
}
/**
* @notice Sets the Boson Price Discovery contract address.
*
* Emits a PriceDiscoveryAddressChanged event if successful.
*
* Reverts if _priceDiscovery is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _priceDiscovery - the Boson Price Discovery contract address
*/
function setPriceDiscoveryAddress(address _priceDiscovery) public override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_priceDiscovery);
protocolAddresses().priceDiscovery = _priceDiscovery;
emit PriceDiscoveryAddressChanged(_priceDiscovery, _msgSender());
}
/**
* @notice Gets the Boson Price Discovery contract address.
*
* @return the Boson Price Discovery contract address
*/
function getPriceDiscoveryAddress() external view override returns (address) {
return protocolAddresses().priceDiscovery;
}
/**
* @notice Sets the protocol fee percentage.
*
* Emits a ProtocolFeePercentageChanged event if successful.
*
* Reverts if the _protocolFeePercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _protocolFeePercentage - the percentage that will be taken as a fee from the net of a Boson Protocol sale or auction (after royalties)
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setProtocolFeePercentage(uint256 _protocolFeePercentage) public override onlyRole(ADMIN) nonReentrant {
// Make sure percentage is less than 10000
checkMaxPercententage(_protocolFeePercentage);
// Store fee percentage
protocolFees().percentage = _protocolFeePercentage;
// Notify watchers of state change
emit ProtocolFeePercentageChanged(_protocolFeePercentage, _msgSender());
}
/**
* @notice Sets the feeTable for a specific token given price ranges and fee tiers for
* the corresponding price ranges.
*
* Reverts if token is $BOSON.
* Reverts if the number of fee percentages does not match the number of price ranges.
* Reverts if the price ranges are not in ascending order.
* Reverts if any of the fee percentages value is above 100%.
*
* @dev Caller must have ADMIN role.
*
* @param _tokenAddress - the address of the token
* @param _priceRanges - array of token price ranges
* @param _feePercentages - array of fee percentages corresponding to each price range
*/
function setProtocolFeeTable(
address _tokenAddress,
uint256[] calldata _priceRanges,
uint256[] calldata _feePercentages
) external override onlyRole(ADMIN) nonReentrant {
if (_tokenAddress == protocolAddresses().token) revert FeeTableAssetNotSupported();
if (_priceRanges.length != _feePercentages.length) revert ArrayLengthMismatch();
// Clear existing price ranges and percentage tiers
delete protocolFees().tokenPriceRanges[_tokenAddress];
delete protocolFees().tokenFeePercentages[_tokenAddress];
if (_priceRanges.length != 0) {
setTokenPriceRanges(_tokenAddress, _priceRanges);
setTokenFeePercentages(_tokenAddress, _feePercentages);
}
emit FeeTableUpdated(_tokenAddress, _priceRanges, _feePercentages, _msgSender());
}
/**
* @notice Gets the current fee table for a given token.
*
* @dev This funciton is used to check price ranges config. If you need to apply percentage based on
* _exchangeToken and offerPrice, use getProtocolFeePercentage(address,uint256)
*
* @param _tokenAddress - the address of the token
* @return priceRanges - array of token price ranges
* @return feePercentages - array of fee percentages corresponding to each price range
*/
function getProtocolFeeTable(
address _tokenAddress
) external view returns (uint256[] memory priceRanges, uint256[] memory feePercentages) {
ProtocolLib.ProtocolFees storage fees = protocolFees();
priceRanges = fees.tokenPriceRanges[_tokenAddress];
feePercentages = fees.tokenFeePercentages[_tokenAddress];
}
/**
* @notice Gets the default protocol fee percentage.
*
* @return the default protocol fee percentage
*/
function getProtocolFeePercentage() external view override returns (uint256) {
return protocolFees().percentage;
}
/**
* @notice Gets the protocol fee percentage based on protocol fee table
*
* @dev This function calculates the protocol fee percentage for specific token and price.
* If the token has a custom fee table configured, it returns the corresponding fee percentage
* for the price range. If the token does not have a custom fee table, it falls back
* to the default protocol fee percentage.
*
* Reverts if the exchange token is BOSON.
*
* @param _exchangeToken - The address of the token being used for the exchange.
* @param _price - The price of the item or service in the exchange.
*
* @return the protocol fee percentage for given price and exchange token
*/
function getProtocolFeePercentage(address _exchangeToken, uint256 _price) external view override returns (uint256) {
return _getFeePercentage(_exchangeToken, _price);
}
/**
* @notice Retrieves the protocol fee percentage for a given token and price.
*
* @dev This function calculates the protocol fee based on the token and price.
* If the token has a custom fee table, it applies the corresponding fee percentage
* for the price range. If the token does not have a custom fee table, it falls back
* to the default protocol fee percentage. If the exchange token is BOSON,
* this function returns the flatBoson fee
*
* @param _exchangeToken - The address of the token being used for the exchange.
* @param _price - The price of the item or service in the exchange.
*
* @return The protocol fee amount based on the token and the price.
*/
function getProtocolFee(address _exchangeToken, uint256 _price) external view override returns (uint256) {
return _getProtocolFee(_exchangeToken, _price);
}
/**
* @notice Sets the flat protocol fee for exchanges in $BOSON.
*
* Emits a ProtocolFeeFlatBosonChanged event if successful.
*
* @dev Caller must have ADMIN role.
*
* @param _protocolFeeFlatBoson - the flat fee taken for exchanges in $BOSON
*
*/
function setProtocolFeeFlatBoson(uint256 _protocolFeeFlatBoson) public override onlyRole(ADMIN) nonReentrant {
// Store fee percentage
protocolFees().flatBoson = _protocolFeeFlatBoson;
// Notify watchers of state change
emit ProtocolFeeFlatBosonChanged(_protocolFeeFlatBoson, _msgSender());
}
/**
* @notice Gets the flat protocol fee for exchanges in $BOSON.
*
* @return the flat fee taken for exchanges in $BOSON
*/
function getProtocolFeeFlatBoson() external view override returns (uint256) {
return protocolFees().flatBoson;
}
/**
* @notice Sets the maximum escalation response period a dispute resolver can specify.
*
* Emits a MaxEscalationResponsePeriodChanged event if successful.
*
* Reverts if the _maxEscalationResponsePeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _maxEscalationResponsePeriod - the maximum escalation response period that a {BosonTypes.DisputeResolver} can specify
*/
function setMaxEscalationResponsePeriod(
uint256 _maxEscalationResponsePeriod
) public override onlyRole(ADMIN) nonReentrant {
// Make sure _maxEscalationResponsePeriod is greater than 0
checkNonZeroValue(_maxEscalationResponsePeriod);
protocolLimits().maxEscalationResponsePeriod = _maxEscalationResponsePeriod;
emit MaxEscalationResponsePeriodChanged(_maxEscalationResponsePeriod, _msgSender());
}
/**
* @notice Gets the maximum escalation response period a dispute resolver can specify.
*
* @return the maximum escalation response period that a {BosonTypes.DisputeResolver} can specify
*/
function getMaxEscalationResponsePeriod() external view override returns (uint256) {
return protocolLimits().maxEscalationResponsePeriod;
}
/**
* @notice Sets the total offer fee percentage limit that will validate the sum of (Protocol Fee percentage + Agent Fee percentage) of an offer fee.
*
* Emits a MaxTotalOfferFeePercentageChanged event if successful.
*
* Reverts if _maxTotalOfferFeePercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _maxTotalOfferFeePercentage - the maximum total offer fee percentage
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setMaxTotalOfferFeePercentage(
uint16 _maxTotalOfferFeePercentage
) public override onlyRole(ADMIN) nonReentrant {
// Make sure percentage is less than 10000
checkMaxPercententage(_maxTotalOfferFeePercentage);
// Store fee percentage
protocolLimits().maxTotalOfferFeePercentage = _maxTotalOfferFeePercentage;
// Notify watchers of state change
emit MaxTotalOfferFeePercentageChanged(_maxTotalOfferFeePercentage, _msgSender());
}
/**
* @notice Gets the total offer fee percentage limit that will validate the sum of (Protocol Fee percentage + Agent Fee percentage) of an offer fee.
*
* @return the maximum total offer fee percentage
*/
function getMaxTotalOfferFeePercentage() external view override returns (uint16) {
return protocolLimits().maxTotalOfferFeePercentage;
}
/**
* @notice Sets the maximum royalty percentage that can be set by the seller.
*
* Emits a MaxRoyaltyPercentageChanged event if successful.
*
* Reverts if:
* - The _maxRoyaltyPercentage is zero.
* - The _maxRoyaltyPercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _maxRoyaltyPercentage - the maximum royalty percentage
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setMaxRoyaltyPercentage(uint16 _maxRoyaltyPercentage) public override onlyRole(ADMIN) nonReentrant {
// Make sure percentage is greater than 0
checkNonZeroValue(_maxRoyaltyPercentage);
// Make sure percentage is less than 10000
checkMaxPercententage(_maxRoyaltyPercentage);
// Store fee percentage
protocolLimits().maxRoyaltyPercentage = _maxRoyaltyPercentage;
// Notify watchers of state change
emit MaxRoyaltyPercentageChanged(_maxRoyaltyPercentage, _msgSender());
}
/**
* @notice Gets the maximum royalty percentage that can be set by the seller.
*
* @return the maximum royalty percentage
*/
function getMaxRoyaltyPercentage() external view override returns (uint16) {
return protocolLimits().maxRoyaltyPercentage;
}
/**
* @notice Sets the buyer escalation fee percentage.
*
* Emits a BuyerEscalationFeePercentageChanged event if successful.
*
* Reverts if the _buyerEscalationDepositPercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _buyerEscalationDepositPercentage - the percentage of the DR fee that will be charged to buyer if they want to escalate the dispute
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setBuyerEscalationDepositPercentage(
uint256 _buyerEscalationDepositPercentage
) public override onlyRole(ADMIN) nonReentrant {
// Make sure percentage is less than 10000
checkMaxPercententage(_buyerEscalationDepositPercentage);
// Store fee percentage
protocolFees().buyerEscalationDepositPercentage = _buyerEscalationDepositPercentage;
// Notify watchers of state change
emit BuyerEscalationFeePercentageChanged(_buyerEscalationDepositPercentage, _msgSender());
}
/**
* @notice Gets the buyer escalation fee percentage.
*
* @return the percentage of the DR fee that will be charged to buyer if they want to escalate the dispute
*/
function getBuyerEscalationDepositPercentage() external view override returns (uint256) {
return protocolFees().buyerEscalationDepositPercentage;
}
/**
* @notice Sets the contract address for the given AuthTokenType.
*
* Emits an AuthTokenContractChanged event if successful.
*
* Reverts if:
* - _authTokenType is None.
* - _authTokenType is Custom.
* - _authTokenContract is the zero address.
*
* @dev Caller must have ADMIN role.
*
* @param _authTokenType - the auth token type, as an Enum value
* @param _authTokenContract the address of the auth token contract (e.g. Lens or ENS contract address)
*/
function setAuthTokenContract(
AuthTokenType _authTokenType,
address _authTokenContract
) external override onlyRole(ADMIN) nonReentrant {
if (_authTokenType == AuthTokenType.None || _authTokenType == AuthTokenType.Custom)
revert InvalidAuthTokenType();
checkNonZeroAddress(_authTokenContract);
protocolLookups().authTokenContracts[_authTokenType] = _authTokenContract;
emit AuthTokenContractChanged(_authTokenType, _authTokenContract, _msgSender());
}
/**
* @notice Gets the contract address for the given AuthTokenType.
*
* @param _authTokenType - the auth token type, as an Enum value
* @return the address of the auth token contract (e.g. Lens or ENS contract address) for the given AuthTokenType
*/
function getAuthTokenContract(AuthTokenType _authTokenType) external view returns (address) {
return protocolLookups().authTokenContracts[_authTokenType];
}
/**
* @notice Sets the minimum resolution period a seller can specify.
*
* Emits a MinResolutionPeriodChanged event.
*
* Reverts if _minResolutionPeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _minResolutionPeriod - the minimum resolution period that a {BosonTypes.Seller} can specify
*/
function setMinResolutionPeriod(uint256 _minResolutionPeriod) public override onlyRole(ADMIN) nonReentrant {
// Make sure _maxResolutionPeriod is greater than 0
checkNonZeroValue(_minResolutionPeriod);
// cache protocol limits
ProtocolLib.ProtocolLimits storage limits = protocolLimits();
// Make sure _minResolutionPeriod is less than _maxResolutionPeriod
if (_minResolutionPeriod > limits.maxResolutionPeriod) revert InvalidResolutionPeriod();
limits.minResolutionPeriod = _minResolutionPeriod;
emit MinResolutionPeriodChanged(_minResolutionPeriod, _msgSender());
}
/**
* @notice Gets the minimum resolution period a seller can specify.
*
* @return the minimum resolution period that a {BosonTypes.Seller} can specify
*/
function getMinResolutionPeriod() external view override returns (uint256) {
return protocolLimits().minResolutionPeriod;
}
/**
* @notice Sets the maximum resolution period a seller can specify.
*
* Emits a MaxResolutionPeriodChanged event if successful.
*
* Reverts if the _maxResolutionPeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _maxResolutionPeriod - the maximum resolution period that a {BosonTypes.Seller} can specify
*/
function setMaxResolutionPeriod(uint256 _maxResolutionPeriod) public override onlyRole(ADMIN) nonReentrant {
// Make sure _maxResolutionPeriod is greater than 0
checkNonZeroValue(_maxResolutionPeriod);
// cache protocol limits
ProtocolLib.ProtocolLimits storage limits = protocolLimits();
// Make sure _maxResolutionPeriod is greater than _minResolutionPeriod
if (_maxResolutionPeriod < limits.minResolutionPeriod) revert InvalidResolutionPeriod();
limits.maxResolutionPeriod = _maxResolutionPeriod;
emit MaxResolutionPeriodChanged(_maxResolutionPeriod, _msgSender());
}
/**
* @notice Gets the maximum resolution period a seller can specify.
*
* @return the maximum resolution period that a {BosonTypes.Seller} can specify
*/
function getMaxResolutionPeriod() external view override returns (uint256) {
return protocolLimits().maxResolutionPeriod;
}
/**
* @notice Sets the minimum dispute period a seller can specify.
*
* Emits a MinDisputePeriodChanged event if successful.
*
* Reverts if the _minDisputePeriod is zero.
*
* @param _minDisputePeriod - the minimum resolution period that a {BosonTypes.Seller} can specify
*/
function setMinDisputePeriod(uint256 _minDisputePeriod) public override onlyRole(ADMIN) nonReentrant {
// Make sure _minDisputePeriod is greater than 0
checkNonZeroValue(_minDisputePeriod);
protocolLimits().minDisputePeriod = _minDisputePeriod;
emit MinDisputePeriodChanged(_minDisputePeriod, _msgSender());
}
/**
* @notice Gets the minimum dispute period a seller can specify.
*/
function getMinDisputePeriod() external view override returns (uint256) {
return protocolLimits().minDisputePeriod;
}
/**
* @notice Sets the access controller address.
*
* Emits an AccessControllerAddressChanged event if successful.
*
* Reverts if _accessControllerAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _accessControllerAddress - access controller address
*/
function setAccessControllerAddress(
address _accessControllerAddress
) external override onlyRole(ADMIN) nonReentrant {
checkNonZeroAddress(_accessControllerAddress);
DiamondLib.diamondStorage().accessController = IAccessControl(_accessControllerAddress);
emit AccessControllerAddressChanged(_accessControllerAddress, _msgSender());
}
/**
* @notice Gets the access controller address.
*
* @return the access controller address
*/
function getAccessControllerAddress() external view returns (address) {
return address(DiamondLib.diamondStorage().accessController);
}
/**
* @notice Sets the gas stipend forwarded when calling IDRFeeMutualizer.finalizeExchange
*
* Emits a MutualizerGasStipendChanged event if successful.
*
* Reverts if the _mutualizerGasStipend is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _mutualizerGasStipend - the gas stipend that is forwarded when calling IDRFeeMutualizer.finalizeExchange
*/
function setMutualizerGasStipend(uint256 _mutualizerGasStipend) public override onlyRole(ADMIN) nonReentrant {
// Make sure _mutualizerGasStipend is greater than 0
checkNonZeroValue(_mutualizerGasStipend);
protocolLimits().mutualizerGasStipend = _mutualizerGasStipend;
emit MutualizerGasStipendChanged(_mutualizerGasStipend, _msgSender());
}
/**
* @notice Gets the gas stipend forwarded when calling IDRFeeMutualizer.finalizeExchange
*
* @return the gas stipend that is forwarded when calling IDRFeeMutualizer.finalizeExchange
*/
function getMutualizerGasStipend() external view override returns (uint256) {
return protocolLimits().mutualizerGasStipend;
}
/**
* @notice Sets the price ranges for a specific token.
*
* @param _tokenAddress - the address of the token
* @param _priceRanges - array of price ranges for the token
*/
function setTokenPriceRanges(address _tokenAddress, uint256[] calldata _priceRanges) internal {
for (uint256 i = 1; i < _priceRanges.length; ++i) {
if (_priceRanges[i] <= _priceRanges[i - 1]) revert NonAscendingOrder();
}
protocolFees().tokenPriceRanges[_tokenAddress] = _priceRanges;
}
/**
* @notice Sets the fee percentages for a specific token and price ranges.
*
* @param _tokenAddress - the address of the token
* @param _feePercentages - array of fee percentages corresponding to each price range
*/
function setTokenFeePercentages(address _tokenAddress, uint256[] calldata _feePercentages) internal {
// Set the fee percentages for the token
for (uint256 i; i < _feePercentages.length; ++i) {
checkMaxPercententage(_feePercentages[i]);
}
protocolFees().tokenFeePercentages[_tokenAddress] = _feePercentages;
}
/**
* @notice Checks that supplied value is not 0.
*
* Reverts if the value is zero
*/
function checkNonZeroValue(uint256 _value) internal pure {
if (_value == 0) revert ValueZeroNotAllowed();
}
/**
* @notice Checks that supplied value is not address 0.
*
* Reverts if the value is address zero
*/
function checkNonZeroAddress(address _address) internal pure {
if (_address == address(0)) revert InvalidAddress();
}
/**
* @notice Checks that supplied value is less or equal to 10000 (100%).
*
* Reverts if the value more than 10000
*/
function checkMaxPercententage(uint256 _percentage) internal pure {
if (_percentage > HUNDRED_PERCENT) revert InvalidFeePercentage();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*
* _Available since v4.1._
*/
interface IERC1271 {
/**
* @dev Should return whether the signature provided is valid for the provided data
* @param hash Hash of the data to be signed
* @param signature Signature byte array associated with _data
*/
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { IAccessControl } from "../interfaces/IAccessControl.sol";
import { IDiamondCut } from "../interfaces/diamond/IDiamondCut.sol";
/**
* @title DiamondLib
*
* @notice Provides Diamond storage slot and supported interface checks.
*
* @notice Based on Nick Mudge's gas-optimized diamond-2 reference,
* with modifications to support role-based access and management of
* supported interfaces. Also added copious code comments throughout.
*
* Reference Implementation : https://github.com/mudgen/diamond-2-hardhat
* EIP-2535 Diamond Standard : https://eips.ethereum.org/EIPS/eip-2535
*
* N.B. Facet management functions from original `DiamondLib` were refactored/extracted
* to JewelerLib, since business facets also use this library for access control and
* managing supported interfaces.
*
* @author Nick Mudge <[email protected]> (https://twitter.com/mudgen)
* @author Cliff Hall <[email protected]> (https://twitter.com/seaofarrows)
*/
library DiamondLib {
bytes32 internal constant DIAMOND_STORAGE_POSITION = keccak256("diamond.standard.diamond.storage");
struct DiamondStorage {
// Maps function selectors to the facets that execute the functions
// and maps the selectors to their position in the selectorSlots array.
// func selector => address facet, selector position
mapping(bytes4 => bytes32) facets;
// Array of slots of function selectors.
// Each slot holds 8 function selectors.
mapping(uint256 => bytes32) selectorSlots;
// The number of function selectors in selectorSlots
uint16 selectorCount;
// Used to query if a contract implement is an interface.
// Used to implement ERC-165.
mapping(bytes4 => bool) supportedInterfaces;
// The Boson Protocol AccessController
IAccessControl accessController;
}
/**
* @notice Gets the Diamond storage slot.
*
* @return ds - Diamond storage slot cast to DiamondStorage
*/
function diamondStorage() internal pure returns (DiamondStorage storage ds) {
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
/**
* @notice Adds a supported interface to the Diamond.
*
* @param _interfaceId - the interface to add
*/
function addSupportedInterface(bytes4 _interfaceId) internal {
// Get the DiamondStorage struct
DiamondStorage storage ds = diamondStorage();
// Flag the interfaces as supported
ds.supportedInterfaces[_interfaceId] = true;
}
/**
* @notice Removes a supported interface from the Diamond.
*
* @param _interfaceId - the interface to remove
*/
function removeSupportedInterface(bytes4 _interfaceId) internal {
// Get the DiamondStorage struct
DiamondStorage storage ds = diamondStorage();
// Flag the interfaces as unsupported
ds.supportedInterfaces[_interfaceId] = false;
}
/**
* @notice Checks if a specific interface is supported.
* Implementation of ERC-165 interface detection standard.
*
* @param _interfaceId - the sighash of the given interface
* @return - whether or not the interface is supported
*/
function supportsInterface(bytes4 _interfaceId) internal view returns (bool) {
// Get the DiamondStorage struct
DiamondStorage storage ds = diamondStorage();
// Return the value
return ds.supportedInterfaces[_interfaceId];
}
}import "./BosonTypes.sol";
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
// Access Control Roles
bytes32 constant ADMIN = keccak256("ADMIN"); // Role Admin
bytes32 constant PAUSER = keccak256("PAUSER"); // Role for pausing the protocol
bytes32 constant PROTOCOL = keccak256("PROTOCOL"); // Role for facets of the ProtocolDiamond
bytes32 constant CLIENT = keccak256("CLIENT"); // Role for clients of the ProtocolDiamond
bytes32 constant UPGRADER = keccak256("UPGRADER"); // Role for performing contract and config upgrades
bytes32 constant FEE_COLLECTOR = keccak256("FEE_COLLECTOR"); // Role for collecting fees from the protocol
// Generic
uint256 constant HUNDRED_PERCENT = 10000; // 100% in basis points
uint256 constant PROTOCOL_ENTITY_ID = 0; // Entity ID for the protocol itself
uint256 constant VOIDED_OFFER_ID = type(uint256).max; // Offer ID for voided non-listed offers
// Pause Handler
uint256 constant ALL_REGIONS_MASK = (1 << (uint256(type(BosonTypes.PausableRegion).max) + 1)) - 1;
// Reentrancy guard
uint256 constant NOT_ENTERED = 1;
uint256 constant ENTERED = 2;
// Twin handler
uint256 constant SINGLE_TWIN_RESERVED_GAS = 160000;
uint256 constant MINIMAL_RESIDUAL_GAS = 230000;
// Config related
bytes32 constant VOUCHER_PROXY_SALT = keccak256(abi.encodePacked("BosonVoucherProxy"));
// Funds related
string constant NATIVE_CURRENCY = "Native currency";
string constant TOKEN_NAME_UNSPECIFIED = "Token name unavailable";
// EIP712Lib
string constant PROTOCOL_NAME = "Boson Protocol";
string constant PROTOCOL_VERSION = "V2";
bytes32 constant EIP712_DOMAIN_TYPEHASH = keccak256(
bytes("EIP712Domain(string name,string version,address verifyingContract,bytes32 salt)")
);
uint256 constant SLOT_SIZE = 32; // Size of a slot in bytes, used for encoding and decoding
// BosonVoucher
string constant VOUCHER_NAME = "Boson Voucher (rNFT)";
string constant VOUCHER_SYMBOL = "BOSON_VOUCHER_RNFT";
// Meta Transactions - Error
string constant FUNCTION_CALL_NOT_SUCCESSFUL = "Function call not successful";
// External contracts errors
string constant OWNABLE_ZERO_ADDRESS = "Ownable: new owner is the zero address"; // exception message from OpenZeppelin Ownable
string constant ERC721_INVALID_TOKEN_ID = "ERC721: invalid token ID"; // exception message from OpenZeppelin ERC721
// Meta Transactions - Structs
bytes32 constant META_TRANSACTION_TYPEHASH = keccak256(
bytes(
"MetaTransaction(uint256 nonce,address from,address contractAddress,string functionName,bytes functionSignature)"
)
);
bytes32 constant OFFER_DETAILS_TYPEHASH = keccak256("MetaTxOfferDetails(address buyer,uint256 offerId)");
bytes32 constant META_TX_COMMIT_TO_OFFER_TYPEHASH = keccak256(
"MetaTxCommitToOffer(uint256 nonce,address from,address contractAddress,string functionName,MetaTxOfferDetails offerDetails)MetaTxOfferDetails(address buyer,uint256 offerId)"
);
bytes32 constant CONDITIONAL_OFFER_DETAILS_TYPEHASH = keccak256(
"MetaTxConditionalOfferDetails(address buyer,uint256 offerId,uint256 tokenId)"
);
bytes32 constant META_TX_COMMIT_TO_CONDITIONAL_OFFER_TYPEHASH = keccak256(
"MetaTxCommitToConditionalOffer(uint256 nonce,address from,address contractAddress,string functionName,MetaTxConditionalOfferDetails offerDetails)MetaTxConditionalOfferDetails(address buyer,uint256 offerId,uint256 tokenId)"
);
bytes32 constant EXCHANGE_DETAILS_TYPEHASH = keccak256("MetaTxExchangeDetails(uint256 exchangeId)");
bytes32 constant META_TX_EXCHANGE_TYPEHASH = keccak256(
"MetaTxExchange(uint256 nonce,address from,address contractAddress,string functionName,MetaTxExchangeDetails exchangeDetails)MetaTxExchangeDetails(uint256 exchangeId)"
);
bytes32 constant FUND_DETAILS_TYPEHASH = keccak256(
"MetaTxFundDetails(uint256 entityId,address[] tokenList,uint256[] tokenAmounts)"
);
bytes32 constant META_TX_FUNDS_TYPEHASH = keccak256(
"MetaTxFund(uint256 nonce,address from,address contractAddress,string functionName,MetaTxFundDetails fundDetails)MetaTxFundDetails(uint256 entityId,address[] tokenList,uint256[] tokenAmounts)"
);
bytes32 constant DISPUTE_RESOLUTION_DETAILS_TYPEHASH = keccak256(
"MetaTxDisputeResolutionDetails(uint256 exchangeId,uint256 buyerPercentBasisPoints,bytes signature)"
);
bytes32 constant META_TX_DISPUTE_RESOLUTIONS_TYPEHASH = keccak256(
"MetaTxDisputeResolution(uint256 nonce,address from,address contractAddress,string functionName,MetaTxDisputeResolutionDetails disputeResolutionDetails)MetaTxDisputeResolutionDetails(uint256 exchangeId,uint256 buyerPercentBasisPoints,bytes signature)"
);
// Function names
string constant COMMIT_TO_OFFER = "commitToOffer(address,uint256)";
string constant COMMIT_TO_CONDITIONAL_OFFER = "commitToConditionalOffer(address,uint256,uint256)";
string constant CANCEL_VOUCHER = "cancelVoucher(uint256)";
string constant REDEEM_VOUCHER = "redeemVoucher(uint256)";
string constant COMPLETE_EXCHANGE = "completeExchange(uint256)";
string constant WITHDRAW_FUNDS = "withdrawFunds(uint256,address[],uint256[])";
string constant RETRACT_DISPUTE = "retractDispute(uint256)";
string constant RAISE_DISPUTE = "raiseDispute(uint256)";
string constant ESCALATE_DISPUTE = "escalateDispute(uint256)";
string constant RESOLVE_DISPUTE = "resolveDispute(uint256,uint256,bytes)";// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import { BosonTypes } from "./BosonTypes.sol";
interface BosonErrors {
// Pause related
// Trying to unpause a protocol when it's not paused
error NotPaused();
// Whenever a region is paused, and a method from that region is called
error RegionPaused(BosonTypes.PausableRegion region);
// General
// Input parameter of type address is zero address
error InvalidAddress();
// Exchange or dispute is in different state than expected when certain action is called
error InvalidState();
// Two or more array parameters with different lengths
error ArrayLengthMismatch();
// Array elements that are not in ascending order (i.e arr[i-1] > arr[i])
error NonAscendingOrder();
// Called contract returned an unexpected value
error UnexpectedDataReturned(bytes data);
// Reentrancy guard
// Reentrancy guard is active and second call to protocol is made
error ReentrancyGuard();
// Protocol initialization related
// Trying to initialize the facet when it's already initialized
error AlreadyInitialized(); // ToDo consider adding the facet to the error message
// Initialization of some facet failed
error ProtocolInitializationFailed(); // ToDo consider adding the facet to the error message
// Trying to initialize the protocol with empty version
error VersionMustBeSet();
// Length of _addresses and _calldata arrays do not match
error AddressesAndCalldataLengthMismatch(); // ToDo consider reusing ArrayLengthMismatch
// The new protocol version is not subsequent to the current one
error WrongCurrentVersion();
// Initialization can be done only through proxy
error DirectInitializationNotAllowed();
// Initialization of v2.3.0 can be done only if not twin exists
error TwinsAlreadyExist();
// Access related
// ToDo consider having a single error, with a parameter for the role
// Caller is not authorized to call the method
error AccessDenied();
// Caller is not entitiy's assistant
error NotAssistant();
// Caller is not entitiy's admin
error NotAdmin();
// Caller is not entitiy's admin and assistant
error NotAdminAndAssistant();
// Caller is neither the buyer or the seller involved in the exchange
error NotBuyerOrSeller();
// Caller is not the owner of the voucher
error NotVoucherHolder();
// Caller is not the buyer
error NotBuyerWallet();
// Caller is not the agent
error NotAgentWallet();
// Caller is not dispute resolver assistant
error NotDisputeResolverAssistant();
// Caller is not the creator of the offer
error NotOfferCreator();
// Supplied clerk is not zero address
error ClerkDeprecated();
// Account-related
// Entity must be active
error MustBeActive();
// Seller's address cannot be already used in another seller
error SellerAddressMustBeUnique();
// Buyer's address cannot be already used in another buyer
error BuyerAddressMustBeUnique();
// DR's address cannot be already used in another DR
error DisputeResolverAddressMustBeUnique();
// Agent's address cannot be already used in another agent
error AgentAddressMustBeUnique();
// Seller does not exist
error NoSuchSeller();
// Buyer does not exist
error NoSuchBuyer();
// Dispute resolver does not exist
error NoSuchDisputeResolver();
// Agent does not exist
error NoSuchAgent();
// Entity does not exist
error NoSuchEntity();
// Buyer is involved in an non-finalized exchange
error WalletOwnsVouchers();
// Escalation period is not greater than zero or is more than the max allowed
error InvalidEscalationPeriod();
// Action would remove the last supported fee from the DR (must always have at least one)
error InexistentDisputeResolverFees();
// Trying to add a fee that already exists
error DuplicateDisputeResolverFees();
// Trying to remove a fee that does not exist
error DisputeResolverFeeNotFound();
// Trying to approve a seller that is already approved (list of sellers that DR will handle disputes for)
error SellerAlreadyApproved();
// Trying to assing a DR that had not approved the seller
error SellerNotApproved();
// Trying to add or removed 0 sellers
error InexistentAllowedSellersList();
// Custom auth token is not yet supported
error InvalidAuthTokenType();
// Seller must use either and address or auth token for authentication, but not both
error AdminOrAuthToken();
// A single auth token can only be used by one seller
error AuthTokenMustBeUnique();
// Sum of protocol and agent fee exceed the max allowed fee
error InvalidAgentFeePercentage();
// Trying to finalize the update, while it's not even started
error NoPendingUpdateForAccount();
// Only the account itself can finalize the update
error UnauthorizedCallerUpdate();
// Trying to update the account with the same values
error NoUpdateApplied();
// Creating a seller's collection failed
error CloneCreationFailed();
// Seller's salt is already used by another seller
error SellerSaltNotUnique();
// Offer related
// Offer does not exist
error NoSuchOffer();
// Offer parameters are invalid
error InvalidOffer();
// Collection index is invalid for the context
error InvalidCollectionIndex();
// Offer finishes in the past or it starts after it finishes
error InvalidOfferPeriod();
// Buyer cancellation penalty is higher than the item price
error InvalidOfferPenalty();
// New offer must be actiove
error OfferMustBeActive();
// Offer can be added to same group only once
error OfferMustBeUnique();
// Offer has been voided
error OfferHasBeenVoided();
// Current timestamp is higher than offer's expiry timestamp
error OfferHasExpired();
// Current timestamp is lower than offer's start timestamp
error OfferNotAvailable();
// Offer's quantity available is zero
error OfferSoldOut();
// Buyer is not allowed to commit to the offer (does not meet the token gating requirements)
error CannotCommit();
// Bundle cannot be created since exchganes for offer exist already
error ExchangeForOfferExists();
// Buyer-initiated offer cannot have seller-specific fields (sellerId, collectionIndex, royaltyInfo)
error InvalidBuyerOfferFields();
// Seller-initiated offer cannot have buyer-specific fields (buyerId, quantityAvailable)
error InvalidSellerOfferFields();
// Buyer cannot provide seller parameters when committing to an offer
error SellerParametersNotAllowed();
// Invalid offer creator value specified
error InvalidOfferCreator();
// Voucher must have either a fixed expiry or a fixed redeemable period, not both
error AmbiguousVoucherExpiry();
// Redemption period starts after it ends or it ends before offer itself expires
error InvalidRedemptionPeriod();
// Dispute period is less than minimal dispute period allowed
error InvalidDisputePeriod();
// Resolution period is not within the allowed range or it's being misconfigured (minimal > maximal)
error InvalidResolutionPeriod();
// Dispute resolver does not exist or is not active
error InvalidDisputeResolver();
// Quantity available is zero
error InvalidQuantityAvailable();
// Chose DR does not support the fees in the chosen exchange token
error DRUnsupportedFee();
// Sum of protocol and agent fee exceeds the max allowed fee
error AgentFeeAmountTooHigh();
// Sum of protocol and agent fee exceeds the seller defined max fee
error TotalFeeExceedsLimit();
// Collection does not exist
error NoSuchCollection();
// Royalty recipient is not allow listed for the seller
error InvalidRoyaltyRecipient();
// Total royality fee exceeds the max allowed
error InvalidRoyaltyPercentage();
// Specified royalty recipient already added
error RecipientNotUnique();
// Trying to access an out of bounds royalty recipient
error InvalidRoyaltyRecipientId();
// Array of royalty recipients is not sorted by id
error RoyaltyRecipientIdsNotSorted();
// Trying to remove the default recipient (treasury)
error CannotRemoveDefaultRecipient();
// Supplying too many Royalty info structs
error InvalidRoyaltyInfo();
// Trying to change the default recipient address (treasury)
error WrongDefaultRecipient();
// Price discovery offer has non zero price
error InvalidPriceDiscoveryPrice();
// Trying to set the same mutualizer as the existing one
error SameMutualizerAddress();
// Group related
// Group does not exist
error NoSuchGroup();
// Offer is not in a group
error OfferNotInGroup();
// Group remains the same
error NothingUpdated();
// There is a logical error in the group's condition parameters or it's not supported yet
error InvalidConditionParameters();
// Group does not have a condition
error GroupHasNoCondition();
// Group has a condition
error GroupHasCondition();
// User exhaused the number of commits allowed for the group
error MaxCommitsReached();
// The supplied token id is outside the condition's range
error TokenIdNotInConditionRange();
// ERC20 and ERC721 require zero token id
error InvalidTokenId();
// Exchange related
// Exchange does not exist
error NoSuchExchange();
// Exchange cannot be completed yet
error DisputePeriodNotElapsed();
// Current timestamp is outside the voucher's redeemable period
error VoucherNotRedeemable();
// New expiration date is earlier than existing expiration date
error VoucherExtensionNotValid();
// Voucher cannot be expired yet
error VoucherStillValid();
// Voucher has expired and cannot be transferred anymore
error VoucherHasExpired();
// Exchange has not been finalized yet
error ExchangeIsNotInAFinalState();
// Exchange with the same id already exists
error ExchangeAlreadyExists();
// Range length is 0, is more than quantity available or it would cause an overflow
error InvalidRangeLength();
// Exchange is being finalized into an invalid state
error InvalidTargeExchangeState();
// Twin related
// Twin does not exist
error NoSuchTwin();
// Seller did not approve the twin transfer
error NoTransferApproved();
// Twin transfer failed
error TwinTransferUnsuccessful();
// Token address is 0 or it does not implement the required interface
error UnsupportedToken();
// Twin cannot be removed if it's in a bundle
error BundleForTwinExists();
// Supply available is zero
error InvalidSupplyAvailable();
// Twin is Fungible or Multitoken and amount was set
error InvalidAmount();
// Twin is NonFungible and amount was not set
error InvalidTwinProperty(); // ToDo consider replacing with InvalidAmount
// Token range overlap with another, starting token id is too high or end of range would overflow
error InvalidTwinTokenRange();
// Token does not support IERC721 interface
error InvalidTokenAddress();
// Bundle related
// Bundle does not exist
error NoSuchBundle();
// Twin is not in a bundle
error TwinNotInBundle();
// Offer is not in a bundle
error OfferNotInBundle();
// Offer can appear in a bundle only once
error BundleOfferMustBeUnique();
// Twin can appear in a bundle only once
error BundleTwinMustBeUnique();
// Twin supply does not covver all offers in the bundle
error InsufficientTwinSupplyToCoverBundleOffers();
// Bundle cannot be created without an offer or a twin
error BundleRequiresAtLeastOneTwinAndOneOffer();
// Funds related
// Native token must be represented with zero address
error NativeWrongAddress();
// Amount sent along (msg.value) does not match the expected amount
error NativeWrongAmount();
// Token list lenght does not match the amount list length
error TokenAmountMismatch(); // ToDo consider replacing with ArrayLengthMismatch
// Token list is empty
error NothingToWithdraw();
// Call is not allowed to transfer the funds
error NotAuthorized();
// Token transfer failed
error TokenTransferFailed();
// Received amount does not match the expected amount
error InsufficientValueReceived();
// Seller's pool does not have enough funds to encumber
error InsufficientAvailableFunds();
// Native token was sent when ERC20 was expected
error NativeNotAllowed();
// Trying to deposit zero amount
error ZeroDepositNotAllowed();
// DR Fee related
// DR fee mutualizer cannot provide coverage for the fee
error DRFeeMutualizerCannotProvideCoverage();
// Meta-Transactions related
// Meta-transaction nonce is invalid
error NonceUsedAlready();
// Function signature does not match it's name
error InvalidFunctionName();
// Signature has invalid parameters
error InvalidSignature();
// Function is not allowed to be executed as a meta-transaction
error FunctionNotAllowlisted();
// Signer does not match the expected one or ERC1271 signature is not valid
error SignatureValidationFailed();
// Dispute related
// Dispute cannot be raised since the period to do it has elapsed
error DisputePeriodHasElapsed();
// Mutualizer address does not implement the required interface
error UnsupportedMutualizer();
// Dispute cannot be resolved anymore and must be finalized with expireDispute
error DisputeHasExpired();
// Buyer gets more than 100% of the total pot
error InvalidBuyerPercent();
// Dispute is still valid and cannot be expired yet
error DisputeStillValid();
// New dispute timeout is earlier than existing dispute timeout
error InvalidDisputeTimeout();
// Absolute zero offers cannot be escalated
error EscalationNotAllowed();
// Dispute is being finalized into an invalid state
error InvalidTargeDisputeState();
// Config related
// Percentage exceeds 100%
error InvalidFeePercentage();
// Zero config value is not allowed
error ValueZeroNotAllowed();
// BosonVoucher
// Trying to issue an voucher that is in a reseverd range
error ExchangeIdInReservedRange();
// Trying to premint vouchers for an offer that does not have a reserved range
error NoReservedRangeForOffer();
// Trying to reserve a range that is already reserved
error OfferRangeAlreadyReserved();
// Range start at 0 is not allowed
error InvalidRangeStart();
// Amount to premint exceeds the range length
error InvalidAmountToMint();
// Trying to silent mint vouchers not belonging to the range owner
error NoSilentMintAllowed();
// Trying to premint the voucher of already expired offer
error OfferExpiredOrVoided();
// Trying to burn preminted vouchers of still valid offer
error OfferStillValid();
// Trying to burn more vouchers than available
error AmountExceedsRangeOrNothingToBurn();
// Royalty fee exceeds the max allowed
error InvalidRoyaltyFee();
// Trying to assign the premined vouchers to the address that is neither the contract owner nor the contract itself
error InvalidToAddress();
// Call to an external contract was not successful
error ExternalCallFailed();
// Trying to interact with external contract in a way that could result in transferring assets from the contract
error InteractionNotAllowed();
// Price discovery related
// Price discovery returned a price that does not match the expected one
error PriceMismatch();
// Token id is mandatory for bid orders and wrappers
error TokenIdMandatory();
// Incoming token id does not match the expected one
error TokenIdMismatch();
// Using price discovery for non-price discovery offer or using ordinary commit for price discovery offer
error InvalidPriceType();
// Missing price discovery contract address or data
error InvalidPriceDiscovery();
// Trying to set incoming voucher when it's already set, indicating reentrancy
error IncomingVoucherAlreadySet();
// Conduit address must be zero ()
error InvalidConduitAddress();
// Protocol does not know what token id to use
error TokenIdNotSet();
// Transferring a preminted voucher to wrong recipient
error VoucherTransferNotAllowed();
// Price discovery contract returned a negative price
error NegativePriceNotAllowed();
// Price discovery did not send the voucher to the protocol
error VoucherNotReceived();
// Price discovery did not send the voucher from the protocol
error VoucherNotTransferred();
// Either token with wrong id received or wrong voucher contract made the transfer
error UnexpectedERC721Received();
// Royalty fee exceeds the price
error FeeAmountTooHigh();
// Price does not cover the cancellation penalty
error PriceDoesNotCoverPenalty();
// Fee Table related
// Thrown if asset is not supported in feeTable feature.
error FeeTableAssetNotSupported();
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
/**
* @title BosonTypes
*
* @notice Enums and structs used by the Boson Protocol contract ecosystem.
*/
contract BosonTypes {
enum PausableRegion {
Offers,
Twins,
Bundles,
Groups,
Sellers,
Buyers,
DisputeResolvers,
Agents,
Exchanges,
Disputes,
Funds,
Orchestration,
MetaTransaction,
PriceDiscovery,
SequentialCommit
}
enum EvaluationMethod {
None, // None should always be at index 0. Never change this value.
Threshold,
SpecificToken
}
enum GatingType {
PerAddress,
PerTokenId
}
enum ExchangeState {
Committed,
Revoked,
Canceled,
Redeemed,
Completed,
Disputed
}
enum DisputeState {
Resolving,
Retracted,
Resolved,
Escalated,
Decided,
Refused
}
enum TokenType {
FungibleToken,
NonFungibleToken,
MultiToken
} // ERC20, ERC721, ERC1155
enum MetaTxInputType {
Generic,
CommitToOffer,
Exchange,
Funds,
CommitToConditionalOffer,
ResolveDispute
}
enum AuthTokenType {
None,
Custom, // For future use
Lens,
ENS
}
enum SellerUpdateFields {
Admin,
Assistant,
Clerk, // Deprecated.
AuthToken
}
enum DisputeResolverUpdateFields {
Admin,
Assistant,
Clerk // Deprecated.
}
enum PriceType {
Static, // Default should always be at index 0. Never change this value.
Discovery
}
enum OfferCreator {
Seller, // Default should always be at index 0. Never change this value.
Buyer
}
struct AuthToken {
uint256 tokenId;
AuthTokenType tokenType;
}
struct Seller {
uint256 id;
address assistant;
address admin;
address clerk; // Deprecated. Kept for backwards compatibility.
address payable treasury;
bool active;
string metadataUri;
}
struct Buyer {
uint256 id;
address payable wallet;
bool active;
}
struct RoyaltyRecipient {
uint256 id;
address payable wallet;
}
struct DisputeResolver {
uint256 id;
uint256 escalationResponsePeriod;
address assistant;
address admin;
address clerk; // Deprecated. Kept for backwards compatibility.
address payable treasury;
string metadataUri;
bool active;
}
struct DisputeResolverFee {
address tokenAddress;
string tokenName;
uint256 feeAmount;
}
struct Agent {
uint256 id;
uint256 feePercentage;
address payable wallet;
bool active;
}
struct DisputeResolutionTerms {
uint256 disputeResolverId;
uint256 escalationResponsePeriod;
uint256 feeAmount;
uint256 buyerEscalationDeposit;
address payable mutualizerAddress; // Address of the DR fee mutualizer
}
struct Offer {
uint256 id;
uint256 sellerId;
uint256 price;
uint256 sellerDeposit;
uint256 buyerCancelPenalty;
uint256 quantityAvailable;
address exchangeToken;
PriceType priceType;
OfferCreator creator;
string metadataUri;
string metadataHash;
bool voided;
uint256 collectionIndex;
RoyaltyInfo[] royaltyInfo;
uint256 buyerId; // For buyer-created offers, stores the buyer who created the offer
}
struct DRParameters {
uint256 disputeResolverId;
address payable mutualizerAddress;
}
struct OfferDates {
uint256 validFrom;
uint256 validUntil;
uint256 voucherRedeemableFrom;
uint256 voucherRedeemableUntil;
}
struct OfferDurations {
uint256 disputePeriod;
uint256 voucherValid;
uint256 resolutionPeriod;
}
struct FullOffer {
Offer offer;
OfferDates offerDates;
OfferDurations offerDurations;
DRParameters drParameters;
Condition condition;
uint256 agentId;
uint256 feeLimit;
bool useDepositedFunds;
}
struct Group {
uint256 id;
uint256 sellerId;
uint256[] offerIds;
}
struct Condition {
EvaluationMethod method;
TokenType tokenType;
address tokenAddress;
GatingType gating; // added in v2.3.0. All conditions created before that have a default value of "PerAddress"
uint256 minTokenId;
uint256 threshold;
uint256 maxCommits;
uint256 maxTokenId;
}
struct Exchange {
uint256 id;
uint256 offerId;
uint256 buyerId;
uint256 finalizedDate;
ExchangeState state;
address payable mutualizerAddress;
}
struct ExchangeCosts {
uint256 resellerId;
uint256 price;
uint256 protocolFeeAmount;
uint256 royaltyAmount;
uint256 royaltyInfoIndex;
}
struct Voucher {
uint256 committedDate;
uint256 validUntilDate;
uint256 redeemedDate;
bool expired;
}
struct Dispute {
uint256 exchangeId;
uint256 buyerPercent;
DisputeState state;
}
struct DisputeDates {
uint256 disputed;
uint256 escalated;
uint256 finalized;
uint256 timeout;
}
struct Receipt {
uint256 exchangeId;
uint256 offerId;
uint256 buyerId;
uint256 sellerId;
uint256 price;
uint256 sellerDeposit;
uint256 buyerCancelPenalty;
OfferFees offerFees;
uint256 agentId;
address exchangeToken;
uint256 finalizedDate;
Condition condition;
uint256 committedDate;
uint256 redeemedDate;
bool voucherExpired;
uint256 disputeResolverId;
uint256 disputedDate;
uint256 escalatedDate;
DisputeState disputeState;
TwinReceipt[] twinReceipts;
}
struct TokenRange {
uint256 start;
uint256 end;
uint256 twinId;
}
struct Twin {
uint256 id;
uint256 sellerId;
uint256 amount; // ERC1155 / ERC20 (amount to be transferred to each buyer on redemption)
uint256 supplyAvailable; // all
uint256 tokenId; // ERC1155 / ERC721 (must be initialized with the initial pointer position of the ERC721 ids available range)
address tokenAddress; // all
TokenType tokenType;
}
struct TwinReceipt {
uint256 twinId;
uint256 tokenId; // only for ERC721 and ERC1155
uint256 amount; // only for ERC1155 and ERC20
address tokenAddress;
TokenType tokenType;
}
struct Bundle {
uint256 id;
uint256 sellerId;
uint256[] offerIds;
uint256[] twinIds;
}
struct Funds {
address tokenAddress;
string tokenName;
uint256 availableAmount;
}
struct MetaTransaction {
uint256 nonce;
address from;
address contractAddress;
string functionName;
bytes functionSignature;
}
struct HashInfo {
bytes32 typeHash;
function(bytes memory) internal pure returns (bytes32) hashFunction;
}
struct OfferFees {
uint256 protocolFee;
uint256 agentFee;
}
struct VoucherInitValues {
string contractURI;
uint256 royaltyPercentage;
bytes32 collectionSalt;
}
struct Collection {
address collectionAddress;
string externalId;
}
struct PriceDiscovery {
uint256 price;
Side side;
address priceDiscoveryContract;
address conduit;
bytes priceDiscoveryData;
}
enum Side {
Ask,
Bid,
Wrapper // Side is not relevant from the protocol perspective
}
struct RoyaltyInfo {
address payable[] recipients;
uint256[] bps;
}
struct RoyaltyRecipientInfo {
address payable wallet;
uint256 minRoyaltyPercentage;
}
struct PremintParameters {
uint256 reservedRangeLength;
address to;
}
struct Payoff {
uint256 seller;
uint256 buyer;
uint256 protocol;
uint256 agent;
uint256 disputeResolver;
uint256 mutualizer;
}
struct SellerOfferParams {
uint256 collectionIndex;
RoyaltyInfo royaltyInfo;
address payable mutualizerAddress;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import { IAccessControl } from "../IAccessControl.sol";
import { IClientExternalAddressesEvents } from "../events/IClientExternalAddressesEvents.sol";
/**
* @title IClientExternalAddresses
*
* @notice ClientExternalAddresses is used to set and get addresses used either by proxies or
* by protocol clients.
*
*
* The ERC-165 identifier for this interface is: 0x344552b3
*/
interface IClientExternalAddresses is IClientExternalAddressesEvents {
/**
* @notice Sets the implementation address.
*
* @param _implementation - the implementation address
*/
function setImplementation(address _implementation) external;
/**
* @notice Gets the implementation address.
*
* @return the implementation address
*/
function getImplementation() external view returns (address);
/**
* @notice Gets the address of the Boson Protocol AccessController contract.
*
* @return the address of the AccessController contract
*/
function getAccessController() external view returns (IAccessControl);
/**
* @notice Set the ProtocolDiamond address.
*
* Emits a ProtocolAddressChanged event.
*
* @param _protocolAddress - the ProtocolDiamond address
*/
function setProtocolAddress(address _protocolAddress) external;
/**
* @notice Gets the address of the ProtocolDiamond contract.
*
* @return the ProtocolDiamond address
*/
function getProtocolAddress() external view returns (address);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import { IERC165 } from "../IERC165.sol";
/**
* @title IDRFeeMutualizer
* @notice Interface for dispute resolver fee mutualization
*
* The ERC-165 identifier for this interface is: 0xe627eff4
*/
interface IDRFeeMutualizer is IERC165 {
/**
* @notice Checks if a seller is covered for a specific DR fee
* @param _sellerId The seller ID
* @param _feeAmount The fee amount to cover
* @param _tokenAddress The token address (address(0) for native currency)
* @param _disputeResolverId The dispute resolver ID (0 for universal agreement covering all dispute resolvers)
* @return bool True if the seller is covered, false otherwise
* @dev Checks for both specific dispute resolver agreements and universal agreements (disputeResolverId = 0).
*/
function isSellerCovered(
uint256 _sellerId,
uint256 _feeAmount,
address _tokenAddress,
uint256 _disputeResolverId
) external view returns (bool);
/**
* @notice Requests a DR fee for a seller
* @param _sellerId The seller ID
* @param _feeAmount The fee amount to cover
* @param _tokenAddress The token address (address(0) for native currency)
* @param _exchangeId The exchange ID
* @param _disputeResolverId The dispute resolver ID (0 for universal agreement)
* @return success True if the request was successful, false otherwise
* @dev Only callable by the Boson protocol. Returns false if seller is not covered.
*
* Emits a {DRFeeProvided} event if successful.
*
* Reverts if:
* - Caller is not the Boson protocol
* - feeAmount is 0
* - Pool balance is insufficient
* - ERC20 or native currency transfer fails
*/
function requestDRFee(
uint256 _sellerId,
uint256 _feeAmount,
address _tokenAddress,
uint256 _exchangeId,
uint256 _disputeResolverId
) external returns (bool success);
/**
* @notice Notifies the mutualizer that the exchange has been finalized and any unused fee can be returned
* @param _exchangeId The exchange ID
* @param _feeAmount The amount being returned (0 means protocol kept all fees)
* @dev Only callable by the Boson protocol. For native currency, token is wrapped and must be transferred as ERC20.
*
* Emits a {DRFeeReturned} event.
*
* Reverts if:
* - Caller is not the Boson protocol
* - exchangeId is not found
* - token transfer fails
*/
function finalizeExchange(uint256 _exchangeId, uint256 _feeAmount) external;
}// SPDX-License-Identifier: MIT pragma solidity 0.8.22; /** * @title IDiamondCut * * @notice Manages Diamond Facets. * * Reference Implementation : https://github.com/mudgen/diamond-2-hardhat * EIP-2535 Diamond Standard : https://eips.ethereum.org/EIPS/eip-2535 * * The ERC-165 identifier for this interface is: 0x1f931c1c * * @author Nick Mudge <[email protected]> (https://twitter.com/mudgen) */ interface IDiamondCut { event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); enum FacetCutAction { Add, Replace, Remove } struct FacetCut { address facetAddress; FacetCutAction action; bytes4[] functionSelectors; } /** * @notice Cuts facets of the Diamond. * * Adds/replaces/removes any number of function selectors. * * If populated, _calldata is executed with delegatecall on _init * * Reverts if caller does not have UPGRADER role * * @param _facetCuts - contains the facet addresses and function selectors * @param _init - the address of the contract or facet to execute _calldata * @param _calldata - a function call, including function selector and arguments */ function diamondCut(FacetCut[] calldata _facetCuts, address _init, bytes calldata _calldata) external; }
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import { BosonTypes } from "../../domain/BosonTypes.sol";
/**
* @title IBosonConfigEvents
*
* @notice Defines events related to management of configuration within the protocol.
*/
interface IBosonConfigEvents {
event TokenAddressChanged(address indexed tokenAddress, address indexed executedBy);
event TreasuryAddressChanged(address indexed treasuryAddress, address indexed executedBy);
event VoucherBeaconAddressChanged(address indexed voucherBeaconAddress, address indexed executedBy);
event BeaconProxyAddressChanged(address indexed beaconProxyAddress, address indexed executedBy);
event PriceDiscoveryAddressChanged(address indexed priceDiscoveryAddress, address indexed executedBy);
event ProtocolFeePercentageChanged(uint256 feePercentage, address indexed executedBy);
event ProtocolFeeFlatBosonChanged(uint256 feeFlatBoson, address indexed executedBy);
event MaxEscalationResponsePeriodChanged(uint256 maxEscalationResponsePeriod, address indexed executedBy);
event BuyerEscalationFeePercentageChanged(uint256 buyerEscalationFeePercentage, address indexed executedBy);
event AuthTokenContractChanged(
BosonTypes.AuthTokenType indexed authTokenType,
address indexed authTokenContract,
address indexed executedBy
);
event MaxTotalOfferFeePercentageChanged(uint16 maxTotalOfferFeePercentage, address indexed executedBy);
event MaxRoyaltyPercentageChanged(uint16 maxRoyaltyPercentage, address indexed executedBy);
event MinResolutionPeriodChanged(uint256 minResolutionPeriod, address indexed executedBy);
event MaxResolutionPeriodChanged(uint256 maxResolutionPeriod, address indexed executedBy);
event MinDisputePeriodChanged(uint256 minDisputePeriod, address indexed executedBy);
event MaxPremintedVouchersChanged(uint256 maxPremintedVouchers, address indexed executedBy);
event AccessControllerAddressChanged(address indexed accessControllerAddress, address indexed executedBy);
event FeeTableUpdated(
address indexed token,
uint256[] priceRanges,
uint256[] feePercentages,
address indexed executedBy
);
event MutualizerGasStipendChanged(uint256 mutualizerGasStipend, address indexed executedBy);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
/**
* @title IBosonFundsBaseEvents
*
* @notice Defines events related to management of funds within the protocol.
*/
interface IBosonFundsBaseEvents {
event FundsDeposited(
uint256 indexed entityId,
address indexed executedBy,
address indexed tokenAddress,
uint256 amount
);
event FundsEncumbered(
uint256 indexed entityId,
address indexed exchangeToken,
uint256 amount,
address indexed executedBy
);
event FundsReleased(
uint256 indexed exchangeId,
uint256 indexed entityId,
address indexed exchangeToken,
uint256 amount,
address executedBy
);
event ProtocolFeeCollected(
uint256 indexed exchangeId,
address indexed exchangeToken,
uint256 amount,
address indexed executedBy
);
event FundsWithdrawn(
uint256 indexed sellerId,
address indexed withdrawnTo,
address indexed tokenAddress,
uint256 amount,
address executedBy
);
event DRFeeRequested(
uint256 indexed exchangeId,
address indexed tokenAddress,
uint256 feeAmount,
address indexed mutualizerAddress,
address executedBy
);
event DRFeeReturned(
uint256 indexed exchangeId,
address indexed tokenAddress,
uint256 returnAmount,
address indexed mutualizerAddress,
address executedBy
);
event DRFeeReturnFailed(
uint256 indexed exchangeId,
address indexed tokenAddress,
uint256 returnAmount,
address indexed mutualizerAddress,
address executedBy
);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
/**
* @title IClientExternalAddressesEvents
*
* @notice Defines events related to management of Boson Protocol clients.
*/
interface IClientExternalAddressesEvents {
event Upgraded(address indexed implementation, address indexed executedBy);
event ProtocolAddressChanged(address indexed protocol, address indexed executedBy);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import { BosonTypes } from "../../domain/BosonTypes.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { IBosonConfigEvents } from "../events/IBosonConfigEvents.sol";
/**
* @title IBosonConfigHandler
*
* @notice Handles management of configuration within the protocol.
*
* The ERC-165 identifier for this interface is: 0x1442a8b7
*/
interface IBosonConfigHandler is IBosonConfigEvents, BosonErrors {
/**
* @notice Sets the Boson Token (ERC-20 contract) address.
*
* Emits a TokenAddressChanged event.
*
* Reverts if _tokenAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _tokenAddress - the Boson Token (ERC-20 contract) address
*/
function setTokenAddress(address payable _tokenAddress) external;
/**
* @notice Gets the Boson Token (ERC-20 contract) address.
*
* @return the Boson Token (ERC-20 contract) address
*/
function getTokenAddress() external view returns (address payable);
/**
* @notice Sets the Boson Protocol multi-sig wallet address.
*
* Emits a TreasuryAddressChanged event.
*
* Reverts if _treasuryAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _treasuryAddress - the the multi-sig wallet address
*/
function setTreasuryAddress(address payable _treasuryAddress) external;
/**
* @notice Gets the Boson Protocol multi-sig wallet address.
*
* @return the Boson Protocol multi-sig wallet address
*/
function getTreasuryAddress() external view returns (address payable);
/**
* @notice Sets the Boson Voucher beacon contract address.
*
* Emits a VoucherBeaconAddressChanged event.
*
* Reverts if _voucherBeaconAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _voucherBeaconAddress - the Boson Voucher beacon contract address
*/
function setVoucherBeaconAddress(address _voucherBeaconAddress) external;
/**
* @notice Gets the Boson Voucher beacon contract address.
*
* @return the Boson Voucher beacon contract address
*/
function getVoucherBeaconAddress() external view returns (address);
/**
* @notice Sets the Boson Voucher reference proxy implementation address.
*
* Emits a BeaconProxyAddressChanged event.
*
* Reverts if _beaconProxyAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _beaconProxyAddress - reference proxy implementation address
*/
function setBeaconProxyAddress(address _beaconProxyAddress) external;
/**
* @notice Gets the beaconProxy address.
*
* @return the beaconProxy address
*/
function getBeaconProxyAddress() external view returns (address);
/**
* @notice Sets the Boson Price Discovery contract address.
*
* Emits a PriceDiscoveryAddressChanged event if successful.
*
* Reverts if _priceDiscovery is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _priceDiscovery - the Boson Price Discovery contract address
*/
function setPriceDiscoveryAddress(address _priceDiscovery) external;
/**
* @notice Gets the Boson Price Discovery contract address.
*
* @return the Boson Price Discovery contract address
*/
function getPriceDiscoveryAddress() external view returns (address);
/**
* @notice Sets the protocol fee percentage.
*
* Emits a ProtocolFeePercentageChanged event.
*
* Reverts if the _protocolFeePercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _protocolFeePercentage - the percentage that will be taken as a fee from the net of a Boson Protocol sale or auction (after royalties)
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setProtocolFeePercentage(uint256 _protocolFeePercentage) external;
/**
* @notice Sets the feeTable for a specific token given price ranges and fee tiers for
* the corresponding price ranges.
*
* Reverts if the number of fee percentages does not match the number of price ranges.
* Reverts if the price ranges are not in ascending order
* Reverts if any of the fee percentages value is above 100%
*
* @dev Caller must have ADMIN role.
*
* @param _tokenAddress - the address of the token
* @param _priceRanges - array of token price ranges
* @param _feePercentages - array of fee percentages corresponding to each price range
*/
function setProtocolFeeTable(
address _tokenAddress,
uint256[] calldata _priceRanges,
uint256[] calldata _feePercentages
) external;
/**
* @notice Gets the current fee table for a given token.
*
* @param _tokenAddress - the address of the token
* @return priceRanges - array of token price ranges
* @return feePercentages - array of fee percentages corresponding to each price range
*/
function getProtocolFeeTable(
address _tokenAddress
) external view returns (uint256[] memory priceRanges, uint256[] memory feePercentages);
/**
* @notice Gets the default protocol fee percentage.
*
* @return the default protocol fee percentage
*/
function getProtocolFeePercentage() external view returns (uint256);
/**
* @notice Gets the protocol fee percentage based on protocol fee table
*
* @dev This function calculates the protocol fee percentage for specific token and price.
* If the token has a custom fee table configured, it returns the corresponding fee percentage
* for the price range. If the token does not have a custom fee table, it falls back
* to the default protocol fee percentage.
*
* Reverts if the exchange token is BOSON.
*
* @param _exchangeToken - The address of the token being used for the exchange.
* @param _price - The price of the item or service in the exchange.
*
* @return the protocol fee percentage for given price and exchange token
*/
function getProtocolFeePercentage(address _exchangeToken, uint256 _price) external view returns (uint256);
/**
* @notice Retrieves the protocol fee percentage for a given exchange token and price.
*
* @dev This function calculates the protocol fee based on the token and price.
* If the token has a custom fee table, it applies the corresponding fee percentage
* for the price range. If the token does not have a custom fee table, it falls back
* to the default protocol fee percentage. If the exchange token is $BOSON,
* this function returns the flatBoson fee
*
* @param _exchangeToken - The address of the token being used for the exchange.
* @param _price - The price of the item or service in the exchange.
*
* @return The protocol fee amount based on the token and the price.
*/
function getProtocolFee(address _exchangeToken, uint256 _price) external view returns (uint256);
/**
* @notice Sets the flat protocol fee for exchanges in $BOSON.
*
* Emits a ProtocolFeeFlatBosonChanged event.
*
* @dev Caller must have ADMIN role.
*
* @param _protocolFeeFlatBoson - the flat fee taken for exchanges in $BOSON
*
*/
function setProtocolFeeFlatBoson(uint256 _protocolFeeFlatBoson) external;
/**
* @notice Gets the flat protocol fee for exchanges in $BOSON.
*
* @return the flat fee taken for exchanges in $BOSON
*/
function getProtocolFeeFlatBoson() external view returns (uint256);
/**
* @notice Sets the maximum escalation response period a dispute resolver can specify.
*
* Emits a MaxEscalationResponsePeriodChanged event.
*
* Reverts if _maxEscalationResponsePeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _maxEscalationResponsePeriod - the maximum escalation response period that a {BosonTypes.DisputeResolver} can specify
*/
function setMaxEscalationResponsePeriod(uint256 _maxEscalationResponsePeriod) external;
/**
* @notice Gets the maximum escalation response period a dispute resolver can specify.
*
* @return the maximum escalation response period that a {BosonTypes.DisputeResolver} can specify
*/
function getMaxEscalationResponsePeriod() external view returns (uint256);
/**
* @notice Sets the total offer fee percentage limit which will validate the sum of (Protocol Fee percentage + Agent Fee percentage) of an offer fee.
*
* Emits a MaxTotalOfferFeePercentageChanged event.
*
* Reverts if the _maxTotalOfferFeePercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _maxTotalOfferFeePercentage - the maximum total offer fee percentage
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setMaxTotalOfferFeePercentage(uint16 _maxTotalOfferFeePercentage) external;
/**
* @notice Gets the total offer fee percentage limit which will validate the sum of (Protocol Fee percentage + Agent Fee percentage) of an offer fee.
*
* @return the maximum total offer fee percentage
*/
function getMaxTotalOfferFeePercentage() external view returns (uint16);
/**
* @notice Sets the buyer escalation fee percentage.
*
* Emits a BuyerEscalationFeePercentageChanged event.
*
* Reverts if the _buyerEscalationDepositPercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _buyerEscalationDepositPercentage - the percentage of the DR fee that will be charged to buyer if they want to escalate the dispute
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setBuyerEscalationDepositPercentage(uint256 _buyerEscalationDepositPercentage) external;
/**
* @notice Gets the buyer escalation fee percentage.
*
* @return the percentage of the DR fee that will be charged to buyer if they want to escalate the dispute
*/
function getBuyerEscalationDepositPercentage() external view returns (uint256);
/**
* @notice Sets the contract address for the given AuthTokenType.
*
* Emits an AuthTokenContractChanged event.
*
* Reverts if _authTokenType is None
* Reverts if _authTokenType is Custom
* Reverts if _authTokenContract is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _authTokenType - the auth token type, as an Enum value
* @param _authTokenContract the address of the auth token contract (e.g. Lens or ENS contract address)
*/
function setAuthTokenContract(BosonTypes.AuthTokenType _authTokenType, address _authTokenContract) external;
/**
* @notice Gets the contract address for the given AuthTokenType.
*
* @param _authTokenType - the auth token type, as an Enum value
* @return the address of the auth token contract (e.g. Lens or ENS contract address) for the given AuthTokenType
*/
function getAuthTokenContract(BosonTypes.AuthTokenType _authTokenType) external view returns (address);
/**
* @notice Sets the maximum royalty percentage that can be set by the seller.
*
* Emits a MaxRoyaltyPercentageChanged event.
*
* Reverts if:
* - The _maxRoyaltyPercentage is zero.
* - The _maxRoyaltyPercentage is greater than 10000.
*
* @dev Caller must have ADMIN role.
*
* @param _maxRoyaltyPercentage - the maximum royalty percentage
*
* N.B. Represent percentage value as an unsigned int by multiplying the percentage by 100:
* e.g, 1.75% = 175, 100% = 10000
*/
function setMaxRoyaltyPercentage(uint16 _maxRoyaltyPercentage) external;
/**
* @notice Gets the maximum royalty percentage that can be set by the seller.
*
* @return the maximum royalty percentage
*/
function getMaxRoyaltyPercentage() external view returns (uint16);
/**
* @notice Sets the minimum resolution period a seller can specify.
*
* Emits a MinResolutionPeriodChanged event.
*
* Reverts if _minResolutionPeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _minResolutionPeriod - the minimum resolution period that a {BosonTypes.Seller} can specify
*/
function setMinResolutionPeriod(uint256 _minResolutionPeriod) external;
/**
* @notice Gets the minimum resolution period a seller can specify.
*
* @return the minimum resolution period that a {BosonTypes.Seller} can specify
*/
function getMinResolutionPeriod() external view returns (uint256);
/**
* @notice Sets the maximum resolution period a seller can specify.
*
* Emits a MaxResolutionPeriodChanged event.
*
* Reverts if _maxResolutionPeriod is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _maxResolutionPeriod - the maximum resolution period that a {BosonTypes.Seller} can specify
*/
function setMaxResolutionPeriod(uint256 _maxResolutionPeriod) external;
/**
* @notice Gets the maximum resolution period a seller can specify.
*
* @return the maximum resolution period that a {BosonTypes.Seller} can specify
*/
function getMaxResolutionPeriod() external view returns (uint256);
/**
* @notice Sets the minimum dispute period a seller can specify.
*
* Emits a MinDisputePeriodChanged event.
*
* Reverts if _minDisputePeriod is zero.
*
* @param _minDisputePeriod - the minimum dispute period that a {BosonTypes.Seller} can specify
*/
function setMinDisputePeriod(uint256 _minDisputePeriod) external;
/**
* @notice Gets the minimum dispute period a seller can specify.
*/
function getMinDisputePeriod() external view returns (uint256);
/**
* @notice Sets the access controller address.
*
* Emits an AccessControllerAddressChanged event.
*
* Reverts if _accessControllerAddress is the zero address
*
* @dev Caller must have ADMIN role.
*
* @param _accessControllerAddress - access controller address
*/
function setAccessControllerAddress(address _accessControllerAddress) external;
/**
* @notice Gets the access controller address.
*
* @return the access controller address
*/
function getAccessControllerAddress() external view returns (address);
/**
* @notice Sets the gas stipend forwarded when calling IDRFeeMutualizer.finalizeExchange
*
* Emits a MutualizerGasStipendChanged event if successful.
*
* Reverts if the _mutualizerGasStipend is zero.
*
* @dev Caller must have ADMIN role.
*
* @param _mutualizerGasStipend - the gas stipend that is forwarded when calling IDRFeeMutualizer.finalizeExchange
*/
function setMutualizerGasStipend(uint256 _mutualizerGasStipend) external;
/**
* @notice Gets the gas stipend forwarded when calling IDRFeeMutualizer.finalizeExchange
*
* @return the gas stipend that is forwarded when calling IDRFeeMutualizer.finalizeExchange
*/
function getMutualizerGasStipend() external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity 0.8.22;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity 0.8.22;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
/**
* @title IWrappedNative
*
* @notice Provides the minimum interface for native token wrapper
*/
interface IWrappedNative {
function withdraw(uint256) external;
function deposit() external payable;
function transfer(address, uint256) external returns (bool);
function transferFrom(address, address, uint256) external returns (bool);
function approve(address, uint256) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import "../../domain/BosonConstants.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { BosonTypes } from "../../domain/BosonTypes.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IBosonFundsBaseEvents } from "../../interfaces/events/IBosonFundsEvents.sol";
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { IDRFeeMutualizer } from "../../interfaces/clients/IDRFeeMutualizer.sol";
import { Context } from "@openzeppelin/contracts/utils/Context.sol";
import { IWrappedNative } from "../../interfaces/IWrappedNative.sol";
/**
* @title FundsBase
*
* @dev
*/
abstract contract FundsBase is Context {
using SafeERC20 for IERC20;
IWrappedNative internal immutable wNative;
/**
* @notice Takes in the offer id and entity id and encumbers the appropriate funds during commitToOffer.
* For seller-created offers: encumbers seller's pre-deposited deposit and validates buyer's incoming payment.
* For buyer-created offers: encumbers buyer's pre-deposited payment and validates seller's incoming deposit.
* If offer is preminted, caller's funds are not encumbered, but the funds are covered from pre-deposited amounts.
*
* Emits FundsEncumbered event if successful.
*
* Reverts if:
* - Incoming payment is in native token and caller does not send enough
* - Incoming payment 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)
* - Entity has less pre-deposited funds available than required amount
* - Received ERC20 token amount differs from the expected value
*
* @param _offerId - id of the offer with the details
* @param _entityId - id of the committing entity (buyer for seller-created offers, seller for buyer-created offers)
* @param _incomingAmount - the amount being paid by the committing entity
* @param _isPreminted - flag indicating if the offer is preminted
* @param _priceType - price type, either static or discovery
*/
function encumberFunds(
uint256 _offerId,
uint256 _entityId,
uint256 _incomingAmount,
bool _isPreminted,
BosonTypes.PriceType _priceType
) internal {
// Load protocol entities storage
ProtocolLib.ProtocolEntities storage pe = ProtocolLib.protocolEntities();
// get message sender
address sender = _msgSender();
// fetch offer to get the exchange token, price and seller
// this will be called only from commitToOffer so we expect that exchange actually exist
BosonTypes.Offer storage offer = pe.offers[_offerId];
address exchangeToken = offer.exchangeToken;
if (!_isPreminted) {
validateIncomingPayment(exchangeToken, _incomingAmount);
emit IBosonFundsBaseEvents.FundsDeposited(_entityId, sender, exchangeToken, _incomingAmount);
emit IBosonFundsBaseEvents.FundsEncumbered(_entityId, exchangeToken, _incomingAmount, sender);
}
if (offer.creator == BosonTypes.OfferCreator.Buyer) {
decreaseAvailableFunds(offer.buyerId, exchangeToken, offer.price);
emit IBosonFundsBaseEvents.FundsEncumbered(offer.buyerId, exchangeToken, offer.price, sender);
} else {
uint256 sellerId = offer.sellerId;
bool isPriceDiscovery = _priceType == BosonTypes.PriceType.Discovery;
uint256 sellerFundsEncumbered = offer.sellerDeposit +
(_isPreminted && !isPriceDiscovery ? _incomingAmount : 0);
decreaseAvailableFunds(sellerId, exchangeToken, sellerFundsEncumbered);
emit IBosonFundsBaseEvents.FundsEncumbered(sellerId, exchangeToken, sellerFundsEncumbered, sender);
}
}
/**
* @notice Validates that incoming payments matches expectation. If token is a native currency, it makes sure
* msg.value is correct. If token is ERC20, it transfers the value from the sender to the protocol.
*
* Emits ERC20 Transfer event in call stack if successful.
*
* Reverts if:
* - 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
*
* @param _exchangeToken - address of the token (0x for native currency)
* @param _value - value expected to receive
*/
function validateIncomingPayment(address _exchangeToken, uint256 _value) internal {
if (_exchangeToken == address(0)) {
// if transfer is in the native currency, msg.value must match offer price
if (msg.value != _value) revert BosonErrors.InsufficientValueReceived();
} else {
// when price is in an erc20 token, transferring the native currency is not allowed
if (msg.value != 0) revert BosonErrors.NativeNotAllowed();
// if transfer is in ERC20 token, try to transfer the amount from buyer to the protocol
transferFundsIn(_exchangeToken, _value);
}
}
/**
* @notice Takes in the exchange id and releases the funds to buyer, seller and dispute resolver depending on the state of the exchange.
* It is called only from finalizeExchange and finalizeDispute.
*
* Emits FundsReleased and/or ProtocolFeeCollected event if payoffs are warranted and transaction is successful.
*
* @param _exchangeId - exchange id
*/
function releaseFunds(uint256 _exchangeId) internal {
// Load protocol entities storage
ProtocolLib.ProtocolEntities storage pe = ProtocolLib.protocolEntities();
// Get the exchange and its state
// Since this should be called only from certain functions from exchangeHandler and disputeHandler
// exchange must exist and be in a completed state, so that's not checked explicitly
BosonTypes.Exchange storage exchange = pe.exchanges[_exchangeId];
// Get offer from storage to get the details about sellerDeposit, price, sellerId, exchangeToken and buyerCancelPenalty
BosonTypes.Offer storage offer = pe.offers[exchange.offerId];
// calculate the payoffs depending on state exchange is in
BosonTypes.Payoff memory payoff;
BosonTypes.OfferFees storage offerFee = pe.offerFees[exchange.offerId];
uint256 offerPrice = offer.priceType == BosonTypes.PriceType.Discovery ? 0 : offer.price;
BosonTypes.ExchangeCosts[] storage exchangeCosts = pe.exchangeCosts[_exchangeId];
uint256 lastPrice = exchangeCosts.length == 0 ? offerPrice : exchangeCosts[exchangeCosts.length - 1].price;
{
// scope to avoid stack too deep errors
BosonTypes.ExchangeState exchangeState = exchange.state;
uint256 sellerDeposit = offer.sellerDeposit;
bool isEscalated = pe.disputeDates[_exchangeId].escalated != 0;
if (exchangeState == BosonTypes.ExchangeState.Completed) {
// COMPLETED
payoff.protocol = offerFee.protocolFee;
// buyerPayoff is 0
payoff.agent = offerFee.agentFee;
payoff.seller = offerPrice + sellerDeposit - payoff.protocol - payoff.agent;
} else if (exchangeState == BosonTypes.ExchangeState.Revoked) {
// REVOKED
// sellerPayoff is 0
payoff.buyer = lastPrice + sellerDeposit;
} else if (exchangeState == BosonTypes.ExchangeState.Canceled) {
// CANCELED
uint256 buyerCancelPenalty = offer.buyerCancelPenalty;
payoff.seller = sellerDeposit + buyerCancelPenalty;
payoff.buyer = lastPrice - buyerCancelPenalty;
} else if (exchangeState == BosonTypes.ExchangeState.Disputed) {
// DISPUTED
// determine if buyerEscalationDeposit was encumbered or not
// if dispute was escalated, disputeDates.escalated is populated
uint256 buyerEscalationDeposit = isEscalated
? pe.disputeResolutionTerms[exchange.offerId].buyerEscalationDeposit
: 0;
// get the information about the dispute, which must exist
BosonTypes.Dispute storage dispute = pe.disputes[_exchangeId];
BosonTypes.DisputeState disputeState = dispute.state;
if (disputeState == BosonTypes.DisputeState.Retracted) {
// RETRACTED - same as "COMPLETED"
payoff.protocol = offerFee.protocolFee;
payoff.agent = offerFee.agentFee;
// buyerPayoff is 0
payoff.seller =
offerPrice +
sellerDeposit -
payoff.protocol -
payoff.agent +
buyerEscalationDeposit;
// DR is paid if dispute was escalated
payoff.disputeResolver = isEscalated ? pe.disputeResolutionTerms[exchange.offerId].feeAmount : 0;
} else if (disputeState == BosonTypes.DisputeState.Refused) {
// REFUSED
payoff.seller = sellerDeposit;
payoff.buyer = lastPrice + buyerEscalationDeposit;
// DR is not paid when dispute is refused
} else {
// RESOLVED or DECIDED
uint256 commonPot = sellerDeposit + buyerEscalationDeposit;
payoff.buyer = applyPercent(commonPot, dispute.buyerPercent);
payoff.seller = commonPot - payoff.buyer;
payoff.buyer = payoff.buyer + applyPercent(lastPrice, dispute.buyerPercent);
payoff.seller = payoff.seller + offerPrice - applyPercent(offerPrice, dispute.buyerPercent);
// DR is always paid for escalated disputes (Decided or Resolved with escalation)
if (isEscalated) {
payoff.disputeResolver = pe.disputeResolutionTerms[exchange.offerId].feeAmount;
}
}
}
}
address exchangeToken = offer.exchangeToken;
// Original seller and last buyer are done
// Release funds to intermediate sellers (if they exist)
// and add the protocol fee to the total
{
(uint256 sequentialProtocolFee, uint256 sequentialRoyalties) = releaseFundsToIntermediateSellers(
_exchangeId,
exchange.state,
offerPrice,
exchangeToken,
offer
);
payoff.seller += sequentialRoyalties;
payoff.protocol += sequentialProtocolFee;
}
// Store payoffs to availablefunds and notify the external observers
address sender = _msgSender();
if (payoff.seller > 0) {
increaseAvailableFundsAndEmitEvent(_exchangeId, offer.sellerId, exchangeToken, payoff.seller, sender);
}
if (payoff.buyer > 0) {
increaseAvailableFundsAndEmitEvent(_exchangeId, exchange.buyerId, exchangeToken, payoff.buyer, sender);
}
if (payoff.protocol > 0) {
increaseAvailableFunds(PROTOCOL_ENTITY_ID, exchangeToken, payoff.protocol);
emit IBosonFundsBaseEvents.ProtocolFeeCollected(_exchangeId, exchangeToken, payoff.protocol, sender);
}
if (payoff.agent > 0) {
// Get the agent for offer
uint256 agentId = ProtocolLib.protocolLookups().agentIdByOffer[exchange.offerId];
increaseAvailableFundsAndEmitEvent(_exchangeId, agentId, exchangeToken, payoff.agent, sender);
}
BosonTypes.DisputeResolutionTerms memory drTerms = pe.disputeResolutionTerms[offer.id];
if (payoff.disputeResolver > 0) {
increaseAvailableFundsAndEmitEvent(
_exchangeId,
drTerms.disputeResolverId,
exchangeToken,
payoff.disputeResolver,
sender
);
}
// Return unused DR fee to mutualizer or seller's pool
if (drTerms.feeAmount != 0) {
payoff.mutualizer = drTerms.feeAmount - payoff.disputeResolver;
// Use exchange-level mutualizer address (locked at commitment time)
address mutualizerAddress = exchange.mutualizerAddress;
if (mutualizerAddress == address(0)) {
if (payoff.mutualizer > 0) {
increaseAvailableFundsAndEmitEvent(
_exchangeId,
offer.sellerId,
exchangeToken,
payoff.mutualizer,
sender
);
}
} else {
if (payoff.mutualizer > 0) {
if (exchangeToken == address(0)) {
exchangeToken = address(wNative);
wNative.deposit{ value: payoff.mutualizer }();
}
uint256 oldAllowance = IERC20(exchangeToken).allowance(address(this), mutualizerAddress);
IERC20(exchangeToken).forceApprove(mutualizerAddress, payoff.mutualizer + oldAllowance);
}
try
IDRFeeMutualizer(mutualizerAddress).finalizeExchange{
gas: ProtocolLib.protocolLimits().mutualizerGasStipend
}(_exchangeId, payoff.mutualizer)
{
emit IBosonFundsBaseEvents.DRFeeReturned(
_exchangeId,
exchangeToken,
payoff.mutualizer,
mutualizerAddress,
sender
);
} catch {
// Ignore failure to not block the main flow
emit IBosonFundsBaseEvents.DRFeeReturnFailed(
_exchangeId,
exchangeToken,
payoff.mutualizer,
mutualizerAddress,
sender
);
}
}
}
}
/**
* @notice Takes the exchange id and releases the funds to original seller if offer.priceType is Discovery
* and to all intermediate resellers in case of sequential commit, depending on the state of the exchange.
* It is called only from releaseFunds. Protocol fee and royalties are calculated and returned to releaseFunds, where they are added to the total.
*
* Emits FundsReleased events for non zero payoffs.
*
* @param _exchangeId - exchange id
* @param _exchangeState - state of the exchange
* @param _initialPrice - initial price of the offer
* @param _exchangeToken - address of the token used for the exchange
* @param _offer - offer struct
* @return protocolFee - protocol fee from secondary sales
* @return sellerRoyalties - royalties from secondary sales collected for the seller
*/
function releaseFundsToIntermediateSellers(
uint256 _exchangeId,
BosonTypes.ExchangeState _exchangeState,
uint256 _initialPrice,
address _exchangeToken,
BosonTypes.Offer storage _offer
) internal returns (uint256 protocolFee, uint256 sellerRoyalties) {
BosonTypes.ExchangeCosts[] storage exchangeCosts;
// calculate effective price multiplier
uint256 effectivePriceMultiplier;
{
ProtocolLib.ProtocolEntities storage pe = ProtocolLib.protocolEntities();
exchangeCosts = pe.exchangeCosts[_exchangeId];
// if price type was static and no sequential commit happened, just return
if (exchangeCosts.length == 0) {
return (0, 0);
}
{
if (_exchangeState == BosonTypes.ExchangeState.Completed) {
// COMPLETED, buyer pays full price
effectivePriceMultiplier = HUNDRED_PERCENT;
} else if (
_exchangeState == BosonTypes.ExchangeState.Revoked ||
_exchangeState == BosonTypes.ExchangeState.Canceled
) {
// REVOKED or CANCELED, buyer pays nothing (buyerCancelPenalty is not considered payment)
effectivePriceMultiplier = 0;
} else if (_exchangeState == BosonTypes.ExchangeState.Disputed) {
// DISPUTED
// get the information about the dispute, which must exist
BosonTypes.Dispute storage dispute = pe.disputes[_exchangeId];
BosonTypes.DisputeState disputeState = dispute.state;
if (disputeState == BosonTypes.DisputeState.Retracted) {
// RETRACTED - same as "COMPLETED"
effectivePriceMultiplier = HUNDRED_PERCENT;
} else if (disputeState == BosonTypes.DisputeState.Refused) {
// REFUSED, buyer pays nothing
effectivePriceMultiplier = 0;
} else {
// RESOLVED or DECIDED
effectivePriceMultiplier = HUNDRED_PERCENT - dispute.buyerPercent;
}
}
}
}
uint256 resellerBuyPrice = _initialPrice; // the price that reseller paid for the voucher
address msgSender = _msgSender();
uint256 len = exchangeCosts.length;
for (uint256 i = 0; i < len; ) {
// Since all elements of exchangeCosts[i] are used, it makes sense to copy them to memory
BosonTypes.ExchangeCosts memory secondaryCommit = exchangeCosts[i];
// amount to be released
uint256 currentResellerAmount;
// inside the scope to avoid stack too deep error
{
if (effectivePriceMultiplier > 0) {
protocolFee =
protocolFee +
applyPercent(secondaryCommit.protocolFeeAmount, effectivePriceMultiplier);
sellerRoyalties += distributeRoyalties(
_exchangeId,
_offer,
secondaryCommit,
effectivePriceMultiplier
);
}
// secondary price without protocol fee and royalties
uint256 reducedSecondaryPrice = secondaryCommit.price -
secondaryCommit.protocolFeeAmount -
secondaryCommit.royaltyAmount;
// Calculate amount to be released to the reseller:
// + part of the price that they paid (relevant for unhappy paths)
// + price of the voucher that they sold reduced for part that goes to next reseller, royalties and protocol fee
// - immediate payout that was released already during the sequential commit
currentResellerAmount =
applyPercent(resellerBuyPrice, (HUNDRED_PERCENT - effectivePriceMultiplier)) +
secondaryCommit.price -
applyPercent(secondaryCommit.price, (HUNDRED_PERCENT - effectivePriceMultiplier)) -
applyPercent(secondaryCommit.protocolFeeAmount, effectivePriceMultiplier) -
applyPercent(secondaryCommit.royaltyAmount, effectivePriceMultiplier) -
Math.min(resellerBuyPrice, reducedSecondaryPrice);
resellerBuyPrice = secondaryCommit.price;
}
if (currentResellerAmount > 0) {
increaseAvailableFundsAndEmitEvent(
_exchangeId,
secondaryCommit.resellerId,
_exchangeToken,
currentResellerAmount,
msgSender
);
}
unchecked {
i++;
}
}
}
/**
* @notice Forwards values to increaseAvailableFunds and emits notifies external listeners.
*
* Emits FundsReleased events
*
* @param _exchangeId - exchange id
* @param _entityId - id of the entity to which the funds are released
* @param _tokenAddress - address of the token used for the exchange
* @param _amount - amount of tokens to be released
* @param _sender - address of the sender that executed the transaction
*/
function increaseAvailableFundsAndEmitEvent(
uint256 _exchangeId,
uint256 _entityId,
address _tokenAddress,
uint256 _amount,
address _sender
) internal {
increaseAvailableFunds(_entityId, _tokenAddress, _amount);
emit IBosonFundsBaseEvents.FundsReleased(_exchangeId, _entityId, _tokenAddress, _amount, _sender);
}
/**
* @notice Tries to transfer tokens from the caller to the protocol.
*
* Emits ERC20 Transfer event in call stack if successful.
*
* Reverts if:
* - 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
*
* @param _tokenAddress - address of the token to be transferred
* @param _from - address to transfer funds from
* @param _amount - amount to be transferred
*/
function transferFundsIn(address _tokenAddress, address _from, uint256 _amount) internal {
if (_amount > 0) {
// protocol balance before the transfer
uint256 protocolTokenBalanceBefore = IERC20(_tokenAddress).balanceOf(address(this));
// transfer ERC20 tokens from the caller
IERC20(_tokenAddress).safeTransferFrom(_from, address(this), _amount);
// protocol balance after the transfer
uint256 protocolTokenBalanceAfter = IERC20(_tokenAddress).balanceOf(address(this));
// make sure that expected amount of tokens was transferred
if (protocolTokenBalanceAfter - protocolTokenBalanceBefore != _amount)
revert BosonErrors.InsufficientValueReceived();
}
}
/**
* @notice Same as transferFundsIn(address _tokenAddress, address _from, uint256 _amount),
* but _from is message sender
*
* @param _tokenAddress - address of the token to be transferred
* @param _amount - amount to be transferred
*/
function transferFundsIn(address _tokenAddress, uint256 _amount) internal {
transferFundsIn(_tokenAddress, _msgSender(), _amount);
}
/**
* @notice Tries to transfer native currency or tokens from the protocol to the recipient.
*
* Emits FundsWithdrawn event if successful.
* Emits ERC20 Transfer event in call stack if ERC20 token is withdrawn and transfer is successful.
*
* Reverts if:
* - Transfer of native currency is not successful (i.e. recipient is a contract which reverted)
* - Contract at token address does not support ERC20 function transfer
* - Available funds is less than amount to be decreased
*
* @param _entityId - id of entity for which funds should be decreased, or 0 for protocol
* @param _tokenAddress - address of the token to be transferred
* @param _to - address of the recipient
* @param _amount - amount to be transferred
*/
function transferFundsOut(uint256 _entityId, address _tokenAddress, address payable _to, uint256 _amount) internal {
// first decrease the amount to prevent the reentrancy attack
decreaseAvailableFunds(_entityId, _tokenAddress, _amount);
// try to transfer the funds
transferFundsOut(_tokenAddress, _to, _amount);
// notify the external observers
emit IBosonFundsBaseEvents.FundsWithdrawn(_entityId, _to, _tokenAddress, _amount, _msgSender());
}
/**
* @notice Tries to transfer native currency or tokens from the protocol to the recipient.
*
* Emits ERC20 Transfer event in call stack if ERC20 token is withdrawn and transfer is successful.
*
* Reverts if:
* - Transfer of native currency is not successful (i.e. recipient is a contract which reverted)
* - Contract at token address does not support ERC20 function transfer
* - Available funds is less than amount to be decreased
*
* @param _tokenAddress - address of the token to be transferred
* @param _to - address of the recipient
* @param _amount - amount to be transferred
*/
function transferFundsOut(address _tokenAddress, address payable _to, uint256 _amount) internal {
// try to transfer the funds
if (_tokenAddress == address(0)) {
// transfer native currency
(bool success, ) = _to.call{ value: _amount }("");
if (!success) revert BosonErrors.TokenTransferFailed();
} else {
// transfer ERC20 tokens
IERC20(_tokenAddress).safeTransfer(_to, _amount);
}
}
/**
* @notice Increases the amount, available to withdraw or use as a seller deposit.
*
* @param _entityId - id of entity for which funds should be increased, or 0 for protocol
* @param _tokenAddress - funds contract address or zero address for native currency
* @param _amount - amount to be credited
*/
function increaseAvailableFunds(uint256 _entityId, address _tokenAddress, uint256 _amount) internal {
ProtocolLib.ProtocolLookups storage pl = ProtocolLib.protocolLookups();
// if the current amount of token is 0, the token address must be added to the token list
mapping(address => uint256) storage availableFunds = pl.availableFunds[_entityId];
if (availableFunds[_tokenAddress] == 0) {
address[] storage tokenList = pl.tokenList[_entityId];
tokenList.push(_tokenAddress);
//Set index mapping. Should be index in tokenList array + 1
pl.tokenIndexByAccount[_entityId][_tokenAddress] = tokenList.length;
}
// update the available funds
availableFunds[_tokenAddress] += _amount;
}
/**
* @notice Decreases the amount available to withdraw or use as a seller deposit.
*
* Reverts if:
* - Available funds is less than amount to be decreased
*
* @param _entityId - id of entity for which funds should be decreased, or 0 for protocol
* @param _tokenAddress - funds contract address or zero address for native currency
* @param _amount - amount to be taken away
*/
function decreaseAvailableFunds(uint256 _entityId, address _tokenAddress, uint256 _amount) internal {
if (_amount > 0) {
ProtocolLib.ProtocolLookups storage pl = ProtocolLib.protocolLookups();
// get available funds from storage
mapping(address => uint256) storage availableFunds = pl.availableFunds[_entityId];
uint256 entityFunds = availableFunds[_tokenAddress];
// make sure that seller has enough funds in the pool and reduce the available funds
if (entityFunds < _amount) revert BosonErrors.InsufficientAvailableFunds();
// Use unchecked to optimize execution cost. The math is safe because of the require above.
unchecked {
availableFunds[_tokenAddress] = entityFunds - _amount;
}
// if available funds are totally emptied, the token address is removed from the seller's tokenList
if (entityFunds == _amount) {
// Get the index in the tokenList array, which is 1 less than the tokenIndexByAccount index
address[] storage tokenList = pl.tokenList[_entityId];
uint256 lastTokenIndex = tokenList.length - 1;
mapping(address => uint256) storage entityTokens = pl.tokenIndexByAccount[_entityId];
uint256 index = entityTokens[_tokenAddress] - 1;
// if target is last index then only pop and delete are needed
// otherwise, we overwrite the target with the last token first
if (index != lastTokenIndex) {
// Need to fill gap caused by delete if more than one element in storage array
address tokenToMove = tokenList[lastTokenIndex];
// Copy the last token in the array to this index to fill the gap
tokenList[index] = tokenToMove;
// Reset index mapping. Should be index in tokenList array + 1
entityTokens[tokenToMove] = index + 1;
}
// Delete last token address in the array, which was just moved to fill the gap
tokenList.pop();
// Delete from index mapping
delete entityTokens[_tokenAddress];
}
}
}
/**
* @notice Distributes the royalties to external recipients and seller's treasury.
*
* @param _offer - storage pointer to the offer
* @param _secondaryCommit - information about the secondary commit (royaltyInfoIndex, price, escrowedRoyaltyAmount)
* @param _effectivePriceMultiplier - multiplier for the price, depending on the state of the exchange
*/
function distributeRoyalties(
uint256 _exchangeId,
BosonTypes.Offer storage _offer,
BosonTypes.ExchangeCosts memory _secondaryCommit,
uint256 _effectivePriceMultiplier
) internal returns (uint256 sellerRoyalties) {
address sender = _msgSender();
address exchangeToken = _offer.exchangeToken;
BosonTypes.RoyaltyInfo storage _royaltyInfo = _offer.royaltyInfo[_secondaryCommit.royaltyInfoIndex];
uint256 len = _royaltyInfo.recipients.length;
uint256 totalAmount;
uint256 effectivePrice = applyPercent(_secondaryCommit.price, _effectivePriceMultiplier);
ProtocolLib.ProtocolLookups storage pl = ProtocolLib.protocolLookups();
for (uint256 i = 0; i < len; ) {
address payable recipient = _royaltyInfo.recipients[i];
uint256 amount = applyPercent(_royaltyInfo.bps[i], effectivePrice);
totalAmount += amount;
if (recipient == address(0)) {
// goes to seller's treasury
sellerRoyalties += amount;
} else {
// Make funds available to withdraw
if (amount > 0) {
increaseAvailableFundsAndEmitEvent(
_exchangeId,
pl.royaltyRecipientIdByWallet[recipient],
exchangeToken,
amount,
sender
);
}
}
unchecked {
i++;
}
}
// if there is a remainder due to rounding, it goes to the seller's treasury
sellerRoyalties =
sellerRoyalties +
applyPercent(_secondaryCommit.royaltyAmount, _effectivePriceMultiplier) -
totalAmount;
}
/**
* @notice Returns the balance of the protocol for the given token address
*
* @param _tokenAddress - the address of the token to check the balance for
* @return balance - the balance of the protocol for the given token address
*/
function getBalance(address _tokenAddress) internal view returns (uint256) {
return _tokenAddress == address(0) ? address(this).balance : IERC20(_tokenAddress).balanceOf(address(this));
}
/**
* @notice Calulates the percentage of the amount.
*
* @param _amount - amount to be used for the calculation
* @param _percent - percentage to be calculated, in basis points (1% = 100, 100% = 10000)
*/
function applyPercent(uint256 _amount, uint256 _percent) internal pure returns (uint256) {
if (_percent == HUNDRED_PERCENT) return _amount;
if (_percent == 0) return 0;
return (_amount * _percent) / HUNDRED_PERCENT;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import "./../../domain/BosonConstants.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { BosonTypes } from "../../domain/BosonTypes.sol";
/**
* @title PausableBase
*
* @notice Provides modifiers for regional pausing
*/
contract PausableBase is BosonTypes {
/**
* @notice Modifier that checks the Offers region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier offersNotPaused() {
revertIfPaused(PausableRegion.Offers);
_;
}
/**
* @notice Modifier that checks the Twins region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier twinsNotPaused() {
revertIfPaused(PausableRegion.Twins);
_;
}
/**
* @notice Modifier that checks the Bundles region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier bundlesNotPaused() {
revertIfPaused(PausableRegion.Bundles);
_;
}
/**
* @notice Modifier that checks the Groups region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier groupsNotPaused() {
revertIfPaused(PausableRegion.Groups);
_;
}
/**
* @notice Modifier that checks the Sellers region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier sellersNotPaused() {
revertIfPaused(PausableRegion.Sellers);
_;
}
/**
* @notice Modifier that checks the Buyers region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier buyersNotPaused() {
revertIfPaused(PausableRegion.Buyers);
_;
}
/**
* @notice Modifier that checks the Agents region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier agentsNotPaused() {
revertIfPaused(PausableRegion.Agents);
_;
}
/**
* @notice Modifier that checks the DisputeResolvers region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier disputeResolversNotPaused() {
revertIfPaused(PausableRegion.DisputeResolvers);
_;
}
/**
* @notice Modifier that checks the Exchanges region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier exchangesNotPaused() {
revertIfPaused(PausableRegion.Exchanges);
_;
}
/**
* @notice Modifier that checks the Disputes region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier disputesNotPaused() {
revertIfPaused(PausableRegion.Disputes);
_;
}
/**
* @notice Modifier that checks the Funds region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier fundsNotPaused() {
revertIfPaused(PausableRegion.Funds);
_;
}
/**
* @notice Modifier that checks the Orchestration region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier orchestrationNotPaused() {
revertIfPaused(PausableRegion.Orchestration);
_;
}
/**
* @notice Modifier that checks the MetaTransaction region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier metaTransactionsNotPaused() {
revertIfPaused(PausableRegion.MetaTransaction);
_;
}
/**
* @notice Modifier that checks the PriceDiscovery region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier priceDiscoveryNotPaused() {
revertIfPaused(PausableRegion.PriceDiscovery);
_;
}
/**
* @notice Modifier that checks the SequentialCommit region is not paused
*
* Reverts if region is paused
*
* See: {BosonTypes.PausableRegion}
*/
modifier sequentialCommitNotPaused() {
revertIfPaused(PausableRegion.SequentialCommit);
_;
}
/**
* @notice Checks if a region of the protocol is paused.
*
* Reverts if region is paused
*
* @param _region the region to check pause status for
*/
function revertIfPaused(PausableRegion _region) internal view {
// Region enum value must be used as the exponent in a power of 2
uint256 powerOfTwo = 1 << uint256(_region);
if ((ProtocolLib.protocolStatus().pauseScenario & powerOfTwo) == powerOfTwo)
revert BosonErrors.RegionPaused(_region);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.22;
import "../../domain/BosonConstants.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { DiamondLib } from "../../diamond/DiamondLib.sol";
import { BosonTypes } from "../../domain/BosonTypes.sol";
import { PausableBase } from "./PausableBase.sol";
import { FundsBase } from "./FundsBase.sol";
import { ReentrancyGuardBase } from "./ReentrancyGuardBase.sol";
/**
* @title ProtocolBase
*
* @notice Provides domain and common modifiers to Protocol facets
*/
abstract contract ProtocolBase is PausableBase, FundsBase, ReentrancyGuardBase, BosonErrors {
/**
* @notice Modifier to protect initializer function from being invoked twice.
*/
modifier onlyUninitialized(bytes4 interfaceId) {
ProtocolLib.ProtocolStatus storage ps = protocolStatus();
if (ps.initializedInterfaces[interfaceId]) revert AlreadyInitialized();
ps.initializedInterfaces[interfaceId] = true;
_;
}
/**
* @notice Modifier that checks that the caller has a specific role.
*
* Reverts if caller doesn't have role.
*
* See: {AccessController.hasRole}
*
* @param _role - the role to check
*/
modifier onlyRole(bytes32 _role) {
DiamondLib.DiamondStorage storage ds = DiamondLib.diamondStorage();
if (!ds.accessController.hasRole(_role, _msgSender())) revert AccessDenied();
_;
}
/**
* @notice Get the Protocol Addresses slot
*
* @return pa - the Protocol Addresses slot
*/
function protocolAddresses() internal pure returns (ProtocolLib.ProtocolAddresses storage pa) {
pa = ProtocolLib.protocolAddresses();
}
/**
* @notice Get the Protocol Limits slot
*
* @return pl - the Protocol Limits slot
*/
function protocolLimits() internal pure returns (ProtocolLib.ProtocolLimits storage pl) {
pl = ProtocolLib.protocolLimits();
}
/**
* @notice Get the Protocol Entities slot
*
* @return pe - the Protocol Entities slot
*/
function protocolEntities() internal pure returns (ProtocolLib.ProtocolEntities storage pe) {
pe = ProtocolLib.protocolEntities();
}
/**
* @notice Get the Protocol Lookups slot
*
* @return pl - the Protocol Lookups slot
*/
function protocolLookups() internal pure returns (ProtocolLib.ProtocolLookups storage pl) {
pl = ProtocolLib.protocolLookups();
}
/**
* @notice Get the Protocol Fees slot
*
* @return pf - the Protocol Fees slot
*/
function protocolFees() internal pure returns (ProtocolLib.ProtocolFees storage pf) {
pf = ProtocolLib.protocolFees();
}
/**
* @notice Get the Protocol Counters slot
*
* @return pc the Protocol Counters slot
*/
function protocolCounters() internal pure returns (ProtocolLib.ProtocolCounters storage pc) {
pc = ProtocolLib.protocolCounters();
}
/**
* @notice Get the Protocol meta-transactions storage slot
*
* @return pmti the Protocol meta-transactions storage slot
*/
function protocolMetaTxInfo() internal pure returns (ProtocolLib.ProtocolMetaTxInfo storage pmti) {
pmti = ProtocolLib.protocolMetaTxInfo();
}
/**
* @notice Get the Protocol Status slot
*
* @return ps the Protocol Status slot
*/
function protocolStatus() internal pure returns (ProtocolLib.ProtocolStatus storage ps) {
ps = ProtocolLib.protocolStatus();
}
/**
* @notice Gets a seller id from storage by assistant address
*
* @param _assistant - the assistant address of the seller
* @return exists - whether the seller id exists
* @return sellerId - the seller id
*/
function getSellerIdByAssistant(address _assistant) internal view returns (bool exists, uint256 sellerId) {
// Get the seller id
sellerId = protocolLookups().sellerIdByAssistant[_assistant];
// Determine existence
exists = (sellerId > 0);
}
/**
* @notice Gets a seller id from storage by admin address
*
* @param _admin - the admin address of the seller
* @return exists - whether the seller id exists
* @return sellerId - the seller id
*/
function getSellerIdByAdmin(address _admin) internal view returns (bool exists, uint256 sellerId) {
// Get the seller id
sellerId = protocolLookups().sellerIdByAdmin[_admin];
// Determine existence
exists = (sellerId > 0);
}
/**
* @notice Gets a seller id from storage by auth token. A seller will have either an admin address or an auth token
*
* @param _authToken - the potential _authToken of the seller.
* @return exists - whether the seller id exists
* @return sellerId - the seller id
*/
function getSellerIdByAuthToken(
AuthToken calldata _authToken
) internal view returns (bool exists, uint256 sellerId) {
// Get the seller id
sellerId = protocolLookups().sellerIdByAuthToken[_authToken.tokenType][_authToken.tokenId];
// Determine existence
exists = (sellerId > 0);
}
/**
* @notice Gets a buyer id from storage by wallet address
*
* @param _wallet - the wallet address of the buyer
* @return exists - whether the buyer id exists
* @return buyerId - the buyer id
*/
function getBuyerIdByWallet(address _wallet) internal view returns (bool exists, uint256 buyerId) {
// Get the buyer id
buyerId = protocolLookups().buyerIdByWallet[_wallet];
// Determine existence
exists = (buyerId > 0);
}
/**
* @notice Gets a agent id from storage by wallet address
*
* @param _wallet - the wallet address of the buyer
* @return exists - whether the buyer id exists
* @return agentId - the buyer id
*/
function getAgentIdByWallet(address _wallet) internal view returns (bool exists, uint256 agentId) {
// Get the buyer id
agentId = protocolLookups().agentIdByWallet[_wallet];
// Determine existence
exists = (agentId > 0);
}
/**
* @notice Gets a dispute resolver id from storage by assistant address
*
* @param _assistant - the assistant address of the dispute resolver
* @return exists - whether the dispute resolver id exists
* @return disputeResolverId - the dispute resolver id
*/
function getDisputeResolverIdByAssistant(
address _assistant
) internal view returns (bool exists, uint256 disputeResolverId) {
// Get the dispute resolver id
disputeResolverId = protocolLookups().disputeResolverIdByAssistant[_assistant];
// Determine existence
exists = (disputeResolverId > 0);
}
/**
* @notice Gets a dispute resolver id from storage by admin address
*
* @param _admin - the admin address of the dispute resolver
* @return exists - whether the dispute resolver id exists
* @return disputeResolverId - the dispute resolver id
*/
function getDisputeResolverIdByAdmin(
address _admin
) internal view returns (bool exists, uint256 disputeResolverId) {
// Get the dispute resolver id
disputeResolverId = protocolLookups().disputeResolverIdByAdmin[_admin];
// Determine existence
exists = (disputeResolverId > 0);
}
/**
* @notice Gets a group id from storage by offer id
*
* @param _offerId - the offer id
* @return exists - whether the group id exists
* @return groupId - the group id.
*/
function getGroupIdByOffer(uint256 _offerId) internal view returns (bool exists, uint256 groupId) {
// Get the group id
groupId = protocolLookups().groupIdByOffer[_offerId];
// Determine existence
exists = (groupId > 0);
}
/**
* @notice Fetches a given seller from storage by id
*
* @param _sellerId - the id of the seller
* @return exists - whether the seller exists
* @return seller - the seller details. See {BosonTypes.Seller}
* @return authToken - optional AuthToken struct that specifies an AuthToken type and tokenId that the user can use to do admin functions
*/
function fetchSeller(
uint256 _sellerId
) internal view returns (bool exists, Seller storage seller, AuthToken storage authToken) {
// Cache protocol entities for reference
ProtocolLib.ProtocolEntities storage entities = protocolEntities();
// Get the seller's slot
seller = entities.sellers[_sellerId];
//Get the seller's auth token's slot
authToken = entities.authTokens[_sellerId];
// Determine existence
exists = (_sellerId > 0 && seller.id == _sellerId);
}
/**
* @notice Fetches a given buyer from storage by id
*
* @param _buyerId - the id of the buyer
* @return exists - whether the buyer exists
* @return buyer - the buyer details. See {BosonTypes.Buyer}
*/
function fetchBuyer(uint256 _buyerId) internal view returns (bool exists, BosonTypes.Buyer storage buyer) {
// Get the buyer's slot
buyer = protocolEntities().buyers[_buyerId];
// Determine existence
exists = (_buyerId > 0 && buyer.id == _buyerId);
}
/**
* @notice Fetches a given dispute resolver from storage by id
*
* @param _disputeResolverId - the id of the dispute resolver
* @return exists - whether the dispute resolver exists
* @return disputeResolver - the dispute resolver details. See {BosonTypes.DisputeResolver}
* @return disputeResolverFees - list of fees dispute resolver charges per token type. Zero address is native currency. See {BosonTypes.DisputeResolverFee}
*/
function fetchDisputeResolver(
uint256 _disputeResolverId
)
internal
view
returns (
bool exists,
BosonTypes.DisputeResolver storage disputeResolver,
BosonTypes.DisputeResolverFee[] storage disputeResolverFees
)
{
// Cache protocol entities for reference
ProtocolLib.ProtocolEntities storage entities = protocolEntities();
// Get the dispute resolver's slot
disputeResolver = entities.disputeResolvers[_disputeResolverId];
//Get dispute resolver's fee list slot
disputeResolverFees = entities.disputeResolverFees[_disputeResolverId];
// Determine existence
exists = (_disputeResolverId > 0 && disputeResolver.id == _disputeResolverId);
}
/**
* @notice Fetches a given agent from storage by id
*
* @param _agentId - the id of the agent
* @return exists - whether the agent exists
* @return agent - the agent details. See {BosonTypes.Agent}
*/
function fetchAgent(uint256 _agentId) internal view returns (bool exists, BosonTypes.Agent storage agent) {
// Get the agent's slot
agent = protocolEntities().agents[_agentId];
// Determine existence
exists = (_agentId > 0 && agent.id == _agentId);
}
/**
* @notice Fetches a given offer from storage by id
*
* @param _offerId - the id of the offer
* @return exists - whether the offer exists
* @return offer - the offer details. See {BosonTypes.Offer}
*/
function fetchOffer(uint256 _offerId) internal view returns (bool exists, Offer storage offer) {
// Get the offer's slot
offer = protocolEntities().offers[_offerId];
// Determine existence
exists = (_offerId > 0 && offer.id == _offerId);
}
/**
* @notice Fetches the offer dates from storage by offer id
*
* @param _offerId - the id of the offer
* @return offerDates - the offer dates details. See {BosonTypes.OfferDates}
*/
function fetchOfferDates(uint256 _offerId) internal view returns (BosonTypes.OfferDates storage offerDates) {
// Get the offerDates slot
offerDates = protocolEntities().offerDates[_offerId];
}
/**
* @notice Fetches the offer durations from storage by offer id
*
* @param _offerId - the id of the offer
* @return offerDurations - the offer durations details. See {BosonTypes.OfferDurations}
*/
function fetchOfferDurations(
uint256 _offerId
) internal view returns (BosonTypes.OfferDurations storage offerDurations) {
// Get the offer's slot
offerDurations = protocolEntities().offerDurations[_offerId];
}
/**
* @notice Fetches the dispute resolution terms from storage by offer id
*
* @param _offerId - the id of the offer
* @return disputeResolutionTerms - the details about the dispute resolution terms. See {BosonTypes.DisputeResolutionTerms}
*/
function fetchDisputeResolutionTerms(
uint256 _offerId
) internal view returns (BosonTypes.DisputeResolutionTerms storage disputeResolutionTerms) {
// Get the disputeResolutionTerms slot
disputeResolutionTerms = protocolEntities().disputeResolutionTerms[_offerId];
}
/**
* @notice Fetches a given group from storage by id
*
* @param _groupId - the id of the group
* @return exists - whether the group exists
* @return group - the group details. See {BosonTypes.Group}
*/
function fetchGroup(uint256 _groupId) internal view returns (bool exists, Group storage group) {
// Get the group's slot
group = protocolEntities().groups[_groupId];
// Determine existence
exists = (_groupId > 0 && group.id == _groupId);
}
/**
* @notice Fetches the Condition from storage by group id
*
* @param _groupId - the id of the group
* @return condition - the condition details. See {BosonTypes.Condition}
*/
function fetchCondition(uint256 _groupId) internal view returns (BosonTypes.Condition storage condition) {
// Get the offerDates slot
condition = protocolEntities().conditions[_groupId];
}
/**
* @notice Fetches a given exchange from storage by id
*
* @param _exchangeId - the id of the exchange
* @return exists - whether the exchange exists
* @return exchange - the exchange details. See {BosonTypes.Exchange}
*/
function fetchExchange(uint256 _exchangeId) internal view returns (bool exists, Exchange storage exchange) {
// Get the exchange's slot
exchange = protocolEntities().exchanges[_exchangeId];
// Determine existence
exists = (_exchangeId > 0 && exchange.id == _exchangeId);
}
/**
* @notice Fetches a given voucher from storage by exchange id
*
* @param _exchangeId - the id of the exchange associated with the voucher
* @return voucher - the voucher details. See {BosonTypes.Voucher}
*/
function fetchVoucher(uint256 _exchangeId) internal view returns (Voucher storage voucher) {
// Get the voucher
voucher = protocolEntities().vouchers[_exchangeId];
}
/**
* @notice Fetches a given dispute from storage by exchange id
*
* @param _exchangeId - the id of the exchange associated with the dispute
* @return exists - whether the dispute exists
* @return dispute - the dispute details. See {BosonTypes.Dispute}
*/
function fetchDispute(
uint256 _exchangeId
) internal view returns (bool exists, Dispute storage dispute, DisputeDates storage disputeDates) {
// Cache protocol entities for reference
ProtocolLib.ProtocolEntities storage entities = protocolEntities();
// Get the dispute's slot
dispute = entities.disputes[_exchangeId];
// Get the disputeDates slot
disputeDates = entities.disputeDates[_exchangeId];
// Determine existence
exists = (_exchangeId > 0 && dispute.exchangeId == _exchangeId);
}
/**
* @notice Fetches a given twin from storage by id
*
* @param _twinId - the id of the twin
* @return exists - whether the twin exists
* @return twin - the twin details. See {BosonTypes.Twin}
*/
function fetchTwin(uint256 _twinId) internal view returns (bool exists, Twin storage twin) {
// Get the twin's slot
twin = protocolEntities().twins[_twinId];
// Determine existence
exists = (_twinId > 0 && twin.id == _twinId);
}
/**
* @notice Fetches a given bundle from storage by id
*
* @param _bundleId - the id of the bundle
* @return exists - whether the bundle exists
* @return bundle - the bundle details. See {BosonTypes.Bundle}
*/
function fetchBundle(uint256 _bundleId) internal view returns (bool exists, Bundle storage bundle) {
// Get the bundle's slot
bundle = protocolEntities().bundles[_bundleId];
// Determine existence
exists = (_bundleId > 0 && bundle.id == _bundleId);
}
/**
* @notice Gets offer from protocol storage, makes sure it exist and not voided
*
* Reverts if:
* - Offer does not exist
* - Offer already voided
*
* @param _offerId - the id of the offer to check
*/
function getValidOffer(uint256 _offerId) internal view returns (Offer storage offer) {
bool exists;
// Get offer
(exists, offer) = fetchOffer(_offerId);
// Offer must already exist
if (!exists) revert NoSuchOffer();
// Offer must not already be voided
if (offer.voided) revert OfferHasBeenVoided();
}
/**
* @notice Gets offer and seller from protocol storage
*
* Reverts if:
* - Offer does not exist
* - Offer already voided
* - Seller assistant is not the caller
*
* @param _offerId - the id of the offer to check
* @return offer - the offer details. See {BosonTypes.Offer}
*/
function getValidOfferWithSellerCheck(uint256 _offerId) internal view returns (Offer storage offer) {
// Get offer
offer = getValidOffer(_offerId);
// Get seller, we assume seller exists if offer exists
(, Seller storage seller, ) = fetchSeller(offer.sellerId);
// Caller must be seller's assistant address
if (seller.assistant != _msgSender()) revert NotAssistant();
}
/**
* @notice Gets a valid offer from storage and checks that the caller is authorized to modify it
*
* Reverts if:
* - Offer id is invalid
* - Offer has already been voided
* - Caller is not authorized (for seller-created offers: not the seller assistant; for buyer-created offers: not the buyer who created it)
*
* @param _offerId - the id of the offer to check
* @return offer - the offer details. See {BosonTypes.Offer}
* @return creatorId - the id of the creator (sellerId for seller-created offers, buyerId for buyer-created offers)
*/
function getValidOfferWithCreatorCheck(
uint256 _offerId
) internal view returns (Offer storage offer, uint256 creatorId) {
// Get offer
offer = getValidOffer(_offerId);
if (offer.creator == OfferCreator.Seller) {
// For seller-created offers, check that caller is the seller's assistant
(, Seller storage seller, ) = fetchSeller(offer.sellerId);
if (seller.assistant != _msgSender()) revert NotAssistant();
creatorId = offer.sellerId;
} else if (offer.creator == OfferCreator.Buyer) {
// For buyer-created offers, check that caller is the buyer who created the offer
(, Buyer storage buyer) = fetchBuyer(offer.buyerId);
if (buyer.wallet != _msgSender()) revert NotOfferCreator();
creatorId = offer.buyerId;
}
}
/**
* @notice Gets the bundle id for a given offer id.
*
* @param _offerId - the offer id.
* @return exists - whether the bundle id exists
* @return bundleId - the bundle id.
*/
function fetchBundleIdByOffer(uint256 _offerId) internal view returns (bool exists, uint256 bundleId) {
// Get the bundle id
bundleId = protocolLookups().bundleIdByOffer[_offerId];
// Determine existence
exists = (bundleId > 0);
}
/**
* @notice Gets the bundle id for a given twin id.
*
* @param _twinId - the twin id.
* @return exists - whether the bundle id exist
* @return bundleId - the bundle id.
*/
function fetchBundleIdByTwin(uint256 _twinId) internal view returns (bool exists, uint256 bundleId) {
// Get the bundle id
bundleId = protocolLookups().bundleIdByTwin[_twinId];
// Determine existence
exists = (bundleId > 0);
}
/**
* @notice Gets the exchange ids for a given offer id.
*
* @param _offerId - the offer id.
* @return exists - whether the exchange Ids exist
* @return exchangeIds - the exchange Ids.
*/
function getExchangeIdsByOffer(
uint256 _offerId
) internal view returns (bool exists, uint256[] storage exchangeIds) {
// Get the exchange Ids
exchangeIds = protocolLookups().exchangeIdsByOffer[_offerId];
// Determine existence
exists = (exchangeIds.length > 0);
}
/**
* @notice Make sure the caller is buyer associated with the exchange
*
* Reverts if
* - caller is not the buyer associated with exchange
*
* @param _currentBuyer - id of current buyer associated with the exchange
*/
function checkBuyer(uint256 _currentBuyer) internal view {
// Get the caller's buyer account id
(, uint256 buyerId) = getBuyerIdByWallet(_msgSender());
// Must be the buyer associated with the exchange (which is always voucher holder)
if (buyerId != _currentBuyer) revert NotVoucherHolder();
}
/**
* @notice Get a valid exchange and its associated voucher
*
* Reverts if
* - Exchange does not exist
* - Exchange is not in the expected state
*
* @param _exchangeId - the id of the exchange to complete
* @param _expectedState - the state the exchange should be in
* @return exchange - the exchange
* @return voucher - the voucher
*/
function getValidExchange(
uint256 _exchangeId,
ExchangeState _expectedState
) internal view returns (Exchange storage exchange, Voucher storage voucher) {
// Get the exchange
bool exchangeExists;
(exchangeExists, exchange) = fetchExchange(_exchangeId);
// Make sure the exchange exists
if (!exchangeExists) revert NoSuchExchange();
// Make sure the exchange is in expected state
if (exchange.state != _expectedState) revert InvalidState();
// Get the voucher
voucher = fetchVoucher(_exchangeId);
}
uint256 private constant ADDRESS_LENGTH = 20;
/**
* @notice Returns the current sender address.
*/
function _msgSender() internal view override returns (address) {
uint256 msgDataLength = msg.data.length;
if (msg.sender == address(this) && msgDataLength >= ADDRESS_LENGTH) {
unchecked {
return address(bytes20(msg.data[msgDataLength - ADDRESS_LENGTH:]));
}
} else {
return msg.sender;
}
}
/**
* @notice Gets the agent id for a given offer id.
*
* @param _offerId - the offer id.
* @return exists - whether the exchange id exist
* @return agentId - the agent id.
*/
function fetchAgentIdByOffer(uint256 _offerId) internal view returns (bool exists, uint256 agentId) {
// Get the agent id
agentId = protocolLookups().agentIdByOffer[_offerId];
// Determine existence
exists = (agentId > 0);
}
/**
* @notice Fetches the offer fees from storage by offer id
*
* @param _offerId - the id of the offer
* @return offerFees - the offer fees details. See {BosonTypes.OfferFees}
*/
function fetchOfferFees(uint256 _offerId) internal view returns (BosonTypes.OfferFees storage offerFees) {
// Get the offerFees slot
offerFees = protocolEntities().offerFees[_offerId];
}
/**
* @notice Fetches a list of twin receipts from storage by exchange id
*
* @param _exchangeId - the id of the exchange
* @return exists - whether one or more twin receipt exists
* @return twinReceipts - the list of twin receipts. See {BosonTypes.TwinReceipt}
*/
function fetchTwinReceipts(
uint256 _exchangeId
) internal view returns (bool exists, TwinReceipt[] storage twinReceipts) {
// Get the twin receipts slot
twinReceipts = protocolLookups().twinReceiptsByExchange[_exchangeId];
// Determine existence
exists = (_exchangeId > 0 && twinReceipts.length > 0);
}
/**
* @notice Fetches a condition from storage by exchange id
*
* @param _exchangeId - the id of the exchange
* @return exists - whether one condition exists for the exchange
* @return condition - the condition. See {BosonTypes.Condition}
*/
function fetchConditionByExchange(
uint256 _exchangeId
) internal view returns (bool exists, Condition storage condition) {
// Get the condition slot
condition = protocolLookups().exchangeCondition[_exchangeId];
// Determine existence
exists = (_exchangeId > 0 && condition.method != EvaluationMethod.None);
}
/**
* @notice calculate the protocol fee amount for a given exchange
*
* @param _exchangeToken - the token used for the exchange
* @param _price - the price of the exchange
* @return protocolFee - the protocol fee
*/
function _getProtocolFee(address _exchangeToken, uint256 _price) internal view returns (uint256 protocolFee) {
// Check if the exchange token is the Boson token
if (_exchangeToken == protocolAddresses().token) {
// Return the flatBoson fee percentage if the exchange token is the Boson token
return protocolFees().flatBoson;
}
uint256 feePercentage = _getFeePercentage(_exchangeToken, _price);
return applyPercent(_price, feePercentage);
}
/**
* @notice calculate the protocol fee percentage for a given exchange
*
* @param _exchangeToken - the token used for the exchange
* @param _price - the price of the exchange
* @return feePercentage - the protocol fee percentage based on token price (using protocol fee table)
*/
function _getFeePercentage(address _exchangeToken, uint256 _price) internal view returns (uint256 feePercentage) {
if (_exchangeToken == protocolAddresses().token) revert FeeTableAssetNotSupported();
ProtocolLib.ProtocolFees storage fees = protocolFees();
uint256[] storage priceRanges = fees.tokenPriceRanges[_exchangeToken];
uint256[] storage feePercentages = fees.tokenFeePercentages[_exchangeToken];
// If the token has a custom fee table, find the appropriate percentage
uint256 priceRangesLength = priceRanges.length;
if (priceRangesLength > 0) {
unchecked {
uint256 i;
for (; i < priceRangesLength - 1; ++i) {
if (_price <= priceRanges[i]) {
// Return the fee percentage for the matching price range
return feePercentages[i];
}
}
// If price exceeds all ranges, use the highest fee percentage
return feePercentages[i];
}
}
// If no custom fee table exists, fallback to using the default protocol percentage
return fees.percentage;
}
/**
* @notice Fetches a clone address from storage by seller id and collection index
* If the collection index is 0, the clone address is the seller's main collection,
* otherwise it is the clone address of the additional collection at the given index.
*
* @param _lookups - storage slot for protocol lookups
* @param _sellerId - the id of the seller
* @param _collectionIndex - the index of the collection
* @return cloneAddress - the clone address
*/
function getCloneAddress(
ProtocolLib.ProtocolLookups storage _lookups,
uint256 _sellerId,
uint256 _collectionIndex
) internal view returns (address cloneAddress) {
return
_collectionIndex == 0
? _lookups.cloneAddress[_sellerId]
: _lookups.additionalCollections[_sellerId][_collectionIndex - 1].collectionAddress;
}
/**
* @notice Internal helper to get royalty information and seller for a chosen exchange.
*
* Reverts if exchange does not exist.
*
* @param _queryId - offer id or exchange id
* @param _isExchangeId - indicates if the query represents the exchange id
* @return royaltyInfo - list of royalty recipients and corresponding bps
* @return royaltyInfoIndex - index of the royalty info
* @return treasury - the seller's treasury address
*/
function fetchRoyalties(
uint256 _queryId,
bool _isExchangeId
) internal view returns (RoyaltyInfo storage royaltyInfo, uint256 royaltyInfoIndex, address treasury) {
RoyaltyInfo[] storage royaltyInfoAll;
if (_isExchangeId) {
(bool exists, Exchange storage exchange) = fetchExchange(_queryId);
if (!exists) revert NoSuchExchange();
_queryId = exchange.offerId;
}
// not using fetchOffer to reduce gas costs (limitation of royalty registry)
ProtocolLib.ProtocolEntities storage pe = protocolEntities();
Offer storage offer = pe.offers[_queryId];
treasury = pe.sellers[offer.sellerId].treasury;
royaltyInfoAll = pe.offers[_queryId].royaltyInfo;
uint256 royaltyInfoLength = royaltyInfoAll.length;
if (royaltyInfoLength == 0) revert NoSuchOffer();
royaltyInfoIndex = royaltyInfoLength - 1;
// get the last royalty info
return (royaltyInfoAll[royaltyInfoIndex], royaltyInfoIndex, treasury);
}
/**
* @notice Helper function that calculates the total royalty percentage for a given exchange
*
* @param _bps - storage slot for array of royalty percentages
* @return totalBps - the total royalty percentage
*/
function getTotalRoyaltyPercentage(uint256[] storage _bps) internal view returns (uint256 totalBps) {
uint256 bpsLength = _bps.length;
for (uint256 i = 0; i < bpsLength; ) {
totalBps += _bps[i];
unchecked {
i++;
}
}
}
}// SPDX-License-Identifier: MIT
import "../../domain/BosonConstants.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
pragma solidity 0.8.22;
/**
* @notice Contract module that helps prevent reentrant calls to a function.
*
* The majority of code, comments and general idea is taken from OpenZeppelin implementation.
* Code was adjusted to work with the storage layout used in the protocol.
* Reference implementation: OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* @dev Because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardBase {
/**
* @notice Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
ProtocolLib.ProtocolStatus storage ps = ProtocolLib.protocolStatus();
// On the first call to nonReentrant, ps.reentrancyStatus will be NOT_ENTERED
if (ps.reentrancyStatus == ENTERED) revert BosonErrors.ReentrancyGuard();
// Any calls to nonReentrant after this point will fail
ps.reentrancyStatus = ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
ps.reentrancyStatus = NOT_ENTERED;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { IClientExternalAddresses } from "../../../interfaces/clients/IClientExternalAddresses.sol";
import { BeaconClientLib } from "../../libs/BeaconClientLib.sol";
import { Proxy } from "./Proxy.sol";
/**
* @title BeaconClientProxy
*
* @notice Delegates calls to a Boson Protocol Client implementation contract,
* such that functions on it execute in the context (address, storage)
* of this proxy, allowing the implementation contract to be upgraded
* without losing the accumulated state data.
*
* Protocol clients are the contracts in the system that communicate with
* the facets of the ProtocolDiamond rather than acting as facets themselves.
*
* Each Protocol client contract will be deployed behind its own proxy for
* future upgradability.
*/
contract BeaconClientProxy is Proxy {
/**
* @notice Initializes the contract after the deployment.
* This function is callable only once
*
* @param _beaconAddress - address of the Beacon to initialize
*/
function initialize(address _beaconAddress) external initializer {
// set the beacon address
BeaconClientLib.getBeaconSlot().value = _beaconAddress;
}
/**
* @notice Modifier to protect initializer function from being invoked twice.
*/
modifier initializer() {
// solhint-disable-next-line gas-custom-errors
require(!BeaconClientLib.getBeaconSlot().initialized, "Initializable: contract is already initialized"); // not using Custom Errors here to match OZ 4.9.* errors
_;
BeaconClientLib.getBeaconSlot().initialized = true;
}
/**
* @notice Returns the address to which the fallback function
* and {_fallback} should delegate.
* Implementation address is supplied by the Beacon
*
* @return address of the Beacon implementation
*/
function _implementation() internal view override returns (address) {
// Return the current implementation address
return IClientExternalAddresses(BeaconClientLib._beacon()).getImplementation();
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
/**
* @notice This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @notice Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*
* @param implementation - the address of the implementation to which the call should be delegated
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @notice This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*
* @return the address to which the fallback function should delegate
*/
function _implementation() internal view virtual returns (address);
/**
* @notice Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @notice Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @notice Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @notice Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
/**
* @title BeaconClientLib
*
* @notice
* - Defines BeaconSlot position
* - Provides BeaconSlot accessor
* - Defines hasRole function
*/
library BeaconClientLib {
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
struct BeaconSlot {
address value;
bool initialized;
}
/**
* @notice Returns a `BeaconSlot` with member `value`.
*
* @return r - the BeaconSlot storage slot cast to BeaconSlot
*/
function getBeaconSlot() internal pure returns (BeaconSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := _BEACON_SLOT
}
}
/**
* @notice Returns the address of the Beacon
*
* @return the Beacon address
*/
function _beacon() internal view returns (address) {
return getBeaconSlot().value;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import "../../domain/BosonConstants.sol";
import { BosonErrors } from "../../domain/BosonErrors.sol";
import { ProtocolLib } from "../libs/ProtocolLib.sol";
import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
/**
* @title EIP712Lib
*
* @dev Provides the domain separator and chain id.
*/
library EIP712Lib {
struct ECDSASignature {
bytes32 r;
bytes32 s;
uint8 v;
}
/**
* @notice Generates the domain separator hash.
* @dev Using the chainId as the salt enables the client to be active on one chain
* while a metatx is signed for a contract on another chain. That could happen if the client is,
* for instance, a metaverse scene that runs on one chain while the contracts it interacts with are deployed on another chain.
*
* @param _name - the name of the protocol
* @param _version - The version of the protocol
* @return the domain separator hash
*/
function buildDomainSeparator(string memory _name, string memory _version) internal view returns (bytes32) {
return
keccak256(
abi.encode(
EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(_name)),
keccak256(bytes(_version)),
address(this),
block.chainid
)
);
}
/**
* @notice Verifies that the user either signed or the user is a contract implementing ERC1271.
*
* Reverts if:
* - User is the zero address
* - User is a contract that does not implement ERC1271.isValidSignature or fallback
* - User is a contract that implements ERC1271.isValidSignature or fallback, but returns an unexpected value (including wrong magic value, wrong return data size, etc.)
* - User is a contract that reverts when called with the signature
* - User is an EOA (including smart accounts that do not implement ERC1271) but the signature is not a valid ECDSA signature
* - Recovered signer does not match the user address
*
* N.B. If the user is a smart account that supports ERC1271, it does not have to provide a valid ECDSA signature.
* If the user is EOA and it provides a valid ECDSA signature, it does not have to implement ERC1271.
* Even if the smart account supports ERC1271, and the validation fails, if the signature is a valid ECDSA signature, it will be accepted.
*
* @param _user - the message signer
* @param _hashedMessage - hashed message
* @param _signature - signature.
If the user is ordinary EOA, it must be ECDSA signature in the format of concatenated r,s,v values.
If the user is a contract, it must be a valid ERC1271 signature.
If the user is a EIP-7702 smart account, it can be either a valid ERC1271 signature or a valid ECDSA signature.
*/
function verify(address _user, bytes32 _hashedMessage, bytes calldata _signature) internal {
if (_user == address(0)) revert BosonErrors.InvalidAddress();
bytes32 typedMessageHash = toTypedMessageHash(_hashedMessage);
// Check if user is a contract implementing ERC1271 or a EIP-7702 smart account
bytes memory returnData; // Make this available for later if needed
bool isValidSignatureCallSuccess;
if (_user.code.length > 0) {
(isValidSignatureCallSuccess, returnData) = _user.staticcall(
abi.encodeCall(IERC1271.isValidSignature, (typedMessageHash, _signature))
);
// if the call succeeded, check the return value, only if it's correctly formatted (bytes4)
// if the returned value matches the expected selector, the signature is valid.
// in all other cases, try the ECDSA signature verification below and if that fails, bubble up the error
if (
isValidSignatureCallSuccess &&
returnData.length == SLOT_SIZE &&
(uint256(bytes32(returnData)) & type(uint224).max) == 0 &&
abi.decode(returnData, (bytes4)) == IERC1271.isValidSignature.selector
) {
return;
}
}
address signer;
// If the user is not a contract or the call to ERC1271 failed, we assume it's an ECDSA signature
if (_signature.length == 65) {
ECDSASignature memory ecdsaSig = ECDSASignature({
r: bytes32(_signature[0:32]),
s: bytes32(_signature[32:64]),
v: uint8(_signature[64])
});
// Ensure signature is unique
// See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/04695aecbd4d17dddfd55de766d10e3805d6f42f/contracts/cryptography/ECDSA.sol#63
if (
uint256(ecdsaSig.s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 ||
(ecdsaSig.v != 27 && ecdsaSig.v != 28)
) revert BosonErrors.InvalidSignature();
signer = ecrecover(typedMessageHash, ecdsaSig.v, ecdsaSig.r, ecdsaSig.s);
if (signer == address(0)) revert BosonErrors.InvalidSignature();
}
if (signer != _user) {
// ECDSA failed, while EIP-1271 verification call succeeded but returned something different than the magic value
if (isValidSignatureCallSuccess) revert BosonErrors.UnexpectedDataReturned(returnData);
// If both ECDSA and EIP-1271 verification call failed, bubble up the revert reason
if (returnData.length > 0) {
/// @solidity memory-safe-assembly
assembly {
revert(add(SLOT_SIZE, returnData), mload(returnData))
}
}
revert BosonErrors.SignatureValidationFailed();
}
}
/**
* @notice Gets the domain separator from storage if matches with the chain id and diamond address, else, build new domain separator.
*
* @return the domain separator
*/
function getDomainSeparator() private returns (bytes32) {
ProtocolLib.ProtocolMetaTxInfo storage pmti = ProtocolLib.protocolMetaTxInfo();
uint256 cachedChainId = pmti.cachedChainId;
if (block.chainid == cachedChainId) {
return pmti.domainSeparator;
} else {
bytes32 domainSeparator = buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION);
pmti.domainSeparator = domainSeparator;
pmti.cachedChainId = block.chainid;
return domainSeparator;
}
}
/**
* @notice Generates EIP712 compatible message hash.
*
* @dev Accepts message hash and returns hash message in EIP712 compatible form
* so that it can be used to recover signer from signature signed using EIP712 formatted data
* https://eips.ethereum.org/EIPS/eip-712
* "\\x19" makes the encoding deterministic
* "\\x01" is the version byte to make it compatible to EIP-191
*
* @param _messageHash - the message hash
* @return the EIP712 compatible message hash
*/
function toTypedMessageHash(bytes32 _messageHash) internal returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", getDomainSeparator(), _messageHash));
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { BosonTypes } from "../../domain/BosonTypes.sol";
/**
* @title ProtocolLib
*
* @notice Provides access to the protocol addresses, limits, entities, fees, counters, initializers and metaTransactions slots for Facets.
*/
library ProtocolLib {
bytes32 internal constant PROTOCOL_ADDRESSES_POSITION = keccak256("boson.protocol.addresses");
bytes32 internal constant PROTOCOL_LIMITS_POSITION = keccak256("boson.protocol.limits");
bytes32 internal constant PROTOCOL_ENTITIES_POSITION = keccak256("boson.protocol.entities");
bytes32 internal constant PROTOCOL_LOOKUPS_POSITION = keccak256("boson.protocol.lookups");
bytes32 internal constant PROTOCOL_FEES_POSITION = keccak256("boson.protocol.fees");
bytes32 internal constant PROTOCOL_COUNTERS_POSITION = keccak256("boson.protocol.counters");
bytes32 internal constant PROTOCOL_STATUS_POSITION = keccak256("boson.protocol.initializers");
bytes32 internal constant PROTOCOL_META_TX_POSITION = keccak256("boson.protocol.metaTransactions");
// Protocol addresses storage
struct ProtocolAddresses {
// Address of the Boson Protocol treasury
address payable treasury;
// Address of the Boson Token (ERC-20 contract)
address payable token;
// Address of the Boson Protocol Voucher beacon
address voucherBeacon;
// Address of the Boson Beacon proxy implementation
address beaconProxy;
// Address of the Boson Price Discovery
address priceDiscovery;
}
// Protocol limits storage
struct ProtocolLimits {
// limit on the resolution period that a seller can specify
uint256 maxResolutionPeriod;
// limit on the escalation response period that a dispute resolver can specify
uint256 maxEscalationResponsePeriod;
// lower limit for dispute period
uint256 minDisputePeriod;
// limit how many exchanges can be processed in single batch transaction
uint16 maxExchangesPerBatch;
// limit how many offers can be added to the group
uint16 maxOffersPerGroup;
// limit how many offers can be added to the bundle
uint16 maxOffersPerBundle;
// limit how many twins can be added to the bundle
uint16 maxTwinsPerBundle;
// limit how many offers can be processed in single batch transaction
uint16 maxOffersPerBatch;
// limit how many different tokens can be withdrawn in a single transaction
uint16 maxTokensPerWithdrawal;
// limit how many dispute resolver fee structs can be processed in a single transaction
uint16 maxFeesPerDisputeResolver;
// limit how many disputes can be processed in single batch transaction
uint16 maxDisputesPerBatch;
// limit how many sellers can be added to or removed from an allow list in a single transaction
uint16 maxAllowedSellers;
// limit the sum of (protocol fee percentage + agent fee percentage) of an offer fee
uint16 maxTotalOfferFeePercentage;
// limit the max royalty percentage that can be set by the seller
uint16 maxRoyaltyPercentage;
// limit the max number of vouchers that can be preminted in a single transaction
uint256 maxPremintedVouchers;
// lower limit for resolution period
uint256 minResolutionPeriod;
// Gas to forward when returning DR fee to mutualizer
uint256 mutualizerGasStipend;
}
// Protocol fees storage
struct ProtocolFees {
// Default percentage that will be taken as a fee from the net of a Boson Protocol exchange.
// This fee is returned if no fee ranges are configured in the fee table for the given asset.
uint256 percentage; // 1.75% = 175, 100% = 10000
// Flat fee taken for exchanges in $BOSON
uint256 flatBoson;
// buyer escalation deposit percentage
uint256 buyerEscalationDepositPercentage;
// Token-specific fee tables
mapping(address => uint256[]) tokenPriceRanges; // Price ranges for each token
mapping(address => uint256[]) tokenFeePercentages; // Fee percentages for each price range
}
// Protocol entities storage
struct ProtocolEntities {
// offer id => offer
mapping(uint256 => BosonTypes.Offer) offers;
// offer id => offer dates
mapping(uint256 => BosonTypes.OfferDates) offerDates;
// offer id => offer fees
mapping(uint256 => BosonTypes.OfferFees) offerFees;
// offer id => offer durations
mapping(uint256 => BosonTypes.OfferDurations) offerDurations;
// offer id => dispute resolution terms
mapping(uint256 => BosonTypes.DisputeResolutionTerms) disputeResolutionTerms;
// exchange id => exchange
mapping(uint256 => BosonTypes.Exchange) exchanges;
// exchange id => voucher
mapping(uint256 => BosonTypes.Voucher) vouchers;
// exchange id => dispute
mapping(uint256 => BosonTypes.Dispute) disputes;
// exchange id => dispute dates
mapping(uint256 => BosonTypes.DisputeDates) disputeDates;
// seller id => seller
mapping(uint256 => BosonTypes.Seller) sellers;
// buyer id => buyer
mapping(uint256 => BosonTypes.Buyer) buyers;
// dispute resolver id => dispute resolver
mapping(uint256 => BosonTypes.DisputeResolver) disputeResolvers;
// dispute resolver id => dispute resolver fee array
mapping(uint256 => BosonTypes.DisputeResolverFee[]) disputeResolverFees;
// agent id => agent
mapping(uint256 => BosonTypes.Agent) agents;
// group id => group
mapping(uint256 => BosonTypes.Group) groups;
// group id => condition
mapping(uint256 => BosonTypes.Condition) conditions;
// bundle id => bundle
mapping(uint256 => BosonTypes.Bundle) bundles;
// twin id => twin
mapping(uint256 => BosonTypes.Twin) twins;
// entity id => auth token
mapping(uint256 => BosonTypes.AuthToken) authTokens;
// exchange id => sequential commit info
mapping(uint256 => BosonTypes.ExchangeCosts[]) exchangeCosts;
// entity id => royalty recipient account
mapping(uint256 => BosonTypes.RoyaltyRecipient) royaltyRecipients;
}
// Protocol lookups storage
struct ProtocolLookups {
// offer id => exchange ids
mapping(uint256 => uint256[]) exchangeIdsByOffer;
// offer id => bundle id
mapping(uint256 => uint256) bundleIdByOffer;
// twin id => bundle id
mapping(uint256 => uint256) bundleIdByTwin;
// offer id => group id
mapping(uint256 => uint256) groupIdByOffer;
// offer id => agent id
mapping(uint256 => uint256) agentIdByOffer;
// seller assistant address => sellerId
mapping(address => uint256) sellerIdByAssistant;
// seller admin address => sellerId
mapping(address => uint256) sellerIdByAdmin;
// seller clerk address => sellerId
// @deprecated sellerIdByClerk is no longer used. Keeping it for backwards compatibility.
mapping(address => uint256) sellerIdByClerk;
// buyer wallet address => buyerId
mapping(address => uint256) buyerIdByWallet;
// dispute resolver assistant address => disputeResolverId
mapping(address => uint256) disputeResolverIdByAssistant;
// dispute resolver admin address => disputeResolverId
mapping(address => uint256) disputeResolverIdByAdmin;
// dispute resolver clerk address => disputeResolverId
// @deprecated disputeResolverIdByClerk is no longer used. Keeping it for backwards compatibility.
mapping(address => uint256) disputeResolverIdByClerk;
// dispute resolver id to fee token address => index of the token address
mapping(uint256 => mapping(address => uint256)) disputeResolverFeeTokenIndex;
// agent wallet address => agentId
mapping(address => uint256) agentIdByWallet;
// account id => token address => amount
mapping(uint256 => mapping(address => uint256)) availableFunds;
// account id => all tokens with balance > 0
mapping(uint256 => address[]) tokenList;
// account id => token address => index on token addresses list
mapping(uint256 => mapping(address => uint256)) tokenIndexByAccount;
// seller id => cloneAddress
mapping(uint256 => address) cloneAddress;
// buyer id => number of active vouchers
mapping(uint256 => uint256) voucherCount;
// buyer address => groupId => commit count (addresses that have committed to conditional offers)
mapping(address => mapping(uint256 => uint256)) conditionalCommitsByAddress;
// AuthTokenType => Auth NFT contract address.
mapping(BosonTypes.AuthTokenType => address) authTokenContracts;
// AuthTokenType => tokenId => sellerId
mapping(BosonTypes.AuthTokenType => mapping(uint256 => uint256)) sellerIdByAuthToken;
// seller id => token address (only ERC721) => start and end of token ids range
mapping(uint256 => mapping(address => BosonTypes.TokenRange[])) twinRangesBySeller;
// seller id => token address (only ERC721) => twin ids
// @deprecated twinIdsByTokenAddressAndBySeller is no longer used. Keeping it for backwards compatibility.
mapping(uint256 => mapping(address => uint256[])) twinIdsByTokenAddressAndBySeller;
// exchange id => BosonTypes.TwinReceipt
mapping(uint256 => BosonTypes.TwinReceipt[]) twinReceiptsByExchange;
// dispute resolver id => list of allowed sellers
mapping(uint256 => uint256[]) allowedSellers;
// dispute resolver id => seller id => index of allowed seller in allowedSellers
mapping(uint256 => mapping(uint256 => uint256)) allowedSellerIndex;
// exchange id => condition
mapping(uint256 => BosonTypes.Condition) exchangeCondition;
// groupId => offerId => index on Group.offerIds array
mapping(uint256 => mapping(uint256 => uint256)) offerIdIndexByGroup;
// seller id => Seller
mapping(uint256 => BosonTypes.Seller) pendingAddressUpdatesBySeller;
// seller id => AuthToken
mapping(uint256 => BosonTypes.AuthToken) pendingAuthTokenUpdatesBySeller;
// dispute resolver id => DisputeResolver
mapping(uint256 => BosonTypes.DisputeResolver) pendingAddressUpdatesByDisputeResolver;
// twin id => range id
mapping(uint256 => uint256) rangeIdByTwin;
// tokenId => groupId => commit count (count how many times a token has been used as gate for this group)
mapping(uint256 => mapping(uint256 => uint256)) conditionalCommitsByTokenId;
// seller id => collections
mapping(uint256 => BosonTypes.Collection[]) additionalCollections;
// seller id => seller salt used to create collections
mapping(uint256 => bytes32) sellerSalt;
// seller salt => is used
mapping(bytes32 => bool) isUsedSellerSalt;
// seller id => royalty recipients info
mapping(uint256 => BosonTypes.RoyaltyRecipientInfo[]) royaltyRecipientsBySeller;
// seller id => royalty recipient => index of royalty recipient in royaltyRecipientsBySeller
mapping(uint256 => mapping(address => uint256)) royaltyRecipientIndexBySellerAndRecipient;
// royalty recipient wallet address => agentId
mapping(address => uint256) royaltyRecipientIdByWallet;
// offer hash -> offer id
mapping(bytes32 => uint256) offerIdByHash;
}
// Incrementing id counters
struct ProtocolCounters {
// Next account id
uint256 nextAccountId;
// Next offer id
uint256 nextOfferId;
// Next exchange id
uint256 nextExchangeId;
// Next twin id
uint256 nextTwinId;
// Next group id
uint256 nextGroupId;
// Next twin id
uint256 nextBundleId;
}
// Storage related to Meta Transactions
struct ProtocolMetaTxInfo {
// [deprecated]
bytes32 deprecatedSlot;
// The domain Separator of the protocol
bytes32 domainSeparator;
// address => nonce => nonce used indicator
mapping(address => mapping(uint256 => bool)) usedNonce;
// The cached chain id
uint256 cachedChainId;
// map function name to input type
mapping(string => BosonTypes.MetaTxInputType) inputType;
// map input type => hash info
mapping(BosonTypes.MetaTxInputType => BosonTypes.HashInfo) hashInfo;
// Can function be executed using meta transactions
mapping(bytes32 => bool) isAllowlisted;
}
// Individual facet initialization states
struct ProtocolStatus {
// the current pause scenario, a sum of PausableRegions as powers of two
uint256 pauseScenario;
// reentrancy status
uint256 reentrancyStatus;
// interface id => initialized?
mapping(bytes4 => bool) initializedInterfaces;
// version => initialized?
mapping(bytes32 => bool) initializedVersions;
// Current protocol version
bytes32 version;
// Incoming voucher id
uint256 incomingVoucherId;
// Incoming voucher clone address
address incomingVoucherCloneAddress;
}
/**
* @dev Gets the protocol addresses slot
*
* @return pa - the protocol addresses slot
*/
function protocolAddresses() internal pure returns (ProtocolAddresses storage pa) {
bytes32 position = PROTOCOL_ADDRESSES_POSITION;
assembly {
pa.slot := position
}
}
/**
* @notice Gets the protocol limits slot
*
* @return pl - the protocol limits slot
*/
function protocolLimits() internal pure returns (ProtocolLimits storage pl) {
bytes32 position = PROTOCOL_LIMITS_POSITION;
assembly {
pl.slot := position
}
}
/**
* @notice Gets the protocol entities slot
*
* @return pe - the protocol entities slot
*/
function protocolEntities() internal pure returns (ProtocolEntities storage pe) {
bytes32 position = PROTOCOL_ENTITIES_POSITION;
assembly {
pe.slot := position
}
}
/**
* @notice Gets the protocol lookups slot
*
* @return pl - the protocol lookups slot
*/
function protocolLookups() internal pure returns (ProtocolLookups storage pl) {
bytes32 position = PROTOCOL_LOOKUPS_POSITION;
assembly {
pl.slot := position
}
}
/**
* @notice Gets the protocol fees slot
*
* @return pf - the protocol fees slot
*/
function protocolFees() internal pure returns (ProtocolFees storage pf) {
bytes32 position = PROTOCOL_FEES_POSITION;
assembly {
pf.slot := position
}
}
/**
* @notice Gets the protocol counters slot
*
* @return pc - the protocol counters slot
*/
function protocolCounters() internal pure returns (ProtocolCounters storage pc) {
bytes32 position = PROTOCOL_COUNTERS_POSITION;
assembly {
pc.slot := position
}
}
/**
* @notice Gets the protocol meta-transactions storage slot
*
* @return pmti - the protocol meta-transactions storage slot
*/
function protocolMetaTxInfo() internal pure returns (ProtocolMetaTxInfo storage pmti) {
bytes32 position = PROTOCOL_META_TX_POSITION;
assembly {
pmti.slot := position
}
}
/**
* @notice Gets the protocol status slot
*
* @return ps - the the protocol status slot
*/
function protocolStatus() internal pure returns (ProtocolStatus storage ps) {
bytes32 position = PROTOCOL_STATUS_POSITION;
assembly {
ps.slot := position
}
}
}{
"viaIR": false,
"optimizer": {
"enabled": true,
"runs": 100,
"details": {
"yul": true
}
},
"evmVersion": "shanghai",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"AccessDenied","type":"error"},{"inputs":[],"name":"AddressesAndCalldataLengthMismatch","type":"error"},{"inputs":[],"name":"AdminOrAuthToken","type":"error"},{"inputs":[],"name":"AgentAddressMustBeUnique","type":"error"},{"inputs":[],"name":"AgentFeeAmountTooHigh","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"AmbiguousVoucherExpiry","type":"error"},{"inputs":[],"name":"AmountExceedsRangeOrNothingToBurn","type":"error"},{"inputs":[],"name":"ArrayLengthMismatch","type":"error"},{"inputs":[],"name":"AuthTokenMustBeUnique","type":"error"},{"inputs":[],"name":"BundleForTwinExists","type":"error"},{"inputs":[],"name":"BundleOfferMustBeUnique","type":"error"},{"inputs":[],"name":"BundleRequiresAtLeastOneTwinAndOneOffer","type":"error"},{"inputs":[],"name":"BundleTwinMustBeUnique","type":"error"},{"inputs":[],"name":"BuyerAddressMustBeUnique","type":"error"},{"inputs":[],"name":"CannotCommit","type":"error"},{"inputs":[],"name":"CannotRemoveDefaultRecipient","type":"error"},{"inputs":[],"name":"ClerkDeprecated","type":"error"},{"inputs":[],"name":"CloneCreationFailed","type":"error"},{"inputs":[],"name":"DRFeeMutualizerCannotProvideCoverage","type":"error"},{"inputs":[],"name":"DRUnsupportedFee","type":"error"},{"inputs":[],"name":"DirectInitializationNotAllowed","type":"error"},{"inputs":[],"name":"DisputeHasExpired","type":"error"},{"inputs":[],"name":"DisputePeriodHasElapsed","type":"error"},{"inputs":[],"name":"DisputePeriodNotElapsed","type":"error"},{"inputs":[],"name":"DisputeResolverAddressMustBeUnique","type":"error"},{"inputs":[],"name":"DisputeResolverFeeNotFound","type":"error"},{"inputs":[],"name":"DisputeStillValid","type":"error"},{"inputs":[],"name":"DuplicateDisputeResolverFees","type":"error"},{"inputs":[],"name":"EscalationNotAllowed","type":"error"},{"inputs":[],"name":"ExchangeAlreadyExists","type":"error"},{"inputs":[],"name":"ExchangeForOfferExists","type":"error"},{"inputs":[],"name":"ExchangeIdInReservedRange","type":"error"},{"inputs":[],"name":"ExchangeIsNotInAFinalState","type":"error"},{"inputs":[],"name":"ExternalCallFailed","type":"error"},{"inputs":[],"name":"FeeAmountTooHigh","type":"error"},{"inputs":[],"name":"FeeTableAssetNotSupported","type":"error"},{"inputs":[],"name":"FunctionNotAllowlisted","type":"error"},{"inputs":[],"name":"GroupHasCondition","type":"error"},{"inputs":[],"name":"GroupHasNoCondition","type":"error"},{"inputs":[],"name":"IncomingVoucherAlreadySet","type":"error"},{"inputs":[],"name":"InexistentAllowedSellersList","type":"error"},{"inputs":[],"name":"InexistentDisputeResolverFees","type":"error"},{"inputs":[],"name":"InsufficientAvailableFunds","type":"error"},{"inputs":[],"name":"InsufficientTwinSupplyToCoverBundleOffers","type":"error"},{"inputs":[],"name":"InsufficientValueReceived","type":"error"},{"inputs":[],"name":"InteractionNotAllowed","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidAgentFeePercentage","type":"error"},{"inputs":[],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidAmountToMint","type":"error"},{"inputs":[],"name":"InvalidAuthTokenType","type":"error"},{"inputs":[],"name":"InvalidBuyerOfferFields","type":"error"},{"inputs":[],"name":"InvalidBuyerPercent","type":"error"},{"inputs":[],"name":"InvalidCollectionIndex","type":"error"},{"inputs":[],"name":"InvalidConditionParameters","type":"error"},{"inputs":[],"name":"InvalidConduitAddress","type":"error"},{"inputs":[],"name":"InvalidDisputePeriod","type":"error"},{"inputs":[],"name":"InvalidDisputeResolver","type":"error"},{"inputs":[],"name":"InvalidDisputeTimeout","type":"error"},{"inputs":[],"name":"InvalidEscalationPeriod","type":"error"},{"inputs":[],"name":"InvalidFeePercentage","type":"error"},{"inputs":[],"name":"InvalidFunctionName","type":"error"},{"inputs":[],"name":"InvalidOffer","type":"error"},{"inputs":[],"name":"InvalidOfferCreator","type":"error"},{"inputs":[],"name":"InvalidOfferPenalty","type":"error"},{"inputs":[],"name":"InvalidOfferPeriod","type":"error"},{"inputs":[],"name":"InvalidPriceDiscovery","type":"error"},{"inputs":[],"name":"InvalidPriceDiscoveryPrice","type":"error"},{"inputs":[],"name":"InvalidPriceType","type":"error"},{"inputs":[],"name":"InvalidQuantityAvailable","type":"error"},{"inputs":[],"name":"InvalidRangeLength","type":"error"},{"inputs":[],"name":"InvalidRangeStart","type":"error"},{"inputs":[],"name":"InvalidRedemptionPeriod","type":"error"},{"inputs":[],"name":"InvalidResolutionPeriod","type":"error"},{"inputs":[],"name":"InvalidRoyaltyFee","type":"error"},{"inputs":[],"name":"InvalidRoyaltyInfo","type":"error"},{"inputs":[],"name":"InvalidRoyaltyPercentage","type":"error"},{"inputs":[],"name":"InvalidRoyaltyRecipient","type":"error"},{"inputs":[],"name":"InvalidRoyaltyRecipientId","type":"error"},{"inputs":[],"name":"InvalidSellerOfferFields","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidState","type":"error"},{"inputs":[],"name":"InvalidSupplyAvailable","type":"error"},{"inputs":[],"name":"InvalidTargeDisputeState","type":"error"},{"inputs":[],"name":"InvalidTargeExchangeState","type":"error"},{"inputs":[],"name":"InvalidToAddress","type":"error"},{"inputs":[],"name":"InvalidTokenAddress","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"InvalidTwinProperty","type":"error"},{"inputs":[],"name":"InvalidTwinTokenRange","type":"error"},{"inputs":[],"name":"MaxCommitsReached","type":"error"},{"inputs":[],"name":"MustBeActive","type":"error"},{"inputs":[],"name":"NativeNotAllowed","type":"error"},{"inputs":[],"name":"NativeWrongAddress","type":"error"},{"inputs":[],"name":"NativeWrongAmount","type":"error"},{"inputs":[],"name":"NegativePriceNotAllowed","type":"error"},{"inputs":[],"name":"NoPendingUpdateForAccount","type":"error"},{"inputs":[],"name":"NoReservedRangeForOffer","type":"error"},{"inputs":[],"name":"NoSilentMintAllowed","type":"error"},{"inputs":[],"name":"NoSuchAgent","type":"error"},{"inputs":[],"name":"NoSuchBundle","type":"error"},{"inputs":[],"name":"NoSuchBuyer","type":"error"},{"inputs":[],"name":"NoSuchCollection","type":"error"},{"inputs":[],"name":"NoSuchDisputeResolver","type":"error"},{"inputs":[],"name":"NoSuchEntity","type":"error"},{"inputs":[],"name":"NoSuchExchange","type":"error"},{"inputs":[],"name":"NoSuchGroup","type":"error"},{"inputs":[],"name":"NoSuchOffer","type":"error"},{"inputs":[],"name":"NoSuchSeller","type":"error"},{"inputs":[],"name":"NoSuchTwin","type":"error"},{"inputs":[],"name":"NoTransferApproved","type":"error"},{"inputs":[],"name":"NoUpdateApplied","type":"error"},{"inputs":[],"name":"NonAscendingOrder","type":"error"},{"inputs":[],"name":"NonceUsedAlready","type":"error"},{"inputs":[],"name":"NotAdmin","type":"error"},{"inputs":[],"name":"NotAdminAndAssistant","type":"error"},{"inputs":[],"name":"NotAgentWallet","type":"error"},{"inputs":[],"name":"NotAssistant","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotBuyerOrSeller","type":"error"},{"inputs":[],"name":"NotBuyerWallet","type":"error"},{"inputs":[],"name":"NotDisputeResolverAssistant","type":"error"},{"inputs":[],"name":"NotOfferCreator","type":"error"},{"inputs":[],"name":"NotPaused","type":"error"},{"inputs":[],"name":"NotVoucherHolder","type":"error"},{"inputs":[],"name":"NothingToWithdraw","type":"error"},{"inputs":[],"name":"NothingUpdated","type":"error"},{"inputs":[],"name":"OfferExpiredOrVoided","type":"error"},{"inputs":[],"name":"OfferHasBeenVoided","type":"error"},{"inputs":[],"name":"OfferHasExpired","type":"error"},{"inputs":[],"name":"OfferMustBeActive","type":"error"},{"inputs":[],"name":"OfferMustBeUnique","type":"error"},{"inputs":[],"name":"OfferNotAvailable","type":"error"},{"inputs":[],"name":"OfferNotInBundle","type":"error"},{"inputs":[],"name":"OfferNotInGroup","type":"error"},{"inputs":[],"name":"OfferRangeAlreadyReserved","type":"error"},{"inputs":[],"name":"OfferSoldOut","type":"error"},{"inputs":[],"name":"OfferStillValid","type":"error"},{"inputs":[],"name":"PriceDoesNotCoverPenalty","type":"error"},{"inputs":[],"name":"PriceMismatch","type":"error"},{"inputs":[],"name":"ProtocolInitializationFailed","type":"error"},{"inputs":[],"name":"RecipientNotUnique","type":"error"},{"inputs":[],"name":"ReentrancyGuard","type":"error"},{"inputs":[{"internalType":"enum BosonTypes.PausableRegion","name":"region","type":"uint8"}],"name":"RegionPaused","type":"error"},{"inputs":[],"name":"RoyaltyRecipientIdsNotSorted","type":"error"},{"inputs":[],"name":"SameMutualizerAddress","type":"error"},{"inputs":[],"name":"SellerAddressMustBeUnique","type":"error"},{"inputs":[],"name":"SellerAlreadyApproved","type":"error"},{"inputs":[],"name":"SellerNotApproved","type":"error"},{"inputs":[],"name":"SellerParametersNotAllowed","type":"error"},{"inputs":[],"name":"SellerSaltNotUnique","type":"error"},{"inputs":[],"name":"SignatureValidationFailed","type":"error"},{"inputs":[],"name":"TokenAmountMismatch","type":"error"},{"inputs":[],"name":"TokenIdMandatory","type":"error"},{"inputs":[],"name":"TokenIdMismatch","type":"error"},{"inputs":[],"name":"TokenIdNotInConditionRange","type":"error"},{"inputs":[],"name":"TokenIdNotSet","type":"error"},{"inputs":[],"name":"TokenTransferFailed","type":"error"},{"inputs":[],"name":"TotalFeeExceedsLimit","type":"error"},{"inputs":[],"name":"TwinNotInBundle","type":"error"},{"inputs":[],"name":"TwinTransferUnsuccessful","type":"error"},{"inputs":[],"name":"TwinsAlreadyExist","type":"error"},{"inputs":[],"name":"UnauthorizedCallerUpdate","type":"error"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"UnexpectedDataReturned","type":"error"},{"inputs":[],"name":"UnexpectedERC721Received","type":"error"},{"inputs":[],"name":"UnsupportedMutualizer","type":"error"},{"inputs":[],"name":"UnsupportedToken","type":"error"},{"inputs":[],"name":"ValueZeroNotAllowed","type":"error"},{"inputs":[],"name":"VersionMustBeSet","type":"error"},{"inputs":[],"name":"VoucherExtensionNotValid","type":"error"},{"inputs":[],"name":"VoucherHasExpired","type":"error"},{"inputs":[],"name":"VoucherNotReceived","type":"error"},{"inputs":[],"name":"VoucherNotRedeemable","type":"error"},{"inputs":[],"name":"VoucherNotTransferred","type":"error"},{"inputs":[],"name":"VoucherStillValid","type":"error"},{"inputs":[],"name":"VoucherTransferNotAllowed","type":"error"},{"inputs":[],"name":"WalletOwnsVouchers","type":"error"},{"inputs":[],"name":"WrongCurrentVersion","type":"error"},{"inputs":[],"name":"WrongDefaultRecipient","type":"error"},{"inputs":[],"name":"ZeroDepositNotAllowed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"accessControllerAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"AccessControllerAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"enum BosonTypes.AuthTokenType","name":"authTokenType","type":"uint8"},{"indexed":true,"internalType":"address","name":"authTokenContract","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"AuthTokenContractChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"beaconProxyAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"BeaconProxyAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"buyerEscalationFeePercentage","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"BuyerEscalationFeePercentageChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"priceRanges","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"feePercentages","type":"uint256[]"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"FeeTableUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxEscalationResponsePeriod","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MaxEscalationResponsePeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxPremintedVouchers","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MaxPremintedVouchersChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"maxResolutionPeriod","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MaxResolutionPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"maxRoyaltyPercentage","type":"uint16"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MaxRoyaltyPercentageChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"maxTotalOfferFeePercentage","type":"uint16"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MaxTotalOfferFeePercentageChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minDisputePeriod","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MinDisputePeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"minResolutionPeriod","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MinResolutionPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"mutualizerGasStipend","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"MutualizerGasStipendChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"priceDiscoveryAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"PriceDiscoveryAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feeFlatBoson","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"ProtocolFeeFlatBosonChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feePercentage","type":"uint256"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"ProtocolFeePercentageChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"TokenAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"treasuryAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"TreasuryAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"voucherBeaconAddress","type":"address"},{"indexed":true,"internalType":"address","name":"executedBy","type":"address"}],"name":"VoucherBeaconAddressChanged","type":"event"},{"inputs":[],"name":"getAccessControllerAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum BosonTypes.AuthTokenType","name":"_authTokenType","type":"uint8"}],"name":"getAuthTokenContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBeaconProxyAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBuyerEscalationDepositPercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxEscalationResponsePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxResolutionPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxRoyaltyPercentage","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxTotalOfferFeePercentage","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinDisputePeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMinResolutionPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMutualizerGasStipend","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPriceDiscoveryAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_exchangeToken","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"getProtocolFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeFlatBoson","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_exchangeToken","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"getProtocolFeePercentage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"}],"name":"getProtocolFeeTable","outputs":[{"internalType":"uint256[]","name":"priceRanges","type":"uint256[]"},{"internalType":"uint256[]","name":"feePercentages","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTokenAddress","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTreasuryAddress","outputs":[{"internalType":"address payable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVoucherBeaconAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address payable","name":"treasury","type":"address"},{"internalType":"address payable","name":"token","type":"address"},{"internalType":"address","name":"voucherBeacon","type":"address"},{"internalType":"address","name":"beaconProxy","type":"address"},{"internalType":"address","name":"priceDiscovery","type":"address"}],"internalType":"struct ProtocolLib.ProtocolAddresses","name":"_addresses","type":"tuple"},{"components":[{"internalType":"uint256","name":"maxResolutionPeriod","type":"uint256"},{"internalType":"uint256","name":"maxEscalationResponsePeriod","type":"uint256"},{"internalType":"uint256","name":"minDisputePeriod","type":"uint256"},{"internalType":"uint16","name":"maxExchangesPerBatch","type":"uint16"},{"internalType":"uint16","name":"maxOffersPerGroup","type":"uint16"},{"internalType":"uint16","name":"maxOffersPerBundle","type":"uint16"},{"internalType":"uint16","name":"maxTwinsPerBundle","type":"uint16"},{"internalType":"uint16","name":"maxOffersPerBatch","type":"uint16"},{"internalType":"uint16","name":"maxTokensPerWithdrawal","type":"uint16"},{"internalType":"uint16","name":"maxFeesPerDisputeResolver","type":"uint16"},{"internalType":"uint16","name":"maxDisputesPerBatch","type":"uint16"},{"internalType":"uint16","name":"maxAllowedSellers","type":"uint16"},{"internalType":"uint16","name":"maxTotalOfferFeePercentage","type":"uint16"},{"internalType":"uint16","name":"maxRoyaltyPercentage","type":"uint16"},{"internalType":"uint256","name":"maxPremintedVouchers","type":"uint256"},{"internalType":"uint256","name":"minResolutionPeriod","type":"uint256"},{"internalType":"uint256","name":"mutualizerGasStipend","type":"uint256"}],"internalType":"struct ProtocolLib.ProtocolLimits","name":"_limits","type":"tuple"},{"internalType":"uint256","name":"defaultFeePercentage","type":"uint256"},{"internalType":"uint256","name":"flatBosonFee","type":"uint256"},{"internalType":"uint256","name":"buyerEscalationDepositPercentage","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_accessControllerAddress","type":"address"}],"name":"setAccessControllerAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum BosonTypes.AuthTokenType","name":"_authTokenType","type":"uint8"},{"internalType":"address","name":"_authTokenContract","type":"address"}],"name":"setAuthTokenContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_beaconProxyAddress","type":"address"}],"name":"setBeaconProxyAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_buyerEscalationDepositPercentage","type":"uint256"}],"name":"setBuyerEscalationDepositPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxEscalationResponsePeriod","type":"uint256"}],"name":"setMaxEscalationResponsePeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxResolutionPeriod","type":"uint256"}],"name":"setMaxResolutionPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_maxRoyaltyPercentage","type":"uint16"}],"name":"setMaxRoyaltyPercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_maxTotalOfferFeePercentage","type":"uint16"}],"name":"setMaxTotalOfferFeePercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minDisputePeriod","type":"uint256"}],"name":"setMinDisputePeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minResolutionPeriod","type":"uint256"}],"name":"setMinResolutionPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mutualizerGasStipend","type":"uint256"}],"name":"setMutualizerGasStipend","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_priceDiscovery","type":"address"}],"name":"setPriceDiscoveryAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeeFlatBoson","type":"uint256"}],"name":"setProtocolFeeFlatBoson","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeePercentage","type":"uint256"}],"name":"setProtocolFeePercentage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"uint256[]","name":"_priceRanges","type":"uint256[]"},{"internalType":"uint256[]","name":"_feePercentages","type":"uint256[]"}],"name":"setProtocolFeeTable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_tokenAddress","type":"address"}],"name":"setTokenAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"_treasuryAddress","type":"address"}],"name":"setTreasuryAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_voucherBeaconAddress","type":"address"}],"name":"setVoucherBeaconAddress","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60a060405234801561000f575f80fd5b506080516130a86100255f395f50506130a85ff3fe608060405234801561000f575f80fd5b5060043610610225575f3560e01c80636ba0f54511610135578063d3ab3d25116100b4578063e737643411610079578063e737643414610455578063eb04d54b14610468578063f8aaad6014610470578063f920fc1714610478578063fa5741eb1461048b575f80fd5b8063d3ab3d251461040c578063d3bdb70c14610414578063d8a5e93614610427578063dda575c91461043a578063e00246041461044d575f80fd5b8063938d1b27116100fa578063938d1b27146103ce5780639d273d67146103e1578063a4fbc18b146103e9578063be620a41146103fc578063c2f7379514610404575f80fd5b80636ba0f5451461037a5780636c2c13c21461038d5780636cb84158146103a0578063706d9f78146103b357806384a91ce6146103bb575f80fd5b806331cd131e116101c15780634dbcca7e116101865780634dbcca7e146103265780635123031414610339578063589e4e581461034c5780636605bfda1461035f578063694ca8ab14610372575f80fd5b806331cd131e146102d557806332cf96ff146102e857806336ee008c146102f057806337987b52146102f857806343024f0c1461030b575f80fd5b8063034594591461022957806307c1fdad1461023e57806310fe9ae8146102515780631adf8535146102765780631b57b63d1461028c578063217a2c7b1461029457806323bbe5d5146102a7578063250664d4146102af57806326a4e8d2146102c2575b5f80fd5b61023c6102373660046129c6565b6104ac565b005b61023c61024c366004612a43565b6106c5565b610259610830565b6040516001600160a01b0390911681526020015b60405180910390f35b61027e61084b565b60405190815260200161026d565b61027e61085d565b61027e6102a2366004612a65565b61086f565b61027e610883565b61023c6102bd366004612aa2565b610895565b61023c6102d0366004612a43565b610aa9565b61023c6102e3366004612a43565b610c14565b61027e610d7f565b61027e610d8e565b61023c610306366004612ad7565b610da0565b610313610ef1565b60405161ffff909116815260200161026d565b61023c610334366004612ad7565b610f0e565b61023c610347366004612aee565b611043565b61023c61035a366004612b4a565b61136e565b61023c61036d366004612a43565b6114d0565b610259611638565b61023c610388366004612ad7565b611653565b61025961039b366004612b6b565b611791565b61023c6103ae366004612a43565b6117f6565b61027e611961565b61023c6103c9366004612ad7565b61196a565b61023c6103dc366004612a43565b611aa8565b610259611c13565b61023c6103f7366004612b4a565b611c1c565b61027e611d8b565b610259611d94565b610313611daf565b61027e610422366004612a65565b611dcc565b61023c610435366004612ad7565b611dd7565b61023c610448366004612ad7565b611f12565b61025961208c565b61023c610463366004612ad7565b6120a4565b61027e6121e2565b6102596121eb565b61023c610486366004612ad7565b612206565b61049e610499366004612a43565b61236a565b60405161026d929190612bbe565b5f805160206130538339815191525f6104c3612458565b60048101549091506001600160a01b03166391d14854836104e261247c565b6040518363ffffffff1660e01b81526004016104ff929190612beb565b602060405180830381865afa15801561051a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061053e9190612c02565b61055b57604051634ca8886760e01b815260040160405180910390fd5b5f6105646124c0565b9050600281600101540361058b576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015561059a6124e4565b600101546001600160a01b03908116908916036105ca57604051630167f5d160e11b815260040160405180910390fd5b8584146105ea5760405163512509d360e11b815260040160405180910390fd5b6105f261250d565b6001600160a01b0389165f90815260039190910160205260408120610616916128ed565b61061e61250d565b6001600160a01b0389165f90815260049190910160205260408120610642916128ed565b851561065e57610653888888612531565b61065e8886866125d5565b61066661247c565b6001600160a01b0316886001600160a01b03167f65476810b2441ea9e5caeefc78d9cfcc0b2b15c2dad3a498acba199fefc3d19b898989896040516106ae9493929190612c51565b60405180910390a360019081015550505050505050565b5f805160206130538339815191525f6106dc612458565b60048101549091506001600160a01b03166391d14854836106fb61247c565b6040518363ffffffff1660e01b8152600401610718929190612beb565b602060405180830381865afa158015610733573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107579190612c02565b61077457604051634ca8886760e01b815260040160405180910390fd5b5f61077d6124c0565b905060028160010154036107a4576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556107b484612639565b836107bd6124e4565b60040180546001600160a01b0319166001600160a01b03929092169190911790556107e661247c565b6001600160a01b0316846001600160a01b03167f8a130a0fff3897853338565715010cc7605f4e32b8d5f71a0113a5052ea98a7a60405160405180910390a3600190810155505050565b5f6108396124e4565b600101546001600160a01b0316919050565b5f610854612663565b60060154905090565b5f610866612663565b60050154905090565b5f61087a8383612687565b90505b92915050565b5f61088c61250d565b60010154905090565b5f805160206130538339815191525f6108ac612458565b60048101549091506001600160a01b03166391d14854836108cb61247c565b6040518363ffffffff1660e01b81526004016108e8929190612beb565b602060405180830381865afa158015610903573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109279190612c02565b61094457604051634ca8886760e01b815260040160405180910390fd5b5f61094d6124c0565b90506002816001015403610974576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201555f85600381111561098e5761098e612c82565b14806109ab575060018560038111156109a9576109a9612c82565b145b156109c957604051630fb3eaf760e01b815260040160405180910390fd5b6109d284612639565b837f612ef4010290807451b703920dc633bec38eb4e2d0b1fda71d2a122f1b61c7de5f876003811115610a0757610a07612c82565b6003811115610a1857610a18612c82565b81526020019081526020015f205f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550610a5061247c565b6001600160a01b0316846001600160a01b0316866003811115610a7557610a75612c82565b6040517f6fe9bb0072dd1f9c4bb4935403936026442d864609e1cfad5d754922fb4d0663905f90a460019081015550505050565b5f805160206130538339815191525f610ac0612458565b60048101549091506001600160a01b03166391d1485483610adf61247c565b6040518363ffffffff1660e01b8152600401610afc929190612beb565b602060405180830381865afa158015610b17573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b3b9190612c02565b610b5857604051634ca8886760e01b815260040160405180910390fd5b5f610b616124c0565b90506002816001015403610b88576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610b9884612639565b83610ba16124e4565b60010180546001600160a01b0319166001600160a01b0392909216919091179055610bca61247c565b6001600160a01b0316846001600160a01b03167f5527f14e7199c63a0d6caffa1fd8eab9a6e595207bc2b23ae26a028acde7eefa60405160405180910390a3600190810155505050565b5f805160206130538339815191525f610c2b612458565b60048101549091506001600160a01b03166391d1485483610c4a61247c565b6040518363ffffffff1660e01b8152600401610c67929190612beb565b602060405180830381865afa158015610c82573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ca69190612c02565b610cc357604051634ca8886760e01b815260040160405180910390fd5b5f610ccc6124c0565b90506002816001015403610cf3576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610d0384612639565b83610d0c6124e4565b60030180546001600160a01b0319166001600160a01b0392909216919091179055610d3561247c565b6001600160a01b0316846001600160a01b03167f091b156afa8cca818dd039c7c3f89b50506ca010386165ba22726a26f9462ebc60405160405180910390a3600190810155505050565b5f610d88612663565b54919050565b5f610d9761250d565b60020154905090565b5f805160206130538339815191525f610db7612458565b60048101549091506001600160a01b03166391d1485483610dd661247c565b6040518363ffffffff1660e01b8152600401610df3929190612beb565b602060405180830381865afa158015610e0e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e329190612c02565b610e4f57604051634ca8886760e01b815260040160405180910390fd5b5f610e586124c0565b90506002816001015403610e7f576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610e8f846126d9565b83610e98612663565b60010155610ea461247c565b6001600160a01b03167fdaf0b2596ff6de0ff2f2059457a3959c9498ffd8608a5a308033733bf31803bc85604051610ede91815260200190565b60405180910390a2600190810155505050565b5f610efa612663565b60030154600160a01b900461ffff16919050565b5f805160206130538339815191525f610f25612458565b60048101549091506001600160a01b03166391d1485483610f4461247c565b6040518363ffffffff1660e01b8152600401610f61929190612beb565b602060405180830381865afa158015610f7c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fa09190612c02565b610fbd57604051634ca8886760e01b815260040160405180910390fd5b5f610fc66124c0565b90506002816001015403610fed576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015583610ffd61250d565b6001015561100961247c565b6001600160a01b03167fe654a39bc0740de992f2c0a4cd2f9d19aa844fdd818c8092ddd96af813e2066e85604051610ede91815260200190565b631442a8b760e01b5f6110546126f9565b6001600160e01b031983165f90815260028201602052604090205490915060ff16156110925760405162dc149f60e41b815260040160405180910390fd5b6001600160e01b031982165f9081526002820160205260409020805460ff191660011790556110c7631442a8b760e01b612702565b6110da6102d06040890160208a01612a43565b6110ea61036d6020890189612a43565b6110fd6103dc6060890160408a01612a43565b61111061024c60a0890160808a01612a43565b61111985611dd7565b61112284610f0e565b61112f8660200135610da0565b61113883611653565b61114d61035a6101a088016101808901612b4a565b6111626103f76101c088016101a08901612b4a565b61116c8635612206565b61117a866101e00135611f12565b611187866040013561196a565b6111958661020001356120a4565b60017f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497dd8181557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e28290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497df8290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e18290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497de8290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e0829055906112786126f9565b600101555f7f31a07027e17a7ce06ef5298187f6091b3997cff96797edc5bdc2504522a609f890506112ea6040518060400160405280600e81526020016d109bdcdbdb88141c9bdd1bd8dbdb60921b815250604051806040016040528060028152602001612b1960f11b815250612735565b600182015546600382015560405170426f736f6e566f756368657250726f787960781b60208201525f906031016040516020818303038152906040528051906020012060405161133990612908565b8190604051809103905ff5905080158015611356573d5f803e3d5ffd5b50905061136281610c14565b50505050505050505050565b5f805160206130538339815191525f611385612458565b60048101549091506001600160a01b03166391d14854836113a461247c565b6040518363ffffffff1660e01b81526004016113c1929190612beb565b602060405180830381865afa1580156113dc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114009190612c02565b61141d57604051634ca8886760e01b815260040160405180910390fd5b5f6114266124c0565b9050600281600101540361144d576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015561146161ffff85166127a4565b8361146a612663565b60030160126101000a81548161ffff021916908361ffff16021790555061148f61247c565b60405161ffff861681526001600160a01b0391909116907f50bd34612c542e1194f6440f08b631a2691b216a585196f4be04225e0ab7f69490602001610ede565b5f805160206130538339815191525f6114e7612458565b60048101549091506001600160a01b03166391d148548361150661247c565b6040518363ffffffff1660e01b8152600401611523929190612beb565b602060405180830381865afa15801561153e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115629190612c02565b61157f57604051634ca8886760e01b815260040160405180910390fd5b5f6115886124c0565b905060028160010154036115af576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556115bf84612639565b836115c86124e4565b80546001600160a01b0319166001600160a01b03929092169190911790556115ee61247c565b6001600160a01b0316846001600160a01b03167f4fc6e7a37aea21888550b60360992adb6a9b3b4da644d63e9f3a420c2d86e28260405160405180910390a3600190810155505050565b5f611641612458565b600401546001600160a01b0316919050565b5f805160206130538339815191525f61166a612458565b60048101549091506001600160a01b03166391d148548361168961247c565b6040518363ffffffff1660e01b81526004016116a6929190612beb565b602060405180830381865afa1580156116c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116e59190612c02565b61170257604051634ca8886760e01b815260040160405180910390fd5b5f61170b6124c0565b90506002816001015403611732576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611742846127a4565b8361174b61250d565b6002015561175761247c565b6001600160a01b03167f14fee7949d0858aa159e7e89ea1595a8dcf39e6f043d148cd32eafaa2552359c85604051610ede91815260200190565b5f7f612ef4010290807451b703920dc633bec38eb4e2d0b1fda71d2a122f1b61c7de818360038111156117c6576117c6612c82565b60038111156117d7576117d7612c82565b815260208101919091526040015f20546001600160a01b031692915050565b5f805160206130538339815191525f61180d612458565b60048101549091506001600160a01b03166391d148548361182c61247c565b6040518363ffffffff1660e01b8152600401611849929190612beb565b602060405180830381865afa158015611864573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118889190612c02565b6118a557604051634ca8886760e01b815260040160405180910390fd5b5f6118ae6124c0565b905060028160010154036118d5576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556118e584612639565b836118ee612458565b60040180546001600160a01b0319166001600160a01b039290921691909117905561191761247c565b6001600160a01b0316846001600160a01b03167f96cec8d5a50883757e1ca88ef9468357f6d9a17ca736caf9c2f2c2d67fe7bfe060405160405180910390a3600190810155505050565b5f610d8861250d565b5f805160206130538339815191525f611981612458565b60048101549091506001600160a01b03166391d14854836119a061247c565b6040518363ffffffff1660e01b81526004016119bd929190612beb565b602060405180830381865afa1580156119d8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119fc9190612c02565b611a1957604051634ca8886760e01b815260040160405180910390fd5b5f611a226124c0565b90506002816001015403611a49576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611a59846126d9565b83611a62612663565b60020155611a6e61247c565b6001600160a01b03167f79b8beaa3a6a3490d2195b336bde8f41b12591ff5d267a7c5e9a8352ecf45da085604051610ede91815260200190565b5f805160206130538339815191525f611abf612458565b60048101549091506001600160a01b03166391d1485483611ade61247c565b6040518363ffffffff1660e01b8152600401611afb929190612beb565b602060405180830381865afa158015611b16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3a9190612c02565b611b5757604051634ca8886760e01b815260040160405180910390fd5b5f611b606124c0565b90506002816001015403611b87576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611b9784612639565b83611ba06124e4565b60020180546001600160a01b0319166001600160a01b0392909216919091179055611bc961247c565b6001600160a01b0316846001600160a01b03167f64e226b4ce5e0bab1017d056b1d1f9412b8590d4a93c4c727751d6e1b35676a960405160405180910390a3600190810155505050565b5f6116416124e4565b5f805160206130538339815191525f611c33612458565b60048101549091506001600160a01b03166391d1485483611c5261247c565b6040518363ffffffff1660e01b8152600401611c6f929190612beb565b602060405180830381865afa158015611c8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cae9190612c02565b611ccb57604051634ca8886760e01b815260040160405180910390fd5b5f611cd46124c0565b90506002816001015403611cfb576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611d0f61ffff85166126d9565b611d1c8461ffff166127a4565b83611d25612663565b60030160146101000a81548161ffff021916908361ffff160217905550611d4a61247c565b60405161ffff861681526001600160a01b0391909116907f74785490a69046c69cacb602d5b56ec0663739188ee81c3c52541b22716a40af90602001610ede565b5f610d97612663565b5f611d9d6124e4565b600301546001600160a01b0316919050565b5f611db8612663565b60030154600160901b900461ffff16919050565b5f61087a83836127c7565b5f805160206130538339815191525f611dee612458565b60048101549091506001600160a01b03166391d1485483611e0d61247c565b6040518363ffffffff1660e01b8152600401611e2a929190612beb565b602060405180830381865afa158015611e45573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e699190612c02565b611e8657604051634ca8886760e01b815260040160405180910390fd5b5f611e8f6124c0565b90506002816001015403611eb6576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611ec6846127a4565b83611ecf61250d565b55611ed861247c565b6001600160a01b03167fa0df6dc233e4996f2cb1729e32435827291014b44fbf881504e5e5f01c9f875485604051610ede91815260200190565b5f805160206130538339815191525f611f29612458565b60048101549091506001600160a01b03166391d1485483611f4861247c565b6040518363ffffffff1660e01b8152600401611f65929190612beb565b602060405180830381865afa158015611f80573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fa49190612c02565b611fc157604051634ca8886760e01b815260040160405180910390fd5b5f611fca6124c0565b90506002816001015403611ff1576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155612001846126d9565b5f61200a612663565b805490915085111561202f5760405163b846227d60e01b815260040160405180910390fd5b6005810185905561203e61247c565b6001600160a01b03167fc282fd40a581150e1b868a2e17cc3ff6b63c78d18db02a12f00ca3414d3aa80c8660405161207891815260200190565b60405180910390a250600190810155505050565b5f6120956124e4565b546001600160a01b0316919050565b5f805160206130538339815191525f6120bb612458565b60048101549091506001600160a01b03166391d14854836120da61247c565b6040518363ffffffff1660e01b81526004016120f7929190612beb565b602060405180830381865afa158015612112573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121369190612c02565b61215357604051634ca8886760e01b815260040160405180910390fd5b5f61215c6124c0565b90506002816001015403612183576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155612193846126d9565b8361219c612663565b600601556121a861247c565b6001600160a01b03167f97b23925795a69237cf6f7ba127311aa242823510da6bd87a0cd56d574eb564285604051610ede91815260200190565b5f61088c612663565b5f6121f46124e4565b600201546001600160a01b0316919050565b5f805160206130538339815191525f61221d612458565b60048101549091506001600160a01b03166391d148548361223c61247c565b6040518363ffffffff1660e01b8152600401612259929190612beb565b602060405180830381865afa158015612274573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122989190612c02565b6122b557604051634ca8886760e01b815260040160405180910390fd5b5f6122be6124c0565b905060028160010154036122e5576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556122f5846126d9565b5f6122fe612663565b905080600501548510156123255760405163b846227d60e01b815260040160405180910390fd5b84815561233061247c565b6001600160a01b03167f913596d61a2425c70ecf382966312459e297c2e38c2096b337b40714e7d28b168660405161207891815260200190565b6060805f61237661250d565b6001600160a01b0385165f90815260038201602090815260409182902080548351818402810184019094528084529394509192908301828280156123d757602002820191905f5260205f20905b8154815260200190600101908083116123c3575b50505050509250806004015f856001600160a01b03166001600160a01b031681526020019081526020015f2080548060200260200160405190810160405280929190818152602001828054801561244b57602002820191905f5260205f20905b815481526020019060010190808311612437575b5050505050915050915091565b7fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c90565b5f36333014801561248e575060148110155b156124b5576124a3366013198301815f612c96565b6124ac91612cbd565b60601c91505090565b3391505090565b5090565b7fe7ad30265b8084c731e610579d091ebe2886115e8a5cacb6b704e4392f48b2c190565b7fcfefadf1e49ed481e9aa8b96a2b3ebd4043faf5a3594be1a1ff7f364fce11e7990565b905090565b7fcc61e6c6f125f3893e1d1fcb0479f4a7b78046e243532c7c469d64eccea5822190565b60015b8181101561259e578282612549600184612d06565b81811061255857612558612d19565b9050602002013583838381811061257157612571612d19565b905060200201351161259657604051635681624d60e01b815260040160405180910390fd5b600101612534565b5081816125a961250d565b6001600160a01b0386165f908152600391909101602052604090206125cf929091612915565b50505050565b5f5b81811015612608576126008383838181106125f4576125f4612d19565b905060200201356127a4565b6001016125d7565b50818161261361250d565b6001600160a01b0386165f908152600491909101602052604090206125cf929091612915565b6001600160a01b0381166126605760405163e6c4247b60e01b815260040160405180910390fd5b50565b7f9c28b7fe0f237f3704e965477183047b916eb4909df1acaccffe9bae8ff6e96e90565b5f6126906124e4565b600101546001600160a01b03908116908416036126ba576126af61250d565b60010154905061087d565b5f6126c584846127c7565b90506126d183826128b7565b949350505050565b805f03612660576040516302e2bfe760e01b815260040160405180910390fd5b5f6125086124c0565b5f61270b612458565b6001600160e01b03199092165f90815260039092016020525060409020805460ff19166001179055565b5f6040518060800160405280604f8152602001613004604f9139805160209182012084518583012084518584012060408051948501939093529183015260608201523060808201524660a082015260c00160405160208183030381529060405280519060200120905092915050565b6127108111156126605760405163390edff560e11b815260040160405180910390fd5b5f6127d06124e4565b600101546001600160a01b039081169084160361280057604051630167f5d160e11b815260040160405180910390fd5b5f61280961250d565b6001600160a01b0385165f9081526003820160209081526040808320600485019092529091208154929350909180156128ab575f5b600182038110156128995783818154811061285b5761285b612d19565b905f5260205f20015487116128915782818154811061287c5761287c612d19565b905f5260205f2001549550505050505061087d565b60010161283e565b82818154811061287c5761287c612d19565b50509054949350505050565b5f61271082036128c857508161087d565b815f036128d657505f61087d565b6127106128e38385612d2d565b61087a9190612d44565b5080545f8255905f5260205f20908101906126609190612956565b6102a080612d6483390190565b828054828255905f5260205f2090810192821561294e579160200282015b8281111561294e578235825591602001919060010190612933565b506124bc9291505b5b808211156124bc575f8155600101612957565b6001600160a01b0381168114612660575f80fd5b5f8083601f84011261298e575f80fd5b50813567ffffffffffffffff8111156129a5575f80fd5b6020830191508360208260051b85010111156129bf575f80fd5b9250929050565b5f805f805f606086880312156129da575f80fd5b85356129e58161296a565b9450602086013567ffffffffffffffff80821115612a01575f80fd5b612a0d89838a0161297e565b90965094506040880135915080821115612a25575f80fd5b50612a328882890161297e565b969995985093965092949392505050565b5f60208284031215612a53575f80fd5b8135612a5e8161296a565b9392505050565b5f8060408385031215612a76575f80fd5b8235612a818161296a565b946020939093013593505050565b803560048110612a9d575f80fd5b919050565b5f8060408385031215612ab3575f80fd5b612abc83612a8f565b91506020830135612acc8161296a565b809150509250929050565b5f60208284031215612ae7575f80fd5b5035919050565b5f805f805f858703610320811215612b04575f80fd5b60a0811215612b11575f80fd5b869550610220609f1982011215612b26575f80fd5b50939660a0860196506102c0860135956102e0810135955061030001359350915050565b5f60208284031215612b5a575f80fd5b813561ffff81168114612a5e575f80fd5b5f60208284031215612b7b575f80fd5b61087a82612a8f565b5f815180845260208085019450602084015f5b83811015612bb357815187529582019590820190600101612b97565b509495945050505050565b604081525f612bd06040830185612b84565b8281036020840152612be28185612b84565b95945050505050565b9182526001600160a01b0316602082015260400190565b5f60208284031215612c12575f80fd5b81518015158114612a5e575f80fd5b8183525f6001600160fb1b03831115612c38575f80fd5b8260051b80836020870137939093016020019392505050565b604081525f612c64604083018688612c21565b8281036020840152612c77818587612c21565b979650505050505050565b634e487b7160e01b5f52602160045260245ffd5b5f8085851115612ca4575f80fd5b83861115612cb0575f80fd5b5050820193919092039150565b6bffffffffffffffffffffffff198135818116916014851015612cea5780818660140360031b1b83161692505b505092915050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561087d5761087d612cf2565b634e487b7160e01b5f52603260045260245ffd5b808202811582820484141761087d5761087d612cf2565b5f82612d5e57634e487b7160e01b5f52601260045260245ffd5b50049056fe608060405234801561000f575f80fd5b506102838061001d5f395ff3fe608060405260043610610021575f3560e01c8063c4d66de81461003857610030565b366100305761002e610057565b005b61002e610057565b348015610043575f80fd5b5061002e610052366004610210565b610069565b610067610062610132565b61019f565b565b6100716101bd565b54600160a01b900460ff16156100e45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b806100ed6101bd565b80546001600160a01b0319166001600160a01b039290921691909117905560016101156101bd565b8054911515600160a01b0260ff60a01b1990921691909117905550565b5f61013b6101e1565b6001600160a01b031663aaf10f426040518163ffffffff1660e01b8152600401602060405180830381865afa158015610176573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019a9190610232565b905090565b365f80375f80365f845af43d5f803e8080156101b9573d5ff35b3d5ffd5b7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5090565b5f6101ea6101bd565b546001600160a01b0316919050565b6001600160a01b038116811461020d575f80fd5b50565b5f60208284031215610220575f80fd5b813561022b816101f9565b9392505050565b5f60208284031215610242575f80fd5b815161022b816101f956fea26469706673582212206b679c2bfd27fcf0c50d9a6f33327f9e0e1a5d03cf009f1151185af9e19071f364736f6c63430008160033454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c6164647265737320766572696679696e67436f6e74726163742c627974657333322073616c7429df8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42a2646970667358221220cb9d7ae61600afb12d2c6011be88b0ac51f402935a929ea21b6cc98d54d9b00764736f6c63430008160033
Deployed Bytecode
0x608060405234801561000f575f80fd5b5060043610610225575f3560e01c80636ba0f54511610135578063d3ab3d25116100b4578063e737643411610079578063e737643414610455578063eb04d54b14610468578063f8aaad6014610470578063f920fc1714610478578063fa5741eb1461048b575f80fd5b8063d3ab3d251461040c578063d3bdb70c14610414578063d8a5e93614610427578063dda575c91461043a578063e00246041461044d575f80fd5b8063938d1b27116100fa578063938d1b27146103ce5780639d273d67146103e1578063a4fbc18b146103e9578063be620a41146103fc578063c2f7379514610404575f80fd5b80636ba0f5451461037a5780636c2c13c21461038d5780636cb84158146103a0578063706d9f78146103b357806384a91ce6146103bb575f80fd5b806331cd131e116101c15780634dbcca7e116101865780634dbcca7e146103265780635123031414610339578063589e4e581461034c5780636605bfda1461035f578063694ca8ab14610372575f80fd5b806331cd131e146102d557806332cf96ff146102e857806336ee008c146102f057806337987b52146102f857806343024f0c1461030b575f80fd5b8063034594591461022957806307c1fdad1461023e57806310fe9ae8146102515780631adf8535146102765780631b57b63d1461028c578063217a2c7b1461029457806323bbe5d5146102a7578063250664d4146102af57806326a4e8d2146102c2575b5f80fd5b61023c6102373660046129c6565b6104ac565b005b61023c61024c366004612a43565b6106c5565b610259610830565b6040516001600160a01b0390911681526020015b60405180910390f35b61027e61084b565b60405190815260200161026d565b61027e61085d565b61027e6102a2366004612a65565b61086f565b61027e610883565b61023c6102bd366004612aa2565b610895565b61023c6102d0366004612a43565b610aa9565b61023c6102e3366004612a43565b610c14565b61027e610d7f565b61027e610d8e565b61023c610306366004612ad7565b610da0565b610313610ef1565b60405161ffff909116815260200161026d565b61023c610334366004612ad7565b610f0e565b61023c610347366004612aee565b611043565b61023c61035a366004612b4a565b61136e565b61023c61036d366004612a43565b6114d0565b610259611638565b61023c610388366004612ad7565b611653565b61025961039b366004612b6b565b611791565b61023c6103ae366004612a43565b6117f6565b61027e611961565b61023c6103c9366004612ad7565b61196a565b61023c6103dc366004612a43565b611aa8565b610259611c13565b61023c6103f7366004612b4a565b611c1c565b61027e611d8b565b610259611d94565b610313611daf565b61027e610422366004612a65565b611dcc565b61023c610435366004612ad7565b611dd7565b61023c610448366004612ad7565b611f12565b61025961208c565b61023c610463366004612ad7565b6120a4565b61027e6121e2565b6102596121eb565b61023c610486366004612ad7565b612206565b61049e610499366004612a43565b61236a565b60405161026d929190612bbe565b5f805160206130538339815191525f6104c3612458565b60048101549091506001600160a01b03166391d14854836104e261247c565b6040518363ffffffff1660e01b81526004016104ff929190612beb565b602060405180830381865afa15801561051a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061053e9190612c02565b61055b57604051634ca8886760e01b815260040160405180910390fd5b5f6105646124c0565b9050600281600101540361058b576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015561059a6124e4565b600101546001600160a01b03908116908916036105ca57604051630167f5d160e11b815260040160405180910390fd5b8584146105ea5760405163512509d360e11b815260040160405180910390fd5b6105f261250d565b6001600160a01b0389165f90815260039190910160205260408120610616916128ed565b61061e61250d565b6001600160a01b0389165f90815260049190910160205260408120610642916128ed565b851561065e57610653888888612531565b61065e8886866125d5565b61066661247c565b6001600160a01b0316886001600160a01b03167f65476810b2441ea9e5caeefc78d9cfcc0b2b15c2dad3a498acba199fefc3d19b898989896040516106ae9493929190612c51565b60405180910390a360019081015550505050505050565b5f805160206130538339815191525f6106dc612458565b60048101549091506001600160a01b03166391d14854836106fb61247c565b6040518363ffffffff1660e01b8152600401610718929190612beb565b602060405180830381865afa158015610733573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107579190612c02565b61077457604051634ca8886760e01b815260040160405180910390fd5b5f61077d6124c0565b905060028160010154036107a4576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556107b484612639565b836107bd6124e4565b60040180546001600160a01b0319166001600160a01b03929092169190911790556107e661247c565b6001600160a01b0316846001600160a01b03167f8a130a0fff3897853338565715010cc7605f4e32b8d5f71a0113a5052ea98a7a60405160405180910390a3600190810155505050565b5f6108396124e4565b600101546001600160a01b0316919050565b5f610854612663565b60060154905090565b5f610866612663565b60050154905090565b5f61087a8383612687565b90505b92915050565b5f61088c61250d565b60010154905090565b5f805160206130538339815191525f6108ac612458565b60048101549091506001600160a01b03166391d14854836108cb61247c565b6040518363ffffffff1660e01b81526004016108e8929190612beb565b602060405180830381865afa158015610903573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109279190612c02565b61094457604051634ca8886760e01b815260040160405180910390fd5b5f61094d6124c0565b90506002816001015403610974576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201555f85600381111561098e5761098e612c82565b14806109ab575060018560038111156109a9576109a9612c82565b145b156109c957604051630fb3eaf760e01b815260040160405180910390fd5b6109d284612639565b837f612ef4010290807451b703920dc633bec38eb4e2d0b1fda71d2a122f1b61c7de5f876003811115610a0757610a07612c82565b6003811115610a1857610a18612c82565b81526020019081526020015f205f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550610a5061247c565b6001600160a01b0316846001600160a01b0316866003811115610a7557610a75612c82565b6040517f6fe9bb0072dd1f9c4bb4935403936026442d864609e1cfad5d754922fb4d0663905f90a460019081015550505050565b5f805160206130538339815191525f610ac0612458565b60048101549091506001600160a01b03166391d1485483610adf61247c565b6040518363ffffffff1660e01b8152600401610afc929190612beb565b602060405180830381865afa158015610b17573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b3b9190612c02565b610b5857604051634ca8886760e01b815260040160405180910390fd5b5f610b616124c0565b90506002816001015403610b88576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610b9884612639565b83610ba16124e4565b60010180546001600160a01b0319166001600160a01b0392909216919091179055610bca61247c565b6001600160a01b0316846001600160a01b03167f5527f14e7199c63a0d6caffa1fd8eab9a6e595207bc2b23ae26a028acde7eefa60405160405180910390a3600190810155505050565b5f805160206130538339815191525f610c2b612458565b60048101549091506001600160a01b03166391d1485483610c4a61247c565b6040518363ffffffff1660e01b8152600401610c67929190612beb565b602060405180830381865afa158015610c82573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ca69190612c02565b610cc357604051634ca8886760e01b815260040160405180910390fd5b5f610ccc6124c0565b90506002816001015403610cf3576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610d0384612639565b83610d0c6124e4565b60030180546001600160a01b0319166001600160a01b0392909216919091179055610d3561247c565b6001600160a01b0316846001600160a01b03167f091b156afa8cca818dd039c7c3f89b50506ca010386165ba22726a26f9462ebc60405160405180910390a3600190810155505050565b5f610d88612663565b54919050565b5f610d9761250d565b60020154905090565b5f805160206130538339815191525f610db7612458565b60048101549091506001600160a01b03166391d1485483610dd661247c565b6040518363ffffffff1660e01b8152600401610df3929190612beb565b602060405180830381865afa158015610e0e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e329190612c02565b610e4f57604051634ca8886760e01b815260040160405180910390fd5b5f610e586124c0565b90506002816001015403610e7f576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155610e8f846126d9565b83610e98612663565b60010155610ea461247c565b6001600160a01b03167fdaf0b2596ff6de0ff2f2059457a3959c9498ffd8608a5a308033733bf31803bc85604051610ede91815260200190565b60405180910390a2600190810155505050565b5f610efa612663565b60030154600160a01b900461ffff16919050565b5f805160206130538339815191525f610f25612458565b60048101549091506001600160a01b03166391d1485483610f4461247c565b6040518363ffffffff1660e01b8152600401610f61929190612beb565b602060405180830381865afa158015610f7c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610fa09190612c02565b610fbd57604051634ca8886760e01b815260040160405180910390fd5b5f610fc66124c0565b90506002816001015403610fed576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015583610ffd61250d565b6001015561100961247c565b6001600160a01b03167fe654a39bc0740de992f2c0a4cd2f9d19aa844fdd818c8092ddd96af813e2066e85604051610ede91815260200190565b631442a8b760e01b5f6110546126f9565b6001600160e01b031983165f90815260028201602052604090205490915060ff16156110925760405162dc149f60e41b815260040160405180910390fd5b6001600160e01b031982165f9081526002820160205260409020805460ff191660011790556110c7631442a8b760e01b612702565b6110da6102d06040890160208a01612a43565b6110ea61036d6020890189612a43565b6110fd6103dc6060890160408a01612a43565b61111061024c60a0890160808a01612a43565b61111985611dd7565b61112284610f0e565b61112f8660200135610da0565b61113883611653565b61114d61035a6101a088016101808901612b4a565b6111626103f76101c088016101a08901612b4a565b61116c8635612206565b61117a866101e00135611f12565b611187866040013561196a565b6111958661020001356120a4565b60017f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497dd8181557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e28290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497df8290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e18290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497de8290557f236215f8ddaf4ac1232d1f2516766788cddc14962c93aafa73278d9e2e4497e0829055906112786126f9565b600101555f7f31a07027e17a7ce06ef5298187f6091b3997cff96797edc5bdc2504522a609f890506112ea6040518060400160405280600e81526020016d109bdcdbdb88141c9bdd1bd8dbdb60921b815250604051806040016040528060028152602001612b1960f11b815250612735565b600182015546600382015560405170426f736f6e566f756368657250726f787960781b60208201525f906031016040516020818303038152906040528051906020012060405161133990612908565b8190604051809103905ff5905080158015611356573d5f803e3d5ffd5b50905061136281610c14565b50505050505050505050565b5f805160206130538339815191525f611385612458565b60048101549091506001600160a01b03166391d14854836113a461247c565b6040518363ffffffff1660e01b81526004016113c1929190612beb565b602060405180830381865afa1580156113dc573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114009190612c02565b61141d57604051634ca8886760e01b815260040160405180910390fd5b5f6114266124c0565b9050600281600101540361144d576040516345f5ce8b60e11b815260040160405180910390fd5b6002600182015561146161ffff85166127a4565b8361146a612663565b60030160126101000a81548161ffff021916908361ffff16021790555061148f61247c565b60405161ffff861681526001600160a01b0391909116907f50bd34612c542e1194f6440f08b631a2691b216a585196f4be04225e0ab7f69490602001610ede565b5f805160206130538339815191525f6114e7612458565b60048101549091506001600160a01b03166391d148548361150661247c565b6040518363ffffffff1660e01b8152600401611523929190612beb565b602060405180830381865afa15801561153e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115629190612c02565b61157f57604051634ca8886760e01b815260040160405180910390fd5b5f6115886124c0565b905060028160010154036115af576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556115bf84612639565b836115c86124e4565b80546001600160a01b0319166001600160a01b03929092169190911790556115ee61247c565b6001600160a01b0316846001600160a01b03167f4fc6e7a37aea21888550b60360992adb6a9b3b4da644d63e9f3a420c2d86e28260405160405180910390a3600190810155505050565b5f611641612458565b600401546001600160a01b0316919050565b5f805160206130538339815191525f61166a612458565b60048101549091506001600160a01b03166391d148548361168961247c565b6040518363ffffffff1660e01b81526004016116a6929190612beb565b602060405180830381865afa1580156116c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116e59190612c02565b61170257604051634ca8886760e01b815260040160405180910390fd5b5f61170b6124c0565b90506002816001015403611732576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611742846127a4565b8361174b61250d565b6002015561175761247c565b6001600160a01b03167f14fee7949d0858aa159e7e89ea1595a8dcf39e6f043d148cd32eafaa2552359c85604051610ede91815260200190565b5f7f612ef4010290807451b703920dc633bec38eb4e2d0b1fda71d2a122f1b61c7de818360038111156117c6576117c6612c82565b60038111156117d7576117d7612c82565b815260208101919091526040015f20546001600160a01b031692915050565b5f805160206130538339815191525f61180d612458565b60048101549091506001600160a01b03166391d148548361182c61247c565b6040518363ffffffff1660e01b8152600401611849929190612beb565b602060405180830381865afa158015611864573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118889190612c02565b6118a557604051634ca8886760e01b815260040160405180910390fd5b5f6118ae6124c0565b905060028160010154036118d5576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556118e584612639565b836118ee612458565b60040180546001600160a01b0319166001600160a01b039290921691909117905561191761247c565b6001600160a01b0316846001600160a01b03167f96cec8d5a50883757e1ca88ef9468357f6d9a17ca736caf9c2f2c2d67fe7bfe060405160405180910390a3600190810155505050565b5f610d8861250d565b5f805160206130538339815191525f611981612458565b60048101549091506001600160a01b03166391d14854836119a061247c565b6040518363ffffffff1660e01b81526004016119bd929190612beb565b602060405180830381865afa1580156119d8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119fc9190612c02565b611a1957604051634ca8886760e01b815260040160405180910390fd5b5f611a226124c0565b90506002816001015403611a49576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611a59846126d9565b83611a62612663565b60020155611a6e61247c565b6001600160a01b03167f79b8beaa3a6a3490d2195b336bde8f41b12591ff5d267a7c5e9a8352ecf45da085604051610ede91815260200190565b5f805160206130538339815191525f611abf612458565b60048101549091506001600160a01b03166391d1485483611ade61247c565b6040518363ffffffff1660e01b8152600401611afb929190612beb565b602060405180830381865afa158015611b16573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3a9190612c02565b611b5757604051634ca8886760e01b815260040160405180910390fd5b5f611b606124c0565b90506002816001015403611b87576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611b9784612639565b83611ba06124e4565b60020180546001600160a01b0319166001600160a01b0392909216919091179055611bc961247c565b6001600160a01b0316846001600160a01b03167f64e226b4ce5e0bab1017d056b1d1f9412b8590d4a93c4c727751d6e1b35676a960405160405180910390a3600190810155505050565b5f6116416124e4565b5f805160206130538339815191525f611c33612458565b60048101549091506001600160a01b03166391d1485483611c5261247c565b6040518363ffffffff1660e01b8152600401611c6f929190612beb565b602060405180830381865afa158015611c8a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cae9190612c02565b611ccb57604051634ca8886760e01b815260040160405180910390fd5b5f611cd46124c0565b90506002816001015403611cfb576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611d0f61ffff85166126d9565b611d1c8461ffff166127a4565b83611d25612663565b60030160146101000a81548161ffff021916908361ffff160217905550611d4a61247c565b60405161ffff861681526001600160a01b0391909116907f74785490a69046c69cacb602d5b56ec0663739188ee81c3c52541b22716a40af90602001610ede565b5f610d97612663565b5f611d9d6124e4565b600301546001600160a01b0316919050565b5f611db8612663565b60030154600160901b900461ffff16919050565b5f61087a83836127c7565b5f805160206130538339815191525f611dee612458565b60048101549091506001600160a01b03166391d1485483611e0d61247c565b6040518363ffffffff1660e01b8152600401611e2a929190612beb565b602060405180830381865afa158015611e45573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611e699190612c02565b611e8657604051634ca8886760e01b815260040160405180910390fd5b5f611e8f6124c0565b90506002816001015403611eb6576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155611ec6846127a4565b83611ecf61250d565b55611ed861247c565b6001600160a01b03167fa0df6dc233e4996f2cb1729e32435827291014b44fbf881504e5e5f01c9f875485604051610ede91815260200190565b5f805160206130538339815191525f611f29612458565b60048101549091506001600160a01b03166391d1485483611f4861247c565b6040518363ffffffff1660e01b8152600401611f65929190612beb565b602060405180830381865afa158015611f80573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fa49190612c02565b611fc157604051634ca8886760e01b815260040160405180910390fd5b5f611fca6124c0565b90506002816001015403611ff1576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155612001846126d9565b5f61200a612663565b805490915085111561202f5760405163b846227d60e01b815260040160405180910390fd5b6005810185905561203e61247c565b6001600160a01b03167fc282fd40a581150e1b868a2e17cc3ff6b63c78d18db02a12f00ca3414d3aa80c8660405161207891815260200190565b60405180910390a250600190810155505050565b5f6120956124e4565b546001600160a01b0316919050565b5f805160206130538339815191525f6120bb612458565b60048101549091506001600160a01b03166391d14854836120da61247c565b6040518363ffffffff1660e01b81526004016120f7929190612beb565b602060405180830381865afa158015612112573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121369190612c02565b61215357604051634ca8886760e01b815260040160405180910390fd5b5f61215c6124c0565b90506002816001015403612183576040516345f5ce8b60e11b815260040160405180910390fd5b60026001820155612193846126d9565b8361219c612663565b600601556121a861247c565b6001600160a01b03167f97b23925795a69237cf6f7ba127311aa242823510da6bd87a0cd56d574eb564285604051610ede91815260200190565b5f61088c612663565b5f6121f46124e4565b600201546001600160a01b0316919050565b5f805160206130538339815191525f61221d612458565b60048101549091506001600160a01b03166391d148548361223c61247c565b6040518363ffffffff1660e01b8152600401612259929190612beb565b602060405180830381865afa158015612274573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122989190612c02565b6122b557604051634ca8886760e01b815260040160405180910390fd5b5f6122be6124c0565b905060028160010154036122e5576040516345f5ce8b60e11b815260040160405180910390fd5b600260018201556122f5846126d9565b5f6122fe612663565b905080600501548510156123255760405163b846227d60e01b815260040160405180910390fd5b84815561233061247c565b6001600160a01b03167f913596d61a2425c70ecf382966312459e297c2e38c2096b337b40714e7d28b168660405161207891815260200190565b6060805f61237661250d565b6001600160a01b0385165f90815260038201602090815260409182902080548351818402810184019094528084529394509192908301828280156123d757602002820191905f5260205f20905b8154815260200190600101908083116123c3575b50505050509250806004015f856001600160a01b03166001600160a01b031681526020019081526020015f2080548060200260200160405190810160405280929190818152602001828054801561244b57602002820191905f5260205f20905b815481526020019060010190808311612437575b5050505050915050915091565b7fc8fcad8db84d3cc18b4c41d551ea0ee66dd599cde068d998e57d5e09332c131c90565b5f36333014801561248e575060148110155b156124b5576124a3366013198301815f612c96565b6124ac91612cbd565b60601c91505090565b3391505090565b5090565b7fe7ad30265b8084c731e610579d091ebe2886115e8a5cacb6b704e4392f48b2c190565b7fcfefadf1e49ed481e9aa8b96a2b3ebd4043faf5a3594be1a1ff7f364fce11e7990565b905090565b7fcc61e6c6f125f3893e1d1fcb0479f4a7b78046e243532c7c469d64eccea5822190565b60015b8181101561259e578282612549600184612d06565b81811061255857612558612d19565b9050602002013583838381811061257157612571612d19565b905060200201351161259657604051635681624d60e01b815260040160405180910390fd5b600101612534565b5081816125a961250d565b6001600160a01b0386165f908152600391909101602052604090206125cf929091612915565b50505050565b5f5b81811015612608576126008383838181106125f4576125f4612d19565b905060200201356127a4565b6001016125d7565b50818161261361250d565b6001600160a01b0386165f908152600491909101602052604090206125cf929091612915565b6001600160a01b0381166126605760405163e6c4247b60e01b815260040160405180910390fd5b50565b7f9c28b7fe0f237f3704e965477183047b916eb4909df1acaccffe9bae8ff6e96e90565b5f6126906124e4565b600101546001600160a01b03908116908416036126ba576126af61250d565b60010154905061087d565b5f6126c584846127c7565b90506126d183826128b7565b949350505050565b805f03612660576040516302e2bfe760e01b815260040160405180910390fd5b5f6125086124c0565b5f61270b612458565b6001600160e01b03199092165f90815260039092016020525060409020805460ff19166001179055565b5f6040518060800160405280604f8152602001613004604f9139805160209182012084518583012084518584012060408051948501939093529183015260608201523060808201524660a082015260c00160405160208183030381529060405280519060200120905092915050565b6127108111156126605760405163390edff560e11b815260040160405180910390fd5b5f6127d06124e4565b600101546001600160a01b039081169084160361280057604051630167f5d160e11b815260040160405180910390fd5b5f61280961250d565b6001600160a01b0385165f9081526003820160209081526040808320600485019092529091208154929350909180156128ab575f5b600182038110156128995783818154811061285b5761285b612d19565b905f5260205f20015487116128915782818154811061287c5761287c612d19565b905f5260205f2001549550505050505061087d565b60010161283e565b82818154811061287c5761287c612d19565b50509054949350505050565b5f61271082036128c857508161087d565b815f036128d657505f61087d565b6127106128e38385612d2d565b61087a9190612d44565b5080545f8255905f5260205f20908101906126609190612956565b6102a080612d6483390190565b828054828255905f5260205f2090810192821561294e579160200282015b8281111561294e578235825591602001919060010190612933565b506124bc9291505b5b808211156124bc575f8155600101612957565b6001600160a01b0381168114612660575f80fd5b5f8083601f84011261298e575f80fd5b50813567ffffffffffffffff8111156129a5575f80fd5b6020830191508360208260051b85010111156129bf575f80fd5b9250929050565b5f805f805f606086880312156129da575f80fd5b85356129e58161296a565b9450602086013567ffffffffffffffff80821115612a01575f80fd5b612a0d89838a0161297e565b90965094506040880135915080821115612a25575f80fd5b50612a328882890161297e565b969995985093965092949392505050565b5f60208284031215612a53575f80fd5b8135612a5e8161296a565b9392505050565b5f8060408385031215612a76575f80fd5b8235612a818161296a565b946020939093013593505050565b803560048110612a9d575f80fd5b919050565b5f8060408385031215612ab3575f80fd5b612abc83612a8f565b91506020830135612acc8161296a565b809150509250929050565b5f60208284031215612ae7575f80fd5b5035919050565b5f805f805f858703610320811215612b04575f80fd5b60a0811215612b11575f80fd5b869550610220609f1982011215612b26575f80fd5b50939660a0860196506102c0860135956102e0810135955061030001359350915050565b5f60208284031215612b5a575f80fd5b813561ffff81168114612a5e575f80fd5b5f60208284031215612b7b575f80fd5b61087a82612a8f565b5f815180845260208085019450602084015f5b83811015612bb357815187529582019590820190600101612b97565b509495945050505050565b604081525f612bd06040830185612b84565b8281036020840152612be28185612b84565b95945050505050565b9182526001600160a01b0316602082015260400190565b5f60208284031215612c12575f80fd5b81518015158114612a5e575f80fd5b8183525f6001600160fb1b03831115612c38575f80fd5b8260051b80836020870137939093016020019392505050565b604081525f612c64604083018688612c21565b8281036020840152612c77818587612c21565b979650505050505050565b634e487b7160e01b5f52602160045260245ffd5b5f8085851115612ca4575f80fd5b83861115612cb0575f80fd5b5050820193919092039150565b6bffffffffffffffffffffffff198135818116916014851015612cea5780818660140360031b1b83161692505b505092915050565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561087d5761087d612cf2565b634e487b7160e01b5f52603260045260245ffd5b808202811582820484141761087d5761087d612cf2565b5f82612d5e57634e487b7160e01b5f52601260045260245ffd5b50049056fe608060405234801561000f575f80fd5b506102838061001d5f395ff3fe608060405260043610610021575f3560e01c8063c4d66de81461003857610030565b366100305761002e610057565b005b61002e610057565b348015610043575f80fd5b5061002e610052366004610210565b610069565b610067610062610132565b61019f565b565b6100716101bd565b54600160a01b900460ff16156100e45760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b606482015260840160405180910390fd5b806100ed6101bd565b80546001600160a01b0319166001600160a01b039290921691909117905560016101156101bd565b8054911515600160a01b0260ff60a01b1990921691909117905550565b5f61013b6101e1565b6001600160a01b031663aaf10f426040518163ffffffff1660e01b8152600401602060405180830381865afa158015610176573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019a9190610232565b905090565b365f80375f80365f845af43d5f803e8080156101b9573d5ff35b3d5ffd5b7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5090565b5f6101ea6101bd565b546001600160a01b0316919050565b6001600160a01b038116811461020d575f80fd5b50565b5f60208284031215610220575f80fd5b813561022b816101f9565b9392505050565b5f60208284031215610242575f80fd5b815161022b816101f956fea26469706673582212206b679c2bfd27fcf0c50d9a6f33327f9e0e1a5d03cf009f1151185af9e19071f364736f6c63430008160033454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c6164647265737320766572696679696e67436f6e74726163742c627974657333322073616c7429df8b4c520ffe197c5343c6f5aec59570151ef9a492f2c624fd45ddde6135ec42a2646970667358221220cb9d7ae61600afb12d2c6011be88b0ac51f402935a929ea21b6cc98d54d9b00764736f6c63430008160033
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.