How to use the @makerdao/dai.USD 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 / topup / src / topup.js View on Github external
throw new Error(`Invalid value for targetRatio: ${err}`);
  }

  const maker = Maker.create(process.env.NETWORK, {
    privateKey: process.env.PRIVATE_KEY,
    log: false,
    provider: {
      infuraProjectId
    }
  });
  const cdp = await maker.getCdp(cdpId);

  const collateral = await cdp.getCollateralValue();
  console.log(`collateral: ${collateral}`);

  const debt = await cdp.getDebtValue(Maker.USD);
  console.log(`debt: ${debt}`);

  const collateralPrice = await maker.service('price').getEthPrice();
  console.log(`price: ${collateralPrice}`);

  const ratio = await cdp.getCollateralizationRatio();
  if (targetRatio.gt(ratio)) {
    let addAmount = debt
      .times(targetRatio)
      .minus(collateral.times(collateralPrice))
      .div(collateralPrice)
      .toNumber();

    if (addAmount < MIN_ADD_AMOUNT) {
      addAmount = MIN_ADD_AMOUNT;
    } else {
github MyEtherWallet / MyEtherWallet / src / dapps / MakerDai / components / ImportCDP / ImportCDP.vue View on Github external
async getCdp(id) {
      this.cdp = await this.maker.getCdp(id);
      this.liqPrice = await this.cdp.getLiquidationPrice();
      this.isSafe = await this.cdp.isSafe();
      this.debtValue = (await this.cdp.getDebtValue()).toBigNumber();
      this.collatRatio = await this.cdp.getCollateralizationRatio();
      this.ethCollateral = (await this.cdp.getCollateralValue()).toBigNumber();
      this.pethCollateral = (await this.cdp.getCollateralValue(
        Maker.PETH
      )).toBigNumber();
      this.usdCollateral = (await this.cdp.getCollateralValue(
        Maker.USD
      )).toBigNumber();
      this.maxEthDraw = bnOver(
        this.liquidationRatio,
        this.usdCollateral,
        this.ethPrice
      ).toString();
      this.maxPethDraw = bnOver(
        this.pethPrice,
        this.pethCollateral,
        this.liquidationRatio
      ).toString();
      this.maxDaiDraw = bnOver(
        this.ethPrice,
        this.ethCollateral,
        this.liquidationRatio
      ).minus(this.debtValue).toString();
github MyEtherWallet / MyEtherWallet / src / dapps / MakerDai / MakerMcdCDP.js View on Github external
this.cdp = await this.services.getCdp(cdpId, this._proxyAddress);
    } else {
      this.cdp = await this.services.getCdp(cdpId, false);
    }

    const liqPrice = await this.cdp.getLiquidationPrice();
    this._liqPrice = liqPrice.toBigNumber().toFixed(2);
    this.isSafe = await this.cdp.isSafe();
    this.debtValue = (await this.cdp.getDebtValue()).toBigNumber();
    this._collatRatio = await this.cdp.getCollateralizationRatio();
    this.ethCollateral = (await this.cdp.getCollateralValue()).toBigNumber();
    this.pethCollateral = (
      await this.cdp.getCollateralValue(Maker.PETH)
    ).toBigNumber();
    this._usdCollateral = (
      await this.cdp.getCollateralValue(Maker.USD)
    ).toBigNumber();
  }
github MyEtherWallet / MyEtherWallet / src / dapps / MakerSai / MakerCDP.js View on Github external
if (this._proxyAddress) {
      this.cdp = await this.services.getCdp(cdpId, this._proxyAddress);
    } else {
      this.cdp = await this.services.getCdp(cdpId, false);
    }
    const liqPrice = await this.cdp.getLiquidationPrice();
    this._liqPrice = liqPrice.toBigNumber().toFixed(2);
    this.isSafe = await this.cdp.isSafe();
    this.debtValue = (await this.cdp.getDebtValue()).toBigNumber();
    this._collatRatio = await this.cdp.getCollateralizationRatio();
    this.ethCollateral = (await this.cdp.getCollateralValue()).toBigNumber();
    this.pethCollateral = (
      await this.cdp.getCollateralValue(Maker.PETH)
    ).toBigNumber();
    this._usdCollateral = (
      await this.cdp.getCollateralValue(Maker.USD)
    ).toBigNumber();
  }

@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