Integration guide
Smart contract
To interact with an 88mph pool, you will mostly call the pool's DInterest contract. You can find the source code on our GitHub.
Creating a deposit
Creating a deposit has two steps:
Give ERC-20 approval to the DInterest contract, the amount of which is at least the deposit amount.
Call
DInterest::deposit()
Once an account makes a deposit, the account will also receive vested MPH rewards.
Example
Trace and map out all the contract interactions with this deposit transaction example.
Withdrawing a deposit
Withdrawing a deposit has the following steps:
Call
DInterest::withdraw()
Set virtualTokenAmount
to type(uint256).max
to withdraw all funds from the deposit, otherwise set it to some proportion of getDeposit(depositID).virtualTokenTotalSupply
to do a partial withdrawal. An easy way to determine the value for this field is that after maturation, virtualTokenAmount
equals the amount of underlying tokens that will be withdrawn.
Set early
to true
if withdrawing before maturation, false
if withdrawing after maturation.
Example
Calculate Interest Amount
Function on the DInterest contract to call can be found here.
If you want to know the interest you'll earn on a 100 DAI deposit for 1 year, the function call would look like calculateInterestAmount(100*1e18, 31556952)
where 100*1e18 is 100 DAI in wei and 31556952 is the number of seconds in a year.
The returned value is the amount of DAI, in wei, you'd earn in fixed-rate interest before protocol fees are taken into account. To account for the fee, you'll need to call getInterestFeeAmount()
on the feeModel contract.
Once you have both the interest amount (before fees) and the fee amount, subtract the two values to get the amount of interest earned by the depositor after fees. Divide that value by the original deposit amount to get the APR (some additional math is needed for deposit length of less than a year). Here is an example of how we do this in our frontend, which calculates the APR for a 10,000 token deposit for 30 days.
Withdrawing vested MPH rewards
Each deposit yields vested MPH rewards to the user. This is handled by the Vesting02 contract. The vesting is linear and continuous, and is done over the deposit period. If a deposit is withdrawn earlier than the maturation date, the remaining vested rewards are forfeited.
The vesting streams are represented using 1-indexed ERC-721 NFTs, so that they are easily transferrable.
In order to withdraw vested MPH, you need to call Vesting02::withdraw(uint256 vestID)
. You need the index of a vesting NFT, vestID
, in order to withdraw the MPH. You can obtain this value using the Vesting02::depositIDToVestID
mapping using the pool address and deposit ID.
Example
Buying yield tokens
Buying yield tokens takes two steps:
Approve deposit tokens to the DInterest contract, the amount of which should be at least the cost of the bond.
Call
DInterest::fund()
with the ID of the deposit to buy yield tokens from and the amount to pay.
Note that if the amount to pay is greater than the value of the available yield tokens, all of the available yield tokens will be purchased.
Example
Zero coupon bonds
Minting a zero coupon bond
Redeeming zero coupon bonds for their face value
REST API
We offer a REST API for fetching basic info of 88mph pools. The endpoint is at https://api.88mph.app/v3/pools. The only supported method is GET.
Example response
Deployment
Read DEPLOY_README.md
Notes:
The mainnet contract addresses are available here https://github.com/88mphapp/88mph-contracts/tree/v3/deployments/mainnet and the rinkeby here https://github.com/88mphapp/88mph-contracts/tree/v3/deployments/rinkeby / https://github.com/88mphapp/88mph-contracts/blob/v3/deployments-exported/rinkeby.json
Last updated