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 Jun 8, 2023
2 parents e75540f + 451dc3d commit ccae0cb
Show file tree
Hide file tree
Showing 46 changed files with 702 additions and 956 deletions.
4 changes: 2 additions & 2 deletions contracts/domain/BosonConstants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ string constant DIRECT_INITIALIZATION_NOT_ALLOWED = "Direct initializtion is not
string constant ACCESS_DENIED = "Access denied, caller doesn't have role";
string constant NOT_ASSISTANT = "Not seller's assistant";
string constant NOT_ADMIN = "Not admin";
string constant NOT_ASSISTANT_AND_CLERK = "Not assistant and clerk";
string constant NOT_ADMIN_ASSISTANT_AND_CLERK = "Not admin, assistant and clerk";
string constant CLERK_DEPRECATED = "Clerk is deprecated and must be set to address 0";
string constant NOT_ADMIN_AND_ASSISTANT = "Not admin and assistant";
string constant NOT_BUYER_OR_SELLER = "Not buyer or seller";
string constant NOT_VOUCHER_HOLDER = "Not current voucher holder";
string constant NOT_BUYER_WALLET = "Not buyer's wallet address";
Expand Down
8 changes: 4 additions & 4 deletions contracts/domain/BosonTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ contract BosonTypes {
enum SellerUpdateFields {
Admin,
Assistant,
Clerk,
Clerk, // Deprecated.
AuthToken
}

enum DisputeResolverUpdateFields {
Admin,
Assistant,
Clerk
Clerk // Deprecated.
}

struct AuthToken {
Expand All @@ -92,7 +92,7 @@ contract BosonTypes {
uint256 id;
address assistant;
address admin;
address clerk;
address clerk; // Deprecated. Kept for backwards compatibility.
address payable treasury;
bool active;
string metadataUri;
Expand All @@ -109,7 +109,7 @@ contract BosonTypes {
uint256 escalationResponsePeriod;
address assistant;
address admin;
address clerk;
address clerk; // Deprecated. Kept for backwards compatibility.
address payable treasury;
string metadataUri;
bool active;
Expand Down
30 changes: 18 additions & 12 deletions contracts/interfaces/handlers/IBosonAccountHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ interface IBosonAccountHandler is IBosonAccountEvents {
*
* Reverts if:
* - Caller is not the supplied admin or does not own supplied auth token
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - The sellers region of protocol is paused
* - Address values are zero address
* - Addresses are not unique to this seller
Expand Down Expand Up @@ -59,7 +60,8 @@ interface IBosonAccountHandler is IBosonAccountEvents {
* Emits a DisputeResolverCreated event if successful.
*
* Reverts if:
* - Caller is not the supplied admin, assistant and clerk
* - Caller is not the supplied admin and assistant
* - Supplied clerk is not a zero address
* - The dispute resolvers region of protocol is paused
* - Any address is zero address
* - Any address is not unique to this dispute resolver
Expand Down Expand Up @@ -98,18 +100,19 @@ interface IBosonAccountHandler is IBosonAccountEvents {
function createAgent(BosonTypes.Agent memory _agent) external;

/**
* @notice Updates treasury address, if changed. Puts admin, assistant, clerk and AuthToken in pending queue, if changed.
* @notice Updates treasury address, if changed. Puts admin, assistant and AuthToken in pending queue, if changed.
* Pending updates can be completed by calling the optInToSellerUpdate function.
* @dev Active flag passed in by caller will be ignored. The value from storage will be used.
*
* Emits a SellerUpdateApplied event if the seller has changed the treasury.
* Emits a SellerUpdatePending event if the seller has requested an update for admin, clerk, assistant, or auth token.
* Holder of new auth token and/or owner(s) of new addresses for admin, clerk, assistant must opt-in to the update.
* Emits a SellerUpdatePending event if the seller has requested an update for admin, assistant, or auth token.
* Holder of new auth token and/or owner(s) of new addresses for admin, assistant must opt-in to the update.
*
* Reverts if:
* - The sellers region of protocol is paused
* - Address values are zero address
* - Addresses are not unique to this seller
* - Supplied clerk is not a zero address
* - Caller address is not the admin address of the stored seller with no AuthToken
* - Caller is not the owner of the seller's stored AuthToken
* - Seller does not exist
Expand All @@ -135,6 +138,7 @@ interface IBosonAccountHandler is IBosonAccountEvents {
* - Caller is not the owner of the pending AuthToken being updated
* - No pending update exists for this seller
* - AuthTokenType is not unique to this seller
* - Seller tries to update the clerk
*
* @param _sellerId - seller id
* @param _fieldsToUpdate - fields to update, see SellerUpdateFields enum
Expand All @@ -161,7 +165,7 @@ interface IBosonAccountHandler is IBosonAccountEvents {
function updateBuyer(BosonTypes.Buyer memory _buyer) external;

/**
* @notice Updates treasury address, escalationResponsePeriod or metadataUri if changed. Puts admin, assistant and clerk in pending queue, if changed.
* @notice Updates treasury address, escalationResponsePeriod or metadataUri if changed. Puts admin and assistant in pending queue, if changed.
* Pending updates can be completed by calling the optInToDisputeResolverUpdate function.
*
* Update doesn't include DisputeResolverFees, allowed seller list or active flag.
Expand All @@ -172,13 +176,14 @@ interface IBosonAccountHandler is IBosonAccountEvents {
* @dev Active flag passed in by caller will be ignored. The value from storage will be used.
*
* Emits a DisputeResolverUpdated event if successful.
* Emits a DisputeResolverUpdatePending event if the dispute resolver has requested an update for admin, clerk or assistant.
* Owner(s) of new addresses for admin, clerk, assistant must opt-in to the update.
* Emits a DisputeResolverUpdatePending event if the dispute resolver has requested an update for admin or assistant.
* Owner(s) of new addresses for admin, assistant must opt-in to the update.
*
* Reverts if:
* - The dispute resolvers region of protocol is paused
* - Caller is not the admin address of the stored dispute resolver
* - Any address is not unique to this dispute resolver
* - Supplied clerk is not a zero address
* - Dispute resolver does not exist
* - EscalationResponsePeriod is invalid
* - No field has been updated or requested to be updated
Expand All @@ -197,6 +202,7 @@ interface IBosonAccountHandler is IBosonAccountEvents {
* - Addresses are not unique to this dispute resolver
* - Caller address is not pending update for the field being updated
* - No pending update exists for this dispute resolver
* - Dispute resolver tries to update the clerk
*
* @param _disputeResolverId - disputeResolver id
* @param _fieldsToUpdate - fields to update, see DisputeResolverUpdateFields enum
Expand Down Expand Up @@ -317,11 +323,11 @@ interface IBosonAccountHandler is IBosonAccountEvents {
) external view returns (bool exists, BosonTypes.Seller memory seller, BosonTypes.AuthToken memory authToken);

/**
* @notice Gets the details about a seller by an address associated with that seller: assistant, admin, or clerk address.
* @notice Gets the details about a seller by an address associated with that seller: assistant, or admin address.
* A seller will have either an admin address or an auth token.
* If seller's admin uses NFT Auth the seller should call `getSellerByAuthToken` instead.
*
* @param _associatedAddress - the address associated with the seller. Must be an assistant, admin, or clerk address.
* @param _associatedAddress - the address associated with the seller. Must be an assistant, or admin address.
* @return exists - the seller was found
* @return seller - the seller details. See {BosonTypes.Seller}
* @return authToken - optional AuthToken struct that specifies an AuthToken type and tokenId that the seller can use to do admin functions
Expand Down Expand Up @@ -378,9 +384,9 @@ interface IBosonAccountHandler is IBosonAccountEvents {
);

/**
* @notice Gets the details about a dispute resolver by an address associated with that dispute resolver: assistant, admin, or clerk address.
* @notice Gets the details about a dispute resolver by an address associated with that dispute resolver: assistant, or admin address.
*
* @param _associatedAddress - the address associated with the dispute resolver. Must be an assistant, admin, or clerk address.
* @param _associatedAddress - the address associated with the dispute resolver. Must be an assistant, or admin address.
* @return exists - the dispute resolver was found
* @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}
Expand Down
24 changes: 16 additions & 8 deletions contracts/interfaces/handlers/IBosonOrchestrationHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ interface IBosonOrchestrationHandler is
* - The offers region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied admin or does not own supplied auth token
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - In seller struct:
Expand Down Expand Up @@ -132,8 +133,9 @@ interface IBosonOrchestrationHandler is
* - The offers region of protocol is paused
* - The orchestration region of protocol is paused
* - The exchanges region of protocol is paused
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Caller is not the supplied admin or does not own supplied auth token
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - Reserved range length is zero
Expand Down Expand Up @@ -678,7 +680,8 @@ interface IBosonOrchestrationHandler is
* - The groups region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied admin or does not own supplied auth token
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - In seller struct:
Expand Down Expand Up @@ -749,8 +752,9 @@ interface IBosonOrchestrationHandler is
* - The groups region of protocol is paused
* - The exchanges region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Caller is not the supplied admin or does not own supplied auth token
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - Reserved range length is zero
Expand Down Expand Up @@ -832,7 +836,8 @@ interface IBosonOrchestrationHandler is
* - The bundles region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied admin or does not own supplied auth token
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - In seller struct:
Expand Down Expand Up @@ -911,8 +916,9 @@ interface IBosonOrchestrationHandler is
* - The bundles region of protocol is paused
* - The exchanges region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Caller is not the supplied admin or does not own supplied auth token
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - Reserved range length is zero
Expand Down Expand Up @@ -1002,7 +1008,8 @@ interface IBosonOrchestrationHandler is
* - The bundles region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied admin or does not own supplied auth token
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - In seller struct:
Expand Down Expand Up @@ -1086,8 +1093,9 @@ interface IBosonOrchestrationHandler is
* - The bundles region of protocol is paused
* - The exchanges region of protocol is paused
* - The orchestration region of protocol is paused
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Caller is not the supplied admin or does not own supplied auth token
* - Supplied clerk is not a zero address
* - Admin address is zero address and AuthTokenType == None
* - AuthTokenType is not unique to this seller
* - Reserved range length is zero
Expand Down
6 changes: 3 additions & 3 deletions contracts/protocol/bases/OfferBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ contract OfferBase is ProtocolBase, IBosonOfferEvents {
// _to must be the contract address or the contract owner
require(_to == address(bosonVoucher) || _to == sender, INVALID_TO_ADDRESS);

// Call reserveRange on voucher
bosonVoucher.reserveRange(_offerId, _startId, _length, _to);

// increase exchangeIds
pc.nextExchangeId = _startId + _length;

Expand All @@ -333,6 +330,9 @@ contract OfferBase is ProtocolBase, IBosonOfferEvents {
offer.quantityAvailable -= _length;
}

// Call reserveRange on voucher
bosonVoucher.reserveRange(_offerId, _startId, _length, _to);

// Notify external observers
emit RangeReserved(_offerId, offer.sellerId, _startId, _startId + _length - 1, _to, sender);
}
Expand Down
32 changes: 0 additions & 32 deletions contracts/protocol/bases/ProtocolBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,6 @@ abstract contract ProtocolBase is PausableBase, ReentrancyGuardBase {
exists = (sellerId > 0);
}

/**
* @notice Gets a seller id from storage by clerk address
*
* @param _clerk - the clerk address of the seller
* @return exists - whether the seller id exists
* @return sellerId - the seller id
*/
function getSellerIdByClerk(address _clerk) internal view returns (bool exists, uint256 sellerId) {
// Get the seller id
sellerId = protocolLookups().sellerIdByClerk[_clerk];

// 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
*
Expand Down Expand Up @@ -238,23 +223,6 @@ abstract contract ProtocolBase is PausableBase, ReentrancyGuardBase {
exists = (disputeResolverId > 0);
}

/**
* @notice Gets a dispute resolver id from storage by clerk address
*
* @param _clerk - the clerk address of the dispute resolver
* @return exists - whether the dispute resolver id exists
* @return disputeResolverId - the dispute resolver id
*/
function getDisputeResolverIdByClerk(
address _clerk
) internal view returns (bool exists, uint256 disputeResolverId) {
// Get the dispute resolver id
disputeResolverId = protocolLookups().disputeResolverIdByClerk[_clerk];

// Determine existence
exists = (disputeResolverId > 0);
}

/**
* @notice Gets a group id from storage by offer id
*
Expand Down
20 changes: 7 additions & 13 deletions contracts/protocol/bases/SellerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
* Emits a SellerCreated event if successful.
*
* Reverts if:
* - Caller is not the supplied assistant and clerk
* - Caller is not the supplied assistant
* - Supplied clerk is not a zero address
* - The sellers region of protocol is paused
* - Address values are zero address
* - Addresses are not unique to this seller
Expand All @@ -45,10 +46,7 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
require(_seller.active, MUST_BE_ACTIVE);

// Check for zero address
require(
_seller.assistant != address(0) && _seller.clerk != address(0) && _seller.treasury != address(0),
INVALID_ADDRESS
);
require(_seller.assistant != address(0) && _seller.treasury != address(0), INVALID_ADDRESS);

// Admin address or AuthToken data must be present. A seller can have one or the other
require(
Expand All @@ -63,8 +61,9 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
// Get message sender
address sender = msgSender();

// Check that caller is the supplied assistant and clerk
require(_seller.assistant == sender && _seller.clerk == sender, NOT_ASSISTANT_AND_CLERK);
// Check that caller is the supplied assistant
require(_seller.assistant == sender, NOT_ASSISTANT);
require(_seller.clerk == address(0), CLERK_DEPRECATED);

// Do caller and uniqueness checks based on auth type
if (_authToken.tokenType != AuthTokenType.None) {
Expand All @@ -87,9 +86,7 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {

// Check that the sender address is unique to one seller id, across all roles
require(
lookups.sellerIdByAdmin[sender] == 0 &&
lookups.sellerIdByAssistant[sender] == 0 &&
lookups.sellerIdByClerk[sender] == 0,
lookups.sellerIdByAdmin[sender] == 0 && lookups.sellerIdByAssistant[sender] == 0,
SELLER_ADDRESS_MUST_BE_UNIQUE
);

Expand Down Expand Up @@ -125,7 +122,6 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
seller.id = _seller.id;
seller.assistant = _seller.assistant;
seller.admin = _seller.admin;
seller.clerk = _seller.clerk;
seller.treasury = _seller.treasury;
seller.active = _seller.active;
seller.metadataUri = _seller.metadataUri;
Expand All @@ -146,7 +142,6 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {

// Map the seller's other addresses to the seller id. It's not necessary to map the treasury address, as it only receives funds
_lookups.sellerIdByAssistant[_seller.assistant] = _seller.id;
_lookups.sellerIdByClerk[_seller.clerk] = _seller.id;
}

/**
Expand Down Expand Up @@ -210,7 +205,6 @@ contract SellerBase is ProtocolBase, IBosonAccountEvents {
exists =
sellerPendingUpdate.admin != address(0) ||
sellerPendingUpdate.assistant != address(0) ||
sellerPendingUpdate.clerk != address(0) ||
authTokenPendingUpdate.tokenType != AuthTokenType.None;
}
}
Loading

0 comments on commit ccae0cb

Please sign in to comment.