Skip to content

Commit

Permalink
Merge branch 'main' into createTwin_inefficiencies
Browse files Browse the repository at this point in the history
  • Loading branch information
anajuliabit committed Jul 6, 2023
2 parents ab55825 + 7cf35c4 commit 1555bc4
Show file tree
Hide file tree
Showing 156 changed files with 13,610 additions and 10,628 deletions.
14 changes: 6 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"extends": [
"eslint:recommended",
"prettier"
],
"extends": ["eslint:recommended", "prettier"],
"env": {
"node": true,
"es6": true,
"es2020": true,
"commonjs": true,
"mocha": true
},
Expand All @@ -17,7 +14,8 @@
"no-empty": "off",
"no-only-tests/no-only-tests": "error"
},
"plugins": [
"no-only-tests"
]
"plugins": ["no-only-tests"],
"globals": {
"BigInt": true
}
}
62 changes: 31 additions & 31 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,34 @@ jobs:
if: failure()
uses: andymckay/cancel-action@0.2

analyze:
needs: setup
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3.1.0
- name: Setup node
uses: actions/setup-node@v3.5.1
with:
node-version: 16.14.x
cache: "npm"
- name: Install Dependencies
run: npm install
- name: Prepare Environment
shell: bash
run: |
cp .env.example .env
- name: Slither analyzer
uses: crytic/slither-action@v0.3.0
id: slither
with:
node-version: 16
sarif: results.sarif
fail-on: none
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
# analyze:
# needs: setup
# runs-on: ubuntu-latest
# permissions:
# contents: read
# security-events: write
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3.1.0
# - name: Setup node
# uses: actions/setup-node@v3.5.1
# with:
# node-version: 16.14.x
# cache: "npm"
# - name: Install Dependencies
# run: npm install
# - name: Prepare Environment
# shell: bash
# run: |
# cp .env.example .env
# - name: Slither analyzer
# uses: crytic/slither-action@v0.3.0
# id: slither
# with:
# node-version: 16
# sarif: results.sarif
# fail-on: none
# - name: Upload SARIF file
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: ${{ steps.slither.outputs.sarif }}
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

find . -name '*.js' -not -path '*/node_modules/*' | xargs git diff --cached --name-only | xargs -r npx eslint --fix
find . -name '*.js' -not -path '*/node_modules/*' | xargs git diff --cached --name-only | xargs -r npx prettier --write
git diff --cached --name-only | grep -e contracts -e *.txt | xargs -r npx solhint --fix
git diff --cached --name-only | grep -e contracts -e *.txt | xargs -r npx prettier --write
git diff --cached --name-only | grep -e ^contracts -e sol$ | xargs -r npx solhint --fix
git diff --cached --name-only | grep -e ^contracts -e sol$ | xargs -r npx prettier --write
npm run natspec-interface-id:fix
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<h1 align="center">Boson Protocol V2</h1>

[![Coverage Status](https://coveralls.io/repos/github/bosonprotocol/boson-protocol-contracts/badge.svg)](https://coveralls.io/github/bosonprotocol/boson-protocol-contracts)
[![Contracts CI](https://github.com/bosonprotocol/boson-protocol-contracts/actions/workflows/ci.yaml/badge.svg)](https://github.com/bosonprotocol/boson-protocol-contracts/actions/workflows/ci.yaml)

### Intro | [Audits](docs/audits.md) | [Setup](docs/setup.md) | [Tasks](docs/tasks.md) | [Architecture](docs/architecture.md) | [Domain Model](docs/domain.md) | [State Machines](docs/state-machines.md) | [Sequences](docs/sequences.md)

Expand Down
29 changes: 17 additions & 12 deletions contracts/domain/BosonConstants.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./BosonTypes.sol";

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;

Expand All @@ -10,12 +12,11 @@ bytes32 constant UPGRADER = keccak256("UPGRADER"); // Role for performing contra
bytes32 constant FEE_COLLECTOR = keccak256("FEE_COLLECTOR"); // Role for collecting fees from the protocol

// Revert Reasons: Pause related
string constant NO_REGIONS_SPECIFIED = "Must specify at least one region to pause";
string constant REGION_DUPLICATED = "A region may only be specified once";
string constant ALREADY_PAUSED = "Protocol is already paused";
string constant NOT_PAUSED = "Protocol is not currently paused";
string constant REGION_PAUSED = "This region of the protocol is currently paused";

uint256 constant ALL_REGIONS_MASK = (1 << (uint256(type(BosonTypes.PausableRegion).max) + 1)) - 1;

// Revert Reasons: General
string constant INVALID_ADDRESS = "Invalid address";
string constant INVALID_STATE = "Invalid state";
Expand Down Expand Up @@ -59,13 +60,13 @@ string constant NO_SUCH_AGENT = "No such agent";
string constant WALLET_OWNS_VOUCHERS = "Wallet address owns vouchers";
string constant NO_SUCH_DISPUTE_RESOLVER = "No such dispute resolver";
string constant INVALID_ESCALATION_PERIOD = "Invalid escalation period";
string constant INVALID_AMOUNT_DISPUTE_RESOLVER_FEES = "Dispute resolver fees are not present or exceed maximum dispute resolver fees in a single transaction";
string constant INEXISTENT_DISPUTE_RESOLVER_FEES = "Dispute resolver fees are not present";
string constant DUPLICATE_DISPUTE_RESOLVER_FEES = "Duplicate dispute resolver fee";
string constant FEE_AMOUNT_NOT_YET_SUPPORTED = "Non-zero dispute resolver fees not yet supported";
string constant DISPUTE_RESOLVER_FEE_NOT_FOUND = "Dispute resolver fee not found";
string constant SELLER_ALREADY_APPROVED = "Seller id is approved already";
string constant SELLER_NOT_APPROVED = "Seller id is not approved";
string constant INVALID_AMOUNT_ALLOWED_SELLERS = "Allowed sellers are not present or exceed maximum allowed sellers in a single transaction";
string constant INEXISTENT_ALLOWED_SELLERS_LIST = "Allowed sellers are not present";
string constant INVALID_AUTH_TOKEN_TYPE = "Invalid AuthTokenType";
string constant ADMIN_OR_AUTH_TOKEN = "An admin address or an auth token is required";
string constant AUTH_TOKEN_MUST_BE_UNIQUE = "Auth token cannot be assigned to another entity of the same type";
Expand Down Expand Up @@ -94,13 +95,19 @@ string constant INVALID_DISPUTE_RESOLVER = "Invalid dispute resolver";
string constant INVALID_QUANTITY_AVAILABLE = "Invalid quantity available";
string constant DR_UNSUPPORTED_FEE = "Dispute resolver does not accept this token";
string constant AGENT_FEE_AMOUNT_TOO_HIGH = "Sum of agent fee amount and protocol fee amount should be <= offer fee limit";
string constant NO_SUCH_COLLECTION = "No such collection";

// Revert Reasons: Group related
string constant NO_SUCH_GROUP = "No such group";
string constant OFFER_NOT_IN_GROUP = "Offer not part of the group";
string constant TOO_MANY_OFFERS = "Exceeded maximum offers in a single transaction";
string constant NOTHING_UPDATED = "Nothing updated";
string constant INVALID_CONDITION_PARAMETERS = "Invalid condition parameters";
string constant GROUP_HAS_NO_CONDITION = "Offer belongs to a group without a condition. Use commitToOffer instead";
string constant GROUP_HAS_CONDITION = "Offer belongs to a group with a condition. Use commitToConditionalOffer instead";
string constant MAX_COMMITS_ADDRESS_REACHED = "Max commits per address reached";
string constant MAX_COMMITS_TOKEN_REACHED = "Max commits per token id reached";
string constant TOKEN_ID_NOT_IN_CONDITION_RANGE = "Token id not in condition range";
string constant INVALID_TOKEN_ID = "ERC721 and ERC20 require zero tokenId";

// Revert Reasons: Exchange related
string constant NO_SUCH_EXCHANGE = "No such exchange";
Expand All @@ -109,12 +116,13 @@ string constant VOUCHER_NOT_REDEEMABLE = "Voucher not yet valid or already expir
string constant VOUCHER_EXTENSION_NOT_VALID = "Proposed date is not later than the current one";
string constant VOUCHER_STILL_VALID = "Voucher still valid";
string constant VOUCHER_HAS_EXPIRED = "Voucher has expired";
string constant TOO_MANY_EXCHANGES = "Exceeded maximum exchanges in a single transaction";
string constant EXCHANGE_IS_NOT_IN_A_FINAL_STATE = "Exchange is not in a final state";
string constant EXCHANGE_ALREADY_EXISTS = "Exchange already exists";
string constant INVALID_RANGE_LENGTH = "Range length is too large or zero";

// Revert Reasons: Twin related
uint256 constant SINGLE_TWIN_RESERVED_GAS = 140000;
uint256 constant MINIMAL_RESIDUAL_GAS = 180000;
string constant NO_SUCH_TWIN = "No such twin";
string constant NO_TRANSFER_APPROVED = "No transfer approved";
string constant TWIN_TRANSFER_FAILED = "Twin could not be transferred";
Expand All @@ -130,7 +138,6 @@ string constant INVALID_TOKEN_ADDRESS = "Token address is a contract that doesn'
string constant NO_SUCH_BUNDLE = "No such bundle";
string constant TWIN_NOT_IN_BUNDLE = "Twin not part of the bundle";
string constant OFFER_NOT_IN_BUNDLE = "Offer not part of the bundle";
string constant TOO_MANY_TWINS = "Exceeded maximum twins in a single transaction";
string constant BUNDLE_OFFER_MUST_BE_UNIQUE = "Offer must be unique to a bundle";
string constant BUNDLE_TWIN_MUST_BE_UNIQUE = "Twin must be unique to a bundle";
string constant EXCHANGE_FOR_BUNDLED_OFFERS_EXISTS = "Exchange for the bundled offers exists";
Expand All @@ -142,7 +149,6 @@ string constant NATIVE_WRONG_ADDRESS = "Native token address must be 0";
string constant NATIVE_WRONG_AMOUNT = "Transferred value must match amount";
string constant TOKEN_NAME_UNSPECIFIED = "Token name unspecified";
string constant NATIVE_CURRENCY = "Native currency";
string constant TOO_MANY_TOKENS = "Too many tokens";
string constant TOKEN_AMOUNT_MISMATCH = "Number of amounts should match number of tokens";
string constant NOTHING_TO_WITHDRAW = "Nothing to withdraw";
string constant NOT_AUTHORIZED = "Not authorized to withdraw";
Expand All @@ -165,7 +171,6 @@ string constant DISPUTE_HAS_EXPIRED = "Dispute has expired";
string constant INVALID_BUYER_PERCENT = "Invalid buyer percent";
string constant DISPUTE_STILL_VALID = "Dispute still valid";
string constant INVALID_DISPUTE_TIMEOUT = "Invalid dispute timeout";
string constant TOO_MANY_DISPUTES = "Exceeded maximum disputes in a single transaction";
string constant ESCALATION_NOT_ALLOWED = "Disputes without dispute resolver cannot be escalated";

// Revert Reasons: Config related
Expand All @@ -188,15 +193,15 @@ string constant OFFER_RANGE_ALREADY_RESERVED = "Offer id already associated with
string constant INVALID_RANGE_START = "Range start too low";
string constant INVALID_AMOUNT_TO_MINT = "Amount to mint is greater than remaining un-minted in range";
string constant NO_SILENT_MINT_ALLOWED = "Only owner's mappings can be updated without event";
string constant TOO_MANY_TO_MINT = "Exceeded maximum amount to mint in a single transaction";
string constant OFFER_EXPIRED_OR_VOIDED = "Offer expired or voided";
string constant OFFER_STILL_VALID = "Offer still valid";
string constant NOTHING_TO_BURN = "Nothing to burn";
string constant AMOUNT_EXCEEDS_RANGE_OR_NOTHING_TO_BURN = "Amount exceeds the range or there is nothing to burn";
string constant OWNABLE_ZERO_ADDRESS = "Ownable: new owner is the zero address";
string constant ROYALTY_FEE_INVALID = "ERC2981: royalty fee exceeds protocol limit";
string constant NOT_COMMITTABLE = "Token not committable";
string constant INVALID_TO_ADDRESS = "Tokens can only be pre-mined to the contract or contract owner address";
string constant EXTERNAL_CALL_FAILED = "External call failed";
string constant ERC721_INVALID_TOKEN_ID = "ERC721: invalid token ID";

// Meta Transactions - Structs
bytes32 constant META_TRANSACTION_TYPEHASH = keccak256(
Expand Down
7 changes: 7 additions & 0 deletions contracts/domain/BosonTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ contract BosonTypes {
string metadataUri;
string metadataHash;
bool voided;
uint256 collectionIndex;
}

struct OfferDates {
Expand Down Expand Up @@ -174,6 +175,7 @@ contract BosonTypes {
uint256 tokenId;
uint256 threshold;
uint256 maxCommits;
uint256 length;
}

struct Exchange {
Expand Down Expand Up @@ -285,4 +287,9 @@ contract BosonTypes {
string contractURI;
uint256 royaltyPercentage;
}

struct Collection {
address collectionAddress;
string externalId;
}
}
4 changes: 2 additions & 2 deletions contracts/example/SnapshotGate/SnapshotGate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ contract SnapshotGate is BosonTypes, Ownable, ERC721 {
require(msg.value == offer.price, "Incorrect payment amount");

// Commit to the offer, passing the message value (native)
IBosonExchangeHandler(protocol).commitToOffer{ value: msg.value }(_buyer, _offerId);
IBosonExchangeHandler(protocol).commitToConditionalOffer{ value: msg.value }(_buyer, _offerId, _tokenId);
} else {
// Transfer the price into custody of this contract and approve protocol to transfer
transferFundsToGateAndApproveProtocol(offer.exchangeToken, offer.price);

// Commit to the offer on behalf of the buyer
IBosonExchangeHandler(protocol).commitToOffer(_buyer, _offerId);
IBosonExchangeHandler(protocol).commitToConditionalOffer(_buyer, _offerId, _tokenId);
}

// Remove the transaction details
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IInitializableVoucherClone.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ interface IInitializableVoucherClone {
* @notice Initializes a voucher with the given parameters.
*
* @param _sellerId - The ID of the seller.
* @param _collectionIndex - The index of the collection.
* @param _newOwner - The address of the new owner.
* @param _voucherInitValues - The voucher initialization values.
*/
function initializeVoucher(
uint256 _sellerId,
uint256 _collectionIndex,
address _newOwner,
BosonTypes.VoucherInitValues calldata _voucherInitValues
) external;
Expand Down
8 changes: 5 additions & 3 deletions contracts/interfaces/clients/IBosonVoucher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IERC721ReceiverUpgradeable } from "@openzeppelin/contracts-upgradeable/
*
* @notice This is the interface for the Boson Protocol ERC-721 Voucher contract.
*
* The ERC-165 identifier for this interface is: 0xaf16da6e
* The ERC-165 identifier for this interface is: 0x5235dd2b
*/
interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable, IERC721ReceiverUpgradeable {
event ContractURIChanged(string contractURI);
Expand Down Expand Up @@ -189,8 +189,9 @@ interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable, IERC7
* - There is nothing to burn
*
* @param _offerId - the id of the offer
* @param _amount - amount to burn
*/
function burnPremintedVouchers(uint256 _offerId) external;
function burnPremintedVouchers(uint256 _offerId, uint256 _amount) external;

/**
* @notice Gets the number of vouchers available to be pre-minted for an offer.
Expand Down Expand Up @@ -219,8 +220,9 @@ interface IBosonVoucher is IERC721Upgradeable, IERC721MetadataUpgradeable, IERC7
*
* @param _to - address of the contract to call
* @param _data - data to pass to the external contract
* @return result - result of the call
*/
function callExternalContract(address _to, bytes memory _data) external payable;
function callExternalContract(address _to, bytes memory _data) external payable returns (bytes memory);

/** @notice Set approval for all to the vouchers owned by this contract
*
Expand Down
7 changes: 7 additions & 0 deletions contracts/interfaces/events/IBosonAccountEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ interface IBosonAccountEvents {
address indexed executedBy
);
event AgentCreated(uint256 indexed agentId, BosonTypes.Agent agent, address indexed executedBy);
event CollectionCreated(
uint256 indexed sellerId,
uint256 collectionIndex,
address collectionAddress,
string indexed externalId,
address indexed executedBy
);
}
10 changes: 1 addition & 9 deletions contracts/interfaces/events/IBosonConfigEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ interface IBosonConfigEvents {
event BeaconProxyAddressChanged(address indexed beaconProxyAddress, address indexed executedBy);
event ProtocolFeePercentageChanged(uint256 feePercentage, address indexed executedBy);
event ProtocolFeeFlatBosonChanged(uint256 feeFlatBoson, address indexed executedBy);
event MaxExchangesPerBatchChanged(uint16 maxExchangesPerBatch, address indexed executedBy);
event MaxOffersPerGroupChanged(uint16 maxOffersPerGroup, address indexed executedBy);
event MaxOffersPerBatchChanged(uint16 maxOffersPerBatch, address indexed executedBy);
event MaxTwinsPerBundleChanged(uint16 maxTwinsPerBundle, address indexed executedBy);
event MaxOffersPerBundleChanged(uint16 maxOffersPerBundle, address indexed executedBy);
event MaxTokensPerWithdrawalChanged(uint16 maxTokensPerWithdrawal, address indexed executedBy);
event MaxFeesPerDisputeResolverChanged(uint16 maxFeesPerDisputeResolver, address indexed executedBy);
event MaxEscalationResponsePeriodChanged(uint256 maxEscalationResponsePeriod, address indexed executedBy);
event MaxDisputesPerBatchChanged(uint16 maxDisputesPerBatch, address indexed executedBy);
event MaxAllowedSellersChanged(uint16 maxAllowedSellers, address indexed executedBy);
event BuyerEscalationFeePercentageChanged(uint256 buyerEscalationFeePercentage, address indexed executedBy);
event AuthTokenContractChanged(
BosonTypes.AuthTokenType indexed authTokenType,
Expand All @@ -33,6 +24,7 @@ interface IBosonConfigEvents {
);
event MaxTotalOfferFeePercentageChanged(uint16 maxTotalOfferFeePercentage, address indexed executedBy);
event MaxRoyaltyPercentageChanged(uint16 maxRoyaltyPecentage, 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);
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/events/IBosonPauseEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { BosonTypes } from "../../domain/BosonTypes.sol";
* @notice Defines events related to pausing of the protocol.
*/
interface IBosonPauseEvents {
// When array of regions is empty, all regions are paused
event ProtocolPaused(BosonTypes.PausableRegion[] regions, address executedBy);
event ProtocolUnpaused(address executedBy);
// When array of regions is empty, all regions are unpaused
event ProtocolUnpaused(BosonTypes.PausableRegion[] regions, address executedBy);
}
Loading

0 comments on commit 1555bc4

Please sign in to comment.