How to use the @makerdao/dai.WETH function in @makerdao/dai

To help you get started, we’ve selected a few @makerdao/dai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github makerdao / integration-examples / leverage / lib / leverage.js View on Github external
//get initial peth collateral
    const initialPethCollateral = await cdp.getCollateralValue(Maker.PETH);
    log.state(`${principal} ETH is worth ${initialPethCollateral}`);

    // calculate how much Dai we need to draw in order
    // to achieve the desired collateralization ratio
    let drawAmt = Math.floor(principal * priceEth / collatRatio);
    const drawTx = cdp.drawDai(drawAmt);
    await maker.service('transactionManager').confirm(drawTx);
    log.action(`drew ${drawAmt} Dai`);

    // do `iterations` round trip(s) to the exchange
    for (let i = 0; i < iterations; i++) {
      // exchange the drawn Dai for W-ETH
      let tx = await maker.service('exchange').sellDai(drawAmt, Maker.WETH);

      // observe the amount of W-ETH received from the exchange
      // by calling `fillAmount` on the returned transaction object
      let returnedWeth = tx.fillAmount();
      log.action(`exchanged ${drawAmt} Dai for ${returnedWeth}`);

      // lock all of the W-ETH we just received into our CDP
      await cdp.lockWeth(returnedWeth);
      log.action(`locked ${returnedWeth}`);

      // calculate how much Dai we need to draw in order to
      // re-attain our desired collateralization ratio
      drawAmt = Math.floor(returnedWeth.toNumber() * priceEth / collatRatio);
      await cdp.drawDai(drawAmt);
      log.action(`drew ${drawAmt} Dai`);
    }

@makerdao/dai

Library for interacting with the Dai Stablecoin System.

MIT
Latest version published 3 years ago

Package Health Score

42 / 100
Full package analysis