Marketplace.sol

This document describes the functions, attributes and modifiers in MarketPlace.sol

MarketPlace

Git Source

Author: Sourabh Marathe, Julian Traversa, Rob Robbins

This contract is in charge of managing the available principals for each loan market.

In addition, this contract routes swap orders between Illuminate PTs and their respective underlying to YieldSpace pools.

State Variables

markets

markets are defined by a tuple that points to a fixed length array of principal token addresses.

mapping(address => mapping(uint256 => address[9])) public markets;

pools

pools map markets to their respective YieldSpace pools for the MetaPrincipal token

mapping(address => mapping(uint256 => address)) public pools;

admin

address that is allowed to create markets, set pools, etc. It is commonly used in the authorized modifier.

address public admin;

redeemer

address of the deployed redeemer contract

address public immutable redeemer;

lender

address of the deployed lender contract

address public immutable lender;

creator

address of the deployed creator contract

address public immutable creator;

Functions

authorized

ensures that only a certain address can call the function

modifier authorized(address a);

Parameters

constructor

initializes the MarketPlace contract

constructor(address r, address l, address c);

Parameters

createMarket

creates a new market for the given underlying token and maturity

function createMarket(
    address u,
    uint256 m,
    address[8] calldata t,
    string calldata n,
    string calldata s,
    address a,
    address e,
    address h,
    address sensePeriphery
) external authorized(admin) returns (bool);

Parameters

Returns

setPrincipal

allows the admin to set an individual market

function setPrincipal(uint8 p, address u, uint256 m, address a, address h, address sensePeriphery)
    external
    authorized(admin)
    returns (bool);

Parameters

Returns

setAdmin

sets the admin address

function setAdmin(address a) external authorized(admin) returns (bool);

Parameters

Returns

setPool

sets the address for a pool

function setPool(address u, uint256 m, address a) external authorized(admin) returns (bool);

Parameters

Returns

sellPrincipalToken

sells the PT for the underlying via the pool

function sellPrincipalToken(address u, uint256 m, uint128 a, uint128 s) external returns (uint128);

Parameters

Returns

buyPrincipalToken

buys the PT for the underlying via the pool

determines how many underlying to sell by using the preview

function buyPrincipalToken(address u, uint256 m, uint128 a, uint128 s) external returns (uint128);

Parameters

Returns

sellUnderlying

sells the underlying for the PT via the pool

function sellUnderlying(address u, uint256 m, uint128 a, uint128 s) external returns (uint128);

Parameters

Returns

buyUnderlying

buys the underlying for the PT via the pool

determines how many PTs to sell by using the preview

function buyUnderlying(address u, uint256 m, uint128 a, uint128 s) external returns (uint128);

Parameters

Returns

mint

mint liquidity tokens in exchange for adding underlying and PT

amount of liquidity tokens to mint is calculated from the amount of unaccounted for PT in this contract.

A proportional amount of underlying tokens need to be present in this contract, also unaccounted for.

function mint(address u, uint256 m, uint256 b, uint256 p, uint256 minRatio, uint256 maxRatio)
    external
    returns (uint256, uint256, uint256);

Parameters

Returns

mintWithUnderlying

Mint liquidity tokens in exchange for adding only underlying

amount of liquidity tokens is calculated from the amount of PT to buy from the pool, plus the amount of unaccounted for PT in this contract.

function mintWithUnderlying(address u, uint256 m, uint256 a, uint256 p, uint256 minRatio, uint256 maxRatio)
    external
    returns (uint256, uint256, uint256);

Parameters

Returns

burn

burn liquidity tokens in exchange for underlying and PT.

function burn(address u, uint256 m, uint256 a, uint256 minRatio, uint256 maxRatio)
    external
    returns (uint256, uint256, uint256);

Parameters

Returns

burnForUnderlying

burn liquidity tokens in exchange for underlying.

function burnForUnderlying(address u, uint256 m, uint256 a, uint256 minRatio, uint256 maxRatio)
    external
    returns (uint256, uint256);

Parameters

Returns

batch

Allows batched call to self (this contract).

function batch(bytes[] calldata c) external payable returns (bytes[] memory results);

Parameters

Events

CreateMarket

emitted upon the creation of a new market

event CreateMarket(
    address indexed underlying, uint256 indexed maturity, address[9] tokens, address element, address apwine
);

SetPrincipal

emitted upon setting a principal token

event SetPrincipal(address indexed underlying, uint256 indexed maturity, address indexed principal, uint8 protocol);

Swap

emitted upon swapping with the pool

event Swap(
    address indexed underlying,
    uint256 indexed maturity,
    address sold,
    address bought,
    uint256 received,
    uint256 spent,
    address spender
);

Mint

emitted upon minting tokens with the pool

event Mint(
    address indexed underlying,
    uint256 indexed maturity,
    uint256 underlyingIn,
    uint256 principalTokensIn,
    uint256 minted,
    address minter
);

Burn

emitted upon burning tokens with the pool

event Burn(
    address indexed underlying,
    uint256 indexed maturity,
    uint256 tokensBurned,
    uint256 underlyingReceived,
    uint256 principalTokensReceived,
    address burner
);

SetAdmin

emitted upon changing the admin

event SetAdmin(address indexed admin);

SetPool

emitted upon setting a pool

event SetPool(address indexed underlying, uint256 indexed maturity, address indexed pool);

Enums

Principals

the available principals

the order of this enum is used to select principals from the markets mapping (e.g. Illuminate => 0, Swivel => 1, and so on)

enum Principals {
    Illuminate,
    Swivel,
    Yield,
    Element,
    Pendle,
    Tempus,
    Sense,
    Apwine,
    Notional
}

Last updated