diff --git a/components/sidebar/context/makerdao/SidebarMakerdaoBorrow.vue b/components/sidebar/context/makerdao/SidebarMakerdaoBorrow.vue
new file mode 100644
index 0000000..6ff635a
--- /dev/null
+++ b/components/sidebar/context/makerdao/SidebarMakerdaoBorrow.vue
@@ -0,0 +1,184 @@
+
+
+ Borrow {{ symbol }}
+
+
+
+ {{ formatNumber(debt) }} {{ symbol }}
+
+
+
+
+ Amount to borrow
+
+
+
+
+
+
+ Projected Debt Position
+
+
+
+
+
+
+ {{ formatUsdMax(liquidationPrice, liquidationMaxPrice) }}
+ / {{ formatUsd(liquidationMaxPrice) }}
+
+
+
+
+
+ Borrow
+
+
+
+
+
+
+
+
+
diff --git a/components/sidebar/context/makerdao/SidebarMakerdaoPayback.vue b/components/sidebar/context/makerdao/SidebarMakerdaoPayback.vue
new file mode 100644
index 0000000..8da43bc
--- /dev/null
+++ b/components/sidebar/context/makerdao/SidebarMakerdaoPayback.vue
@@ -0,0 +1,207 @@
+
+
+ Payback {{ symbol }}
+
+
+
+
+ {{ formatNumber(debt) }} {{ symbol }}
+
+
+
+
+
+ {{ formatNumber(balance) }} {{ symbol }}
+
+
+
+
+
+ Amount to supply
+
+
+
+
+
+
+
+
+
+
+
+ Projected Debt Position
+
+
+
+
+
+
+ {{ formatUsdMax(liquidationPrice, liquidationMaxPrice) }}
+ / {{ formatUsd(liquidationMaxPrice) }}
+
+
+
+
+
+ Payback
+
+
+
+
+
+
+
+
+
diff --git a/composables/useMakerdaoPosition.ts b/composables/useMakerdaoPosition.ts
index c8bf81e..969dbf7 100644
--- a/composables/useMakerdaoPosition.ts
+++ b/composables/useMakerdaoPosition.ts
@@ -1,4 +1,4 @@
-import { computed, ref, watch } from "@nuxtjs/composition-api";
+import { computed, Ref, ref, watch } from "@nuxtjs/composition-api";
import BigNumber from "bignumber.js";
BigNumber.config({ POW_PRECISION: 200 });
import abis from "~/constant/abis";
@@ -50,7 +50,7 @@ const vault = computed(() => {
return defaultVault;
});
-export function useMakerdaoPosition() {
+export function useMakerdaoPosition(collateralAmountRef: Ref =null, debtAmountRef: Ref = null) {
const { web3, chainId, networkName } = useWeb3();
const { activeAccount } = useDSA();
const { isZero, ensureValue, times, div, max, gt } = useBigNumber();
@@ -77,14 +77,20 @@ export function useMakerdaoPosition() {
const rate = computed(() => ensureValue(vault.value.rate).toFixed());
const netValue = computed(() => ensureValue(vault.value.netValue).toFixed());
- const status = computed(() => ensureValue(vault.value.status).toFixed());
+ const status = computed(() => {
+ if (!collateralAmountRef || !debtAmountRef) return ensureValue(vault.value.status).toFixed()
+ return isZero(collateralAmountRef.value) && !isZero(debtAmountRef.value)
+ ? '1.1'
+ : div(debtAmountRef.value, times(collateralAmountRef.value, price.value)).toFixed()
+ })
const liquidationPrice = computed(() => {
- return max(
- div(div(debt.value, collateral.value), liquidation.value),
- "0"
- ).toFixed();
- });
+ if (!collateralAmountRef || !debtAmountRef)
+ return max(div(div(debt.value, collateral.value), liquidation.value), '0').toFixed()
+ return isZero(collateralAmountRef.value) && !isZero(debtAmountRef.value)
+ ? times(price.value, '1.1').toFixed()
+ : max(div(div(debtAmountRef.value, collateralAmountRef.value), liquidation.value), '0').toFixed()
+ })
const debt = computed(() => ensureValue(vault.value.debt).toFixed());
const minDebt = computed(() => vaultTypes.value[0]?.totalFloor || "5000");
diff --git a/composables/useSidebar.ts b/composables/useSidebar.ts
index 2f10f85..e4e76dc 100644
--- a/composables/useSidebar.ts
+++ b/composables/useSidebar.ts
@@ -23,6 +23,8 @@ import SidebarCompoundSupply from '~/components/sidebar/context/compound/Sidebar
import SidebarCompoundBorrow from '~/components/sidebar/context/compound/SidebarCompoundBorrow.vue'
import SidebarCompoundPayback from '~/components/sidebar/context/compound/SidebarCompoundPayback.vue'
+import SidebarMakerdaoBorrow from '~/components/sidebar/context/makerdao/SidebarMakerdaoBorrow.vue'
+import SidebarMakerdaoPayback from '~/components/sidebar/context/makerdao/SidebarMakerdaoPayback.vue'
const sidebars = {
"#overview" : {component: SidebarOverview, back : false, close : true },
@@ -47,6 +49,12 @@ const sidebars = {
"/mainnet/compound#supply": { component: SidebarCompoundSupply },
"/mainnet/compound#borrow": { component: SidebarCompoundBorrow },
"/mainnet/compound#payback": { component: SidebarCompoundPayback },
+
+ "/mainnet/maker": { component: null },
+ "/mainnet/maker#withdraw": { component: null },
+ "/mainnet/maker#supply": { component: null },
+ "/mainnet/maker#borrow": { component: SidebarMakerdaoBorrow },
+ "/mainnet/maker#payback": { component: SidebarMakerdaoPayback },
};
const sidebar = ref(null);
diff --git a/composables/useValidators.ts b/composables/useValidators.ts
index 485cc4d..a2938a4 100644
--- a/composables/useValidators.ts
+++ b/composables/useValidators.ts
@@ -1,9 +1,11 @@
import { useBigNumber } from "./useBigNumber";
import { useFormatting } from "./useFormatting";
+import { useMakerdaoPosition } from "./useMakerdaoPosition";
export function useValidators() {
- const { formatNumber } = useFormatting()
- const { isZero, minus, eq, gt } = useBigNumber();
+ const { formatNumber } = useFormatting();
+ const { isZero, minus, eq, gt, lt, gte, plus } = useBigNumber();
+ const { minDebt: makerMinDebt, vaultTypes } = useMakerdaoPosition();
function validateAmount(amountParsed, balance = null, options = null) {
const mergedOptions = Object.assign(
@@ -39,21 +41,61 @@ export function useValidators() {
return null;
}
- function validateLiquidity(borrow, availableLiquidity, tokenSymbol, withdraw = false) {
+ function validateLiquidity(
+ borrow,
+ availableLiquidity,
+ tokenSymbol,
+ withdraw = false
+ ) {
if (gt(borrow, availableLiquidity)) {
- let action = 'borrow'
+ let action = "borrow";
if (withdraw) {
- action = 'withdraw'
+ action = "withdraw";
}
- return `Not enough liquidity to ${action} ${formatNumber(borrow, 2)} ${tokenSymbol}`
+ return `Not enough liquidity to ${action} ${formatNumber(
+ borrow,
+ 2
+ )} ${tokenSymbol}`;
}
- return null
+ return null;
+ }
+
+ function validateMakerDebt(
+ debtParsed,
+ minDebt = makerMinDebt.value,
+ vaultId
+ ) {
+ if (lt(debtParsed, minDebt) && gt(debtParsed, "0")) {
+ const vaultText = vaultId
+ ? vaultId !== "0"
+ ? `on vault #${vaultId}`
+ : `on new vault`
+ : "";
+ return `Minimum debt requirement is ${minDebt} DAI ${vaultText}`;
+ }
+
+ return null;
+ }
+
+ function validateMakerDebtCeiling(vaultType, debtParsed = 0) {
+ const vault = vaultTypes.value.find(v => v.type === vaultType);
+ const { debtCeiling, totalDebt } = vault || {};
+
+ if (!isZero(debtCeiling) && !isZero(totalDebt)) {
+ const total = plus(totalDebt, debtParsed);
+ return gte(total, debtCeiling)
+ ? `${vaultType} Collateral reached debt ceiling`
+ : null;
+ }
+ return null;
}
return {
validateAmount,
validateLiquidation,
validateIsLoggedIn,
- validateLiquidity
+ validateLiquidity,
+ validateMakerDebt,
+ validateMakerDebtCeiling
};
}
diff --git a/pages/mainnet/maker.vue b/pages/mainnet/maker.vue
index 4bce698..b9a7c45 100644
--- a/pages/mainnet/maker.vue
+++ b/pages/mainnet/maker.vue
@@ -84,12 +84,16 @@
- {{ formatUsdMax(liquidationPrice, liquidationMaxPrice) }} / {{ formatUsd(liquidationMaxPrice) }}
+ {{ formatUsdMax(liquidationPrice, liquidationMaxPrice) }} /
+ {{ formatUsd(liquidationMaxPrice) }}
Liquidation (ETH)
-
+
@@ -131,7 +135,7 @@