Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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();
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();
}
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();
}