Skip to main content

Marketplace Storage Contract Technical Reference

This is a technical reference for the Media Protocol's Marketplace Storage smart contract.

Inheritance

The Marketplace contract inherits Recoverable contract.

Public State Variables

General Variables

NameType
protocolFeeToaddressAddress that will receive the protocol fees.
protocolFeeRateuint256The rate of the protocol fees.
marketplacesCounteruintMarketplaces counter.

Marketplaces Variables

The following variables are mappings that store the data specific to each marketplaceId.

NameType
ownersmapping(uint => address)Mapping of marketplaces owners.
marketFeeTomapping(uint => address)Mapping of marketplaces fee recipients.
marketFeeRatemapping(uint => uint)Mapping of marketplaces fee rates.
REQUIRED_STAKEmapping(uint => uint)Mapping of required stakes for providers.
marketMetadatamapping(uint => string)Mapping of marketplaces metadata.
clientsmapping(uint => mapping(address => string))Mapping of clients metadata.

Write Functions

initializeMarketplace

Initializes a new marketplace.

function initializeMarketplace(
uint requiredStake,
address _marketFeeTo,
uint256 _marketFeeRate,
string calldata metadata
) external nonReentrant returns (uint marketplaceId);

Parameters:

NameType
requiredStakeuintThe required staked liquidity to be a provider.
_marketFeeToaddressThe address that will receive the marketplace fees.
_marketFeeRateuintThe marketplace fee rate. 100 to 100000 (0.01% to 10%).
metadatastringThe metadata for the marketplace.

Return values:

NameType
marketplaceIduintThe id of the created marketplace.

setMarketplaceMetadata

Sets the metadata for a marketplace.

function setMarketplaceMetadata(
uint marketplaceId,
string calldata metadata
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
metadatastringThe metadata for the marketplace.

Return values:

Type
boolWhether the operation was successful or not.

setRequiredStake

Sets the required stake for a marketplace.

function setRequiredStake(
uint marketplaceId,
uint requiredStake
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
requiredStakeuintThe required liquidity to be a provider.

Return values:

Type
boolWhether the operation was successful or not.

transferMarketplaceOwnership

Transfers the ownership of a marketplace.

function transferMarketplaceOwnership(
uint marketplaceId,
address newOwner
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
newOwneraddressThe address of the new owner.

Return values:

Type
boolWhether the operation was successful or not.

setMarketFeeRate

Allows marketplace owners to set the fee rate for their marketplace.

function setMarketFeeRate(
uint marketplaceId,
uint256 _feeRate
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace you want to set the fee for.
_feeRateuintThe fee rate you want to set. 100 to 100000 (0.01% to 10%).

Return:

Type
boolWhether the setting was successful or not.

setMarketFeeTo

Allows marketplace owners to set the fee recipient for their marketplace.

function setMarketFeeTo(
uint marketplaceId,
address _feeTo
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace you want to set the fee for.
_feeToaddressThe fee recipient you want to set.

Return:

Type
boolWhether the setting was successful or not.

updateClient

Allows clients to update their metadata.

function updateClient(
uint marketplaceId,
string calldata metadata
) external nonReentrant returns (bool);

Parameters:

NameType
marketplaceIduintThe id of the marketplace where you are registered.
metadatastringThe new metadata for the client.

Return:

Type
boolWhether the update was successful or not.

setProtocolFeeTo

Allows the contract owner to set the protocol fee recipient.

function setProtocolFeeTo(address feeTo) external onlyRole(DEFAULT_ADMIN_ROLE) returns (bool);

Parameters:

NameType
feeToaddressThe address of the protocol fee recipient.

Return:

Type
boolWhether the setting was successful or not.

setProtocolFeeRate

Allows the contract owner to set the protocol fee rate.

function setProtocolFeeRate(uint256 feeRate) external onlyRole(DEFAULT_ADMIN_ROLE) returns (bool);

Parameters:

NameType
feeRateuint256The rate of the protocol fee. 100 to 100000 (0.01% to 10%)

Return:

Type
boolWhether the setting was successful or not.

Events

Events are emitted for significant actions within the contract, such as registration of a provider, creation, acceptance, or cancellation of a deal. All event names and return values are self-descriptive.

  • ProtocolFeeToSet(address _feeTo)
  • ProtocolFeeRateSet(uint256 _feeRate)
  • MarketplaceInitialized(uint _marketplaceId)
  • MarketplaceMetadataSet(uint _marketplaceId, string _metadata)
  • RequiredStakeSet(uint _marketplaceId, uint _stake)
  • MarketplaceOwnershipTransferred(uint _marketplaceId, address _newOwner)
  • MarketFeeRateSet(uint _marketplaceId, uint256 _feeRate)
  • MarketFeeToSet(uint _marketplaceId, address _feeTo)
  • ClientUpdated(uint _marketplaceId, address _client)

Modifiers

Modifiers are used to conditionally change the behavior of functions. For instance, certain functions can only be executed by the contract owner or by authorized addresses.

onlyRole(MARKETPLACE_ROLE)

The onlyRole(MARKETPLACE_ROLE) modifier ensures that msg.sender is the marketplace contract.

onlyRole(DEFAULT_ADMIN_ROLE)

The onlyRole(DEFAULT_ADMIN_ROLE) modifier ensures that msg.sender is an admin.