MarketPool

arketPool.sol

The MarketPool contract is a core component of Scall.io, responsible for managing perpetual options, liquidity deposits, and strike price pools for a specific market (e.g., BTC/USDC or ETH/USDC).

Each deployed MarketPool instance handles one market and uses a Chainlink price feed to determine valid strike prices and market conditions.


🧩 What It Does

  • Accepts deposits from Liquidity Providers (LPs) who want to earn yield at specific strike prices.

  • Allows traders to open and close Call or Put perpetual options.

  • Tracks individual LP positions and open option contracts through NFTs.


📤 Public Functions

Here are the key functions users and external contracts can call:

deposit(bool isCall, uint256 amount)

  • Called by LPs to provide liquidity at a specific strike price.

  • Mints an LP NFT representing their position.

  • Emits: Deposit event

/// @notice Allows a user to deposit assets and open an LP position
/// @dev Mints an NFT for the LP position and updates liquidity information
/// @param _isCall Specifies if the option is a call or a put
/// @param _amount The amount of assets to deposit (token decimal)
/// @return id The unique ID assigned to the newly created LP position.
function deposit(bool _isCall, uint256 _amount) external returns(uint256)

withdraw(uint256 lpId)

  • Allows LPs to withdraw their deposited liquidity (if not in use).

  • Burns the associated LP NFT.

  • Emits: Withdraw event

/// @notice Allows a user to withdraw assets from an LP position
/// @dev Claims rewards for the LP position before withdrawal and burns the NFT if fully withdrawn
/// @param _id The ID of the LP position to withdraw from
/// @return tokenAtoTransfer The amount of token A withdrawn by the LP (token decimals).
/// @return tokenBtoTransfer The amount of token B withdrawn by the LP (token decimals).
/// @return claimedRewards The additional reward amount received by the LP (token decimals).
function withdraw(uint256 _id) external returns(uint256, uint256, uint256)

openContract(bool isCall, uint256 strikeIndex, uint256 amount)

  • Called by traders to open a new perpetual option.

  • Requires sufficient collateral in the CollateralPool.

  • Mints a contract NFT.

  • Emits: ContractOpened event

/// @notice Opens a new option contract using liquidity provided in the pool
/// @dev Mints an NFT for the option contract and updates liquidity information
/// @param _isCall Specifies if the option is a call or a put
/// @param _strikeIndex The strike Index from getIntervals()
/// @param _amount The amount of assets for the option contract
function openContract(bool _isCall, uint256 _strikeIndex, uint256 _amount) external

closeContract(uint256 contractId)

  • Allows traders to manually close their perpetual options at any time.

  • Burns the contract NFT.

  • Emits: ContractClosed event

/// @notice Closes an open contract position, settles based on the current price, and burns the contract NFT.
/// @dev Checks if the caller is the contract owner. Determines if the position is a call or put and settles the contract based on the current price relative to the strike price.
/// @param _id The unique ID of the contract to close.
function closeContract(uint256 _id) external

👀 View Functions

Here are helpful read-only functions to query data:

Function
Description

getMain()

Returns the address of the Main contract.

getERC721_Contract()

Returns the address of the ERC721 contract representing trader positions.

getERC721_LP()

Returns the address of the ERC721 contract representing LP positions.

getTokenA()

Returns the address of the asset token (e.g., BTC).

getTokenB()

Returns the address of the collateral token (e.g., USDC).

getPriceFeed()

Returns the address of the Chainlink price feed used for indexing.

getIntervalLength()

Returns the strike price interval setting.

getRange()

Returns the range of strike prices around the market price.

getYield()

Returns the current yield (APR) configured for the market.

getContractInfos(uint256 _id)

Returns all stored data for a given trader contract ID.

getLpInfos(uint256 _id)

Returns all stored data for a given LP position ID.

getStrikeInfos(uint256 _strike)

Returns aggregated info about liquidity at a specific strike.

getStrikeHistory(uint256 _strike, uint256 _index)

Returns historical data for a strike (useful for rewards calculations or snapshots).

getPrice()

Fetches the current price from the Chainlink oracle.

getIntervals()

Returns the list of active strike price intervals.

getRewards(uint256 _id)

Returns the claimable rewards for a given LP NFT ID.


🔐 Roles & Interactions

This contract interacts with:

  • CollateralPool.sol for rent collection and liquidation triggers

  • Main.sol to access governance parameters

  • Chainlink price feeds for accurate strike pricing

  • Custom ERC721 contracts for on-chain position tracking

Last updated