Marketplace.sol
This document describes the functions, attributes and modifiers in MarketPlace.sol
MarketPlace
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.
pools
pools map markets to their respective YieldSpace pools for the MetaPrincipal token
admin
address that is allowed to create markets, set pools, etc. It is commonly used in the authorized modifier.
redeemer
address of the deployed redeemer contract
lender
address of the deployed lender contract
creator
address of the deployed creator contract
Functions
authorized
ensures that only a certain address can call the function
Parameters
Name | Type | Description |
---|---|---|
|
| address that msg.sender must be to be authorized |
constructor
initializes the MarketPlace contract
Parameters
Name | Type | Description |
---|---|---|
|
| address of the deployed redeemer contract |
|
| address of the deployed lender contract |
|
| address of the deployed creator contract |
createMarket
creates a new market for the given underlying token and maturity
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| principal token addresses for this market |
|
| name for the Illuminate token |
|
| symbol for the Illuminate token |
|
| address of the APWine router that corresponds to this market |
|
| address of the Element vault that corresponds to this market |
|
| address of a helper contract, used for Sense approvals if active in the market |
|
| address of the Sense periphery contract that must be approved by the lender |
Returns
Name | Type | Description |
---|---|---|
|
| bool true if successful |
setPrincipal
allows the admin to set an individual market
Parameters
Name | Type | Description |
---|---|---|
|
| principal value according to the MarketPlace's Principals Enum |
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| address of the new principal token |
|
| a supplementary address (apwine needs a router, element needs a vault, sense needs interest bearing asset) |
|
| address of the Sense periphery contract that must be approved by the lender |
Returns
Name | Type | Description |
---|---|---|
|
| bool true if the principal set, false otherwise |
setAdmin
sets the admin address
Parameters
Name | Type | Description |
---|---|---|
|
| Address of a new admin |
Returns
Name | Type | Description |
---|---|---|
|
| bool true if the admin set, false otherwise |
setPool
sets the address for a pool
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| address of the pool |
Returns
Name | Type | Description |
---|---|---|
|
| bool true if the pool set, false otherwise |
sellPrincipalToken
sells the PT for the underlying via the pool
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| amount of PTs to sell |
|
| slippage cap, minimum amount of underlying that must be received |
Returns
Name | Type | Description |
---|---|---|
|
| uint128 amount of underlying bought |
buyPrincipalToken
buys the PT for the underlying via the pool
determines how many underlying to sell by using the preview
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| amount of PTs to be purchased |
|
| slippage cap, maximum number of underlying that can be sold |
Returns
Name | Type | Description |
---|---|---|
|
| uint128 amount of underlying sold |
sellUnderlying
sells the underlying for the PT via the pool
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| amount of underlying to sell |
|
| slippage cap, minimum number of PTs that must be received |
Returns
Name | Type | Description |
---|---|---|
|
| uint128 amount of PT purchased |
buyUnderlying
buys the underlying for the PT via the pool
determines how many PTs to sell by using the preview
Parameters
Name | Type | Description |
---|---|---|
|
| address of an underlying asset |
|
| maturity (timestamp) of the market |
|
| amount of underlying to be purchased |
|
| slippage cap, maximum number of PTs that can be sold |
Returns
Name | Type | Description |
---|---|---|
|
| uint128 amount of PTs sold |
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.
Parameters
Name | Type | Description |
---|---|---|
|
| the address of the underlying token |
|
| the maturity of the principal token |
|
| number of base tokens |
|
| the principal token amount being sent |
|
| minimum ratio of LP tokens to PT in the pool. |
|
| maximum ratio of LP tokens to PT in the pool. |
Returns
Name | Type | Description |
---|---|---|
|
| uint256 number of base tokens passed to the method |
|
| uint256 number of yield tokens passed to the method |
|
| uint256 the amount of tokens minted. |
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.
Parameters
Name | Type | Description |
---|---|---|
|
| the address of the underlying token |
|
| the maturity of the principal token |
|
| the underlying amount being sent |
|
| amount of |
|
| minimum ratio of LP tokens to PT in the pool. |
|
| maximum ratio of LP tokens to PT in the pool. |
Returns
Name | Type | Description |
---|---|---|
|
| uint256 number of base tokens passed to the method |
|
| uint256 number of yield tokens passed to the method |
|
| uint256 the amount of tokens minted. |
burn
burn liquidity tokens in exchange for underlying and PT.
Parameters
Name | Type | Description |
---|---|---|
|
| the address of the underlying token |
|
| the maturity of the principal token |
|
| the amount of liquidity tokens to burn |
|
| minimum ratio of LP tokens to PT in the pool |
|
| maximum ratio of LP tokens to PT in the pool |
Returns
Name | Type | Description |
---|---|---|
|
| uint256 amount of LP tokens burned |
|
| uint256 amount of base tokens received |
|
| uint256 amount of fyTokens received |
burnForUnderlying
burn liquidity tokens in exchange for underlying.
Parameters
Name | Type | Description |
---|---|---|
|
| the address of the underlying token |
|
| the maturity of the principal token |
|
| the amount of liquidity tokens to burn |
|
| minimum ratio of LP tokens to PT in the pool. |
|
| minimum ratio of LP tokens to PT in the pool. |
Returns
Name | Type | Description |
---|---|---|
|
| uint256 amount of PT tokens sent to the pool |
|
| uint256 amount of underlying tokens returned |
batch
Allows batched call to self (this contract).
Parameters
Name | Type | Description |
---|---|---|
|
| An array of inputs for each call. |
Events
CreateMarket
emitted upon the creation of a new market
SetPrincipal
emitted upon setting a principal token
Swap
emitted upon swapping with the pool
Mint
emitted upon minting tokens with the pool
Burn
emitted upon burning tokens with the pool
SetAdmin
emitted upon changing the admin
SetPool
emitted upon setting a 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)
Last updated