Currency units
import Maker from '@makerdao/dai';
// Multi-Collateral Dai
import { ETH, BAT, DAI } from '@makerdao/dai-plugin-mcd';
const maker = await Maker.create(...);
const mgr = maker.service('mcd:cdpManager');
// lock BAT into a new vault and draw Dai
const vault = await mgr.openLockAndDraw(
'BAT-A',
BAT(100),
DAI(100)
);
// Single-Collateral Sai
const {
MKR,
SAI,
ETH,
WETH,
PETH,
USD_ETH,
USD_MKR,
USD_SAI
} = Maker;
// These are all identical:
// each method has a default type
cdp.lockEth(0.25);
cdp.lockEth('0.25');
// you can pass in a currency unit instance
cdp.lockEth(ETH(0.25));
// currency units have convenient converter methods
cdp.lockEth(ETH.wei(250000000000000000));
const eth = ETH(5);
eth.toString() == '5.00 ETH';
const price = USD_ETH(500);
price.toString() == '500.00 USD/ETH';
// multiplication handles units
const usd = eth.times(price);
usd.toString() == '2500.00 USD';
// division does too
const eth2 = usd.div(eth);
eth2.isEqual(eth);Last updated