Skip to main content

Marketplace Helper

The MarketplaceHelper contract acts as a helper for the Marketplace contract. It allows users to register and unregister as providers, add liquidity, create deals, and add balance using ERC20 tokens or ETH. It utilizes Uniswap's ISwapRouter02 and INonfungiblePositionManager interfaces to interact with Uniswap V3 pools.

Functions

addLiquidityAndRegisterWithETH

This function deposits ETH into the WETH contract, swaps half of it to MEDIA, and then adds both ERC20 tokens as liquidity on the Uniswap V3 Pool. The resulting Uniswap V3 Position NFT is sent to the Marketplace contract, which then stakes it into the Staking contract in the name of the provider. If the NFT is in range and the liquidity is sufficient, the provider is registered on the Marketplace contract.

function addLiquidityAndRegisterWithETH(
uint256 marketplaceId,
string memory metadata,
string memory publicKey,
uint256 minMediaAmountOut,
bytes memory path,
uint256 slippage,
uint24 poolFee
) external payable returns (
uint nftId,
uint128 liquidity,
uint amount0,
uint amount1
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
metadatastringThe metadata of the provider.
publicKeystringThe public key of the provider.
minMediaAmountOutuint256The minimum amount of MEDIA Tokens to receive for half of the sent ETH.
pathbytesThe path for WETH/MEDIA including the pool fee.
slippageuint256The slippage for the NFT mint. Note that this is not the slippage for the swap but for amount0Min and amount1Min in Uniswap's INonfungiblePositionManager.MintParams.
poolFeeuint24The pool fee of the MEDIA/WETH Uniswap V3 pool.

Return values:

NameType
nftIduintThe id of the created Uniswap V3 Position NFT.
liquidityuint128The amount of liquidity added.
amount0uintThe amount of token0 added.
amount1uintThe amount of token1 added.

addLiquidityAndRegister

Same as addLiquidityAndRegisterWithETH but with an ERC20 token instead of ETH.

function addLiquidityAndRegister(
uint256 marketplaceId,
IERC20 inputToken,
uint256 inputAmount,
string memory metadata,
string memory publicKey,
uint256[] memory minOut,
bytes[] memory paths,
uint256 slippage,
uint24 poolFee
) external nonReentrant returns (
uint nftId,
uint128 liquidity,
uint mediaAmount,
uint wethAmount
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
inputTokenIERC20The token to add liquidity with.
inputAmountuint256The amount of input token to add.
metadatastringThe metadata of the provider.
publicKeystringThe public key of the provider.
minOutuint256[]The minimum amount of tokens to receive.
pathsbytes[]The paths for swapping tokens.
slippageuint256The slippage for the NFT mint. Note that this is not the slippage for the swap but for amount0Min and amount1Min in Uniswap's INonfungiblePositionManager.MintParams.
poolFeeuint24The pool fee of the MEDIA/WETH Uniswap V3 pool.

Return values:

NameType
nftIduintThe id of the created Uniswap V3 Position NFT.
liquidityuint128The amount of liquidity added.
mediaAmountuintThe amount of MEDIA added.
wethAmountuintThe amount of WETH added.

addLiquidityAndStakeWithETH

It increases the liquidity of a staked Uniswap V3 Position NFT.

function addLiquidityAndStakeWithETH(
uint256 marketplaceId,
uint256 minWethAmountOut,
uint256 minMediaAmountOut,
bytes memory path,
uint256 slippage
) external payable nonReentrant returns (
uint128 liquidity,
uint amount0,
uint amount1
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
minWethAmountOutuint256The minimum amount of WETH to receive.
minMediaAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping ETH to media token.
slippageuint256The slippage for the NFT mint. Note that this is not the slippage for the swap but for amount0Min and amount1Min in Uniswap's INonfungiblePositionManager.MintParams.

Return values:

NameType
liquidityuint128The amount of liquidity added.
amount0uintThe amount of token0 added.

addLiquidityAndStake

Same as addLiquidityAndStakeWithETH but with an ERC20 token instead of ETH.

function addLiquidityAndStake(
uint256 marketplaceId,
IERC20 inputToken,
uint256 inputAmount,
uint256 minWethAmountOut,
uint256 minMediaAmountOut,
bytes memory path0,
bytes memory path1,
uint256 slippage
) external nonReentrant returns (
uint128 liquidity,
uint amount0,
uint amount1
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
inputTokenIERC20The token to add liquidity with.
inputAmountuint256The amount of input token to add.
minWethAmountOutuint256The minimum amount of WETH to receive.
minMediaAmountOutuint256The minimum amount of media token to receive.
path0bytesThe path for swapping token0.
path1bytesThe path for swapping token1.
slippageuint256The slippage for the NFT mint. Note that this is not the slippage for the swap but for amount0Min and amount1Min in Uniswap's INonfungiblePositionManager.MintParams.

Return values:

NameType
liquidityuint128The amount of liquidity added.
amount0uintThe amount of token0 added.
amount1uintThe amount of token1 added.

unregisterRemoveLiquidity

Unregisters a provider from a marketplace and removes liquidity from the Uniswap V3 pool.

function unregisterRemoveLiquidity(
uint256 marketplaceId,
uint256 amount0Min,
uint256 amount1Min
) external nonReentrant returns(
uint256 collectedToken0,
uint256 collectedToken1,
address token0,
address token1
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
amount0Minuint256The minimum amount of token0 to receive.
amount1Minuint256The minimum amount of token1 to receive.

Return values:

NameType
collectedToken0uint256The amount of token0 collected.
collectedToken1uint256The amount of token1 collected.
token0
token1addressThe addresses of the tokens collected.

unregisterRemoveLiquidityAndSwap

Same as unregisterRemoveLiquidity but it returns the liquidity to the provider in the form of MEDIA only.

function unregisterRemoveLiquidityAndSwap(
uint256 marketplaceId,
uint256 minOutputMedia,
uint256 minMediaAmount,
uint256 minWethAmount,
uint24 poolFee
) external nonReentrant;

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
minOutputMediauint256The minimum amount of media token to receive.
minMediaAmountuint256The minimum amount of media token to receive.
minWethAmountuint256The minimum amount of WETH to receive.
poolFeeuint24The pool fee of the Uniswap V3 pool.

swapAndCreateDeal

Swaps tokens and creates a deal.

function swapAndCreateDeal(
uint256 marketplaceId,
IERC20 inputToken,
uint256 inputAmount,
uint256 resourceId,
uint256 offerId,
string memory sharedKeyCopy,
uint256 minAmountOut,
bytes memory path
) external nonReentrant returns (
uint256 mediaAmount,
uint actualDeposit,
uint256 dealId
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
inputTokenIERC20The token to swap.
inputAmountuint256The amount of input token to swap.
resourceIduint256The id of the resource.
offerIduint256The id of the offer.
sharedKeyCopystringThe shared key of the deal.
minAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.
actualDeposituintThe actual deposit amount.
dealIduint256The id of the created deal.

swapAndCreateDealWithETH

Swaps ETH and creates a deal.

function swapAndCreateDealWithETH(
uint256 marketplaceId,
uint256 resourceId,
uint256 offerId,
string memory sharedKeyCopy,
uint256 minMediaAmountOut,
bytes memory path
) external payable nonReentrant returns (
uint256 mediaAmount,
uint actualDeposit,
uint256 dealId
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
resourceIduint256The id of the resource.
offerIduint256The id of the offer.
sharedKeyCopystringThe shared key of the deal.
minMediaAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.
actualDeposituintThe actual deposit amount.
dealIduint256The id of the created deal.

swapAndCreateDeals

Swaps tokens and creates multiple deals.

function swapAndCreateDeals(
uint256 marketplaceId,
IERC20 inputToken,
uint256 inputAmount,
uint256 resourceId,
uint256[] memory offerIds,
string[] memory sharedKeyCopies,
uint256 minAmountOut,
bytes memory path
) external nonReentrant returns (
uint256 mediaAmount,
uint actualDeposit,
uint256[] memory dealsId
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
inputTokenIERC20The token to swap.
inputAmountuint256The amount of input token to swap.
resourceIduint256The id of the resource.
offerIdsuint256[]The ids of the offers.
sharedKeyCopiesstring[]The shared keys of the deals.
minAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.
actualDeposituintThe actual deposit amount.
dealsIduint256[]The ids of the created deals.

swapAndCreateDealsWithETH

Swaps ETH and creates multiple deals.

function swapAndCreateDealsWithETH(
uint256 marketplaceId,
uint256 resourceId,
uint256[] memory offerIds,
string[] memory sharedKeyCopies,
uint256 minMediaAmountOut,
bytes memory path
) external payable nonReentrant returns (
uint256 mediaAmount,
uint actualDeposit,
uint256[] memory dealsId
);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
resourceIduint256The id of the resource.
offerIdsuint256[]The ids of the offers.
sharedKeyCopiesstring[]The shared keys of the deals.
minMediaAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.
actualDeposituintThe actual deposit amount.
dealsIduint256[]The ids of the created deals.

swapAndAddBalance

Swaps tokens and adds balance to a deal.

function swapAndAddBalance(
uint256 marketplaceId,
IERC20 inputToken,
uint256 inputAmount,
uint256 dealId,
uint256 minAmountOut,
bytes memory path
) external nonReentrant returns (uint256 mediaAmount);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
inputTokenIERC20The token to swap.
inputAmountuint256The amount of input token to swap.
dealIduint256The id of the deal.
minAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.

swapAndAddBalanceWithETH

Swaps ETH and adds balance to a deal.

function swapAndAddBalanceWithETH(
uint256 marketplaceId,
uint256 dealId,
uint256 minMediaAmountOut,
bytes memory path
) external payable nonReentrant returns (uint256 mediaAmount);

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
dealIduint256The id of the deal.
minMediaAmountOutuint256The minimum amount of media token to receive.
pathbytesThe path for swapping tokens.

Return values:

NameType
mediaAmountuint256The amount of media token swapped.

note

This is a high-level technical breakdown. For a deep understanding of each function's inner workings and logic, refer to the smart contract's actual implementation.