88mph Docs
Search…
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:
  1. 1.
    Give ERC-20 approval to the DInterest contract, the amount of which is at least the deposit amount.
  2. 2.
    Call DInterest::deposit()
Once an account makes a deposit, the account will also receive vested MPH rewards.

Example

1
DInterest pool = DInterest(0xdead);
2
ERC20 token = ERC20(0x6b175474e89094c44da98b954eedeac495271d0f); // DAI
3
uint256 depositAmount = 3 * 10 ** 18; // 3 DAI
4
uint256 maturationTimestamp = now + 365 days;
5
​require(token.approve(address(pool), depositAmount));
6
// deposit returns the ID of the deposit
7
uint64 depositID = pool.deposit(depositAmount, maturationTimestamp);
Copied!

Withdrawing a deposit

Withdrawing a deposit has the following steps:
  1. 1.
    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

1
DInterest pool = DInterest(0xdead);
2
uint64 depositID = 10;
3
uint256 virtualTokenAmount = type(uint256).max; // withdraw all funds
4
bool early = false; // withdrawing after maturation​
5
pool.withdraw(depositID, virtualTokenAmount, early);
Copied!

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

1
Vesting02 vesting = Vesting02(0xdead);
2
uint64 vestID = 10;​ // msg.sender needs to own the vesting NFT
3
vesting.withdraw(vestID);
Copied!

Buying yield tokens

Buying yield tokens takes two steps:
  1. 1.
    Approve deposit tokens to the DInterest contract, the amount of which should be at least the cost of the bond.
  2. 2.
    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

1
DInterest pool = DInterest(0xdead);
2
ERC20 token = ERC20(0x6b175474e89094c44da98b954eedeac495271d0f); // DAI​
3
uint64 depositID = 5;
4
uint256 payAmount = 3 * 10**18; // 3 DAI
5
require(token.approve(address(pool), payAmount));
6
uint64 fundingID = pool.fund(depositID, payAmount);
Copied!

Zero coupon bonds

Minting a zero coupon bond

1
ZeroCouponBond bond = ZeroCouponBond(0xdead);
2
ERC20 token = ERC20(0x6b175474e89094c44da98b954eedeac495271d0f); // DAI
3
uint256 depositAmount = 3 * 10**18; // 3 DAI
4
require(token.approve(address(bond), depositAmount));
5
​// mint returns the amount of zero coupon bonds minted
6
// which can be 1-for-1 redeemed for the underlying token
7
// at maturation
8
uint256 mintedZCBAmount = bond.mint(depositAmount);
Copied!

Redeeming zero coupon bonds for their face value

1
ZeroCouponBond bond = ZeroCouponBond(0xdead);​
2
uint256 redeemAmount = 30 * (10 ** 18); // 30 DAI
3
// setting this to true will withdraw the ZCB's deposit
4
// from the 88mph pool if it hasn't been done yet
5
// which will increase the gas cost but also
6
// ensures that the redemption succeeds
7
bool withdrawDepositIfNeeded = true;
8
bond.redeem(redeemAmount, withdrawDepositIfNeeded);
Copied!

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

1
[ { "address": "0xb1abaac351e06d40441cf2cd97f6f0098e6473f2", "token": "0x5b5cfe992adac0c9d48e05854b2d91c73a003858", "tokenSymbol": "CRV:HUSD", "protocol": "Harvest", "oneYearInterestRate": "3.6621277863445296", "mphAPY": "60.8988450243270707253", "totalValueLockedInToken": "1548211.678555032702255836", "totalValueLockedInUSD": "1548211.678555032702255836" }, ...]
Copied!

Deployment

Notes:
Last modified 3mo ago