Skip to content

Latest commit

Β 

History

History
396 lines (273 loc) Β· 8.78 KB

CherryPool.md

File metadata and controls

396 lines (273 loc) Β· 8.78 KB

CherryPool Contract (CherryPool.sol)

View Source: contracts/CherryPool.sol

β†— Extends: Initializable β†˜ Derived Contracts: CherrySwap

CherryPool

This contract handle Cherry Pool functionalities

Contract Members

Constants & Variables

//public members
address public owner;
uint256 public poolBalance;
uint256 public poolcBalance;
uint256 public longPoolBalance;
uint256 public shortPoolBalance;
uint256 public longPoolReserved;
uint256 public shortPoolReserved;
int256 public poolcTokenProfit;
contract IERC20 public token;
contract ICERC20 public cToken;
contract CherryDai public cherryDai;

//internal members
contract CherryMath internal cherryMath;

Events

event DepositLiquidity(address indexed liquidityProvider, uint256  amount);
event MintCherry(address indexed liquidityProvider, uint256  amountDai, uint256  amountcDai, uint256  amountCherryDai);
event RedeemCherry(address indexed liquidityProvider, uint256  redeemedCherryDaiDaiAmount);
event TransferDai(address indexed to, uint256  value);
event CurrentExchangeRate(uint256  rate);
event PoolShare(uint256  amount);
event FreeLongPool(uint256  amount);
event FreeShortPool(uint256  amount);
event SetCherryDai(address  cherryDai);

Modifiers

isLongUtilized

Modifier to check if long pool is not fully utilized

modifier isLongUtilized() internal

Arguments

Name Type Description

isShortUtilized

Modifier to check if short pool is not fully utilized

modifier isShortUtilized() internal

Arguments

Name Type Description

canReserveLong

modifier canReserveLong(uint256 _amount) internal

Arguments

Name Type Description
_amount uint256

canReserveShort

modifier canReserveShort(uint256 _amount) internal

Arguments

Name Type Description
_amount uint256

Functions

initialize

β€Ώ Overridden Implementation(s): CherrySwap.initialize

Initialize contract states

function initialize(address _token, address _cToken, address _cherryMath) public nonpayable initializer 

Arguments

Name Type Description
_token address
_cToken address
_cherryMath address

mint

adds liquidity to the cherry pool to offer swaps against

function mint(uint256 _amount) external nonpayable
returns(uint256)

Returns

cherryDaiToMint amount of minted CherryDai

Arguments

Name Type Description
_amount uint256 amount of deposited DAI

calcLongPoolUtil

Get long pool utilization

function calcLongPoolUtil(uint256 _longPoolReserved) public view
returns(uint256)

Returns

current long pool utilization as a decimal scaled 10*18

Arguments

Name Type Description
_longPoolReserved uint256 amount of liquidity reserved in the long pool

calcShortPoolUtil

Get short pool utilization

function calcShortPoolUtil(uint256 _shortPoolReserved) public view
returns(uint256)

Returns

current short pool utilization as a decimal scaled 10*18

Arguments

Name Type Description
_shortPoolReserved uint256 amount of liquidity reserved in the short pool

cherryDaiBalanceOf

Get Cherrydai balance for liquidity provider

function cherryDaiBalanceOf(address _provider) public view
returns(uint256)

Returns

CherryDai balance

Arguments

Name Type Description
_provider address liquidity provider address

redeem

the amount returned is the number of cherrytokens multiplied by the current exchange rate The sender should approve the _amount to this contract address

function redeem(uint256 _amount) external nonpayable isLongUtilized isShortUtilized 
returns(uint256)

Returns

daiRedeemed amount of DAI redeemed

Arguments

Name Type Description
_amount uint256 amount of CherryDai to redeem

getCashPrior

Get available pool balance (total pool balance - total reserved balance)

function getCashPrior() internal nonpayable
returns(uint256)

Returns

available pool balance

Arguments

Name Type Description

payout

Transfer the underlying asset

function payout(address _redeemer, uint256 _redeemedDaiAmount, uint256 _redeemedCherryDaiTokens) internal nonpayable

Arguments

Name Type Description
_redeemer address redeemer address
_redeemedDaiAmount uint256 amount of DAI to transfer
_redeemedCherryDaiTokens uint256 amount of CherryDAI to burn

exchangeRate

Each CherryDai is convertible into the underlying asset + the fees accrued through liquidity provision.

function exchangeRate() public nonpayable
returns(uint256)

Returns

rate Exchange rate

Arguments

Name Type Description

setToken

can only be called by the owner

function setToken(address _token) external nonpayable

Arguments

Name Type Description
_token address CherryDai token address

_reserveLongPool

function _reserveLongPool(uint256 _amount) internal nonpayable canReserveLong 

Arguments

Name Type Description
_amount uint256

_reserveShortPool

function _reserveShortPool(uint256 _amount) internal nonpayable canReserveShort 

Arguments

Name Type Description
_amount uint256

_freeLongPool

function _freeLongPool(uint256 _amount) internal nonpayable

Arguments

Name Type Description
_amount uint256

_freeShortPool

function _freeShortPool(uint256 _amount) internal nonpayable

Arguments

Name Type Description
_amount uint256

_addcTokenPoolProfit

function _addcTokenPoolProfit(int256 _profit) internal nonpayable

Arguments

Name Type Description
_profit int256

getcTokenExchangeRate

function getcTokenExchangeRate() public view
returns(uint256)

Arguments

Name Type Description

Contracts