Skip to content

Commit

Permalink
add(downpayment for spcific protocol)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermake committed Nov 1, 2024
1 parent abd0090 commit 6c08e2b
Show file tree
Hide file tree
Showing 26 changed files with 2,495 additions and 2,052 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ coverage

/cypress/videos/
/cypress/screenshots/
public/downpayment-range/*

# Editor directories and files
.idea
Expand Down
3,134 changes: 1,289 additions & 1,845 deletions package-lock.json

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@cosmjs/tendermint-rpc": "0.32.4",
"@headlessui/vue": "^1.7.19",
"@heroicons/vue": "^2.1.5",
"@injectivelabs/sdk-ts": "^1.14.13",
"@injectivelabs/sdk-ts": "^1.14.5",
"@keplr-wallet/crypto": "0.12.144",
"@keplr-wallet/types": "0.12.144",
"@keplr-wallet/unit": "0.12.144",
Expand All @@ -38,7 +38,7 @@
"@ledgerhq/hw-transport-webusb": "^6.29.4",
"@ledgerhq/logs": "^6.12.0",
"@nolus/nolusjs": "^2.4.17",
"@skip-go/client": "^0.10.3",
"@skip-go/client": "^0.11.1",
"chart.js": "^4.4.5",
"chartjs-adapter-date-fns": "^3.0.0",
"cosmjs-types": "^0.9.0",
Expand All @@ -54,35 +54,35 @@
"web-components": "github:nolus-protocol/web-components#v1.6.1"
},
"devDependencies": {
"@intlify/unplugin-vue-i18n": "^4.0.0",
"@intlify/unplugin-vue-i18n": "^5.2.0",
"@rushstack/eslint-patch": "^1.10.1",
"@tsconfig/node20": "^20.1.2",
"@tsconfig/node20": "^20.1.4",
"@types/jsdom": "^21.1.6",
"@types/node": "^20.11.10",
"@vitejs/plugin-vue": "^5.1.2",
"@types/node": "^22.8.6",
"@vitejs/plugin-vue": "^5.1.4",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"@vue/test-utils": "^2.4.4",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.5.1",
"autoprefixer": "^10.4.17",
"buffer": "^6.0.3",
"cypress": "^13.13.0",
"cypress": "^13.15.1",
"eslint": "^8.57.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-vue": "^9.27.0",
"husky": "^9.0.10",
"jsdom": "^24.1.0",
"npm-run-all2": "^6.2.2",
"postcss": "^8.4.39",
"eslint-plugin-vue": "^9.30.0",
"husky": "^9.1.6",
"jsdom": "^25.0.1",
"npm-run-all2": "^7.0.1",
"postcss": "^8.4.47",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.4",
"sass": "^1.77.0",
"prettier-plugin-tailwindcss": "^0.6.8",
"sass": "^1.80.5",
"start-server-and-test": "^2.0.3",
"tailwindcss": "^3.4.1",
"typescript": "~5.5.3",
"vite": "^5.4.0",
"tailwindcss": "^3.4.14",
"typescript": "~5.6.3",
"vite": "^5.4.10",
"vite-plugin-node-polyfills": "^0.22.0",
"vitest": "^2.0.1",
"vue-tsc": "^2.0.26"
"vitest": "^2.1.4",
"vue-tsc": "^2.1.10"
}
}
13 changes: 7 additions & 6 deletions src/common/components/modals/long/LongFormComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<Tooltip :content="$t('message.borrowed-tooltip')" />
</p>
<p class="align-center mb-2 mt-[14px] flex justify-end text-neutral-typography-200">
<template v-if="FREE_INTEREST_ASSETS.includes(selectedAssetDenom)">
<template v-if="freeInterest?.includes(selectedAssetDenom)">
<span
v-if="annualInterestRate"
class="line-throught-gray text-[#8396B1]"
Expand Down Expand Up @@ -134,13 +134,12 @@ import { CurrencyUtils } from "@nolus/nolusjs";
import { useWalletStore } from "@/common/stores/wallet";
import { Dec } from "@keplr-wallet/unit";
import { useOracleStore } from "@/common/stores/oracle";
import { AssetUtils, getMicroAmount, LeaseUtils, SkipRouter } from "@/common/utils";
import { AppUtils, AssetUtils, LeaseUtils, SkipRouter } from "@/common/utils";
import { useApplicationStore } from "@/common/stores/application";
import { CurrencyDemapping, CurrencyMapping } from "@/config/currencies";
import { CurrencyMapping } from "@/config/currencies";
import {
Contracts,
FREE_INTEREST_ASSETS,
IGNORE_DOWNPAYMENT_ASSETS,
IGNORE_LEASE_ASSETS,
MONTHS,
Expand All @@ -157,8 +156,10 @@ const swapFee = ref(0);
const timeOut = 200;
let time: NodeJS.Timeout;
let freeInterest = ref<string[]>();
onMounted(() => {
onMounted(async () => {
freeInterest.value = await AppUtils.getFreeInterest();
if (props.modelValue.dialogSelectedCurrency) {
const [ticker, protocol] = props.modelValue.dialogSelectedCurrency.split("@");
for (const balance of balances.value) {
Expand Down Expand Up @@ -290,7 +291,7 @@ const balances = computed(() => {
return false;
}
if (IGNORE_DOWNPAYMENT_ASSETS.includes(ticker)) {
if (IGNORE_DOWNPAYMENT_ASSETS.includes(ticker) || IGNORE_DOWNPAYMENT_ASSETS.includes(`${ticker}@${protocol}`)) {
return false;
}
Expand Down
52 changes: 24 additions & 28 deletions src/common/components/modals/long/LongMainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ const state = ref({
const getLeases = inject("getLeases", () => {});
let leaseAssetPrice: string | null;
let downPaymentRange: { [key: string]: { min: number; max: number } };
const downPaymentRange = ref<{ [key: string]: { min: number; max: number } }>();
onMounted(async () => {
downPaymentRange = await AppUtils.getDownpaymentRange();
setDownpaymentRange();
});
watch(walletRef.balances, async () => {
Expand Down Expand Up @@ -186,6 +186,7 @@ watch(
() => state.value.selectedCurrency,
() => {
calculate();
setDownpaymentRange();
}
);
Expand All @@ -196,6 +197,11 @@ watch(
}
);
async function setDownpaymentRange() {
const [_, p] = state.value.selectedCurrency.key.split("@");
downPaymentRange.value = await AppUtils.getDownpaymentRange(p);
}
async function calculate() {
try {
const downPaymentAmount = state.value.downPayment;
Expand Down Expand Up @@ -323,28 +329,18 @@ function validateMinMaxValues(): boolean {
const downPaymentAmount = state.value.downPayment;
const currentBalance = state.value.selectedDownPaymentCurrency;
const currency = state.value.selectedCurrency;
const downPaymentCurrency = state.value.selectedDownPaymentCurrency;
const range = downPaymentRange?.[currency.ticker];
const rangedownPaymentCurrency = downPaymentRange?.[downPaymentCurrency.ticker];
const values: number[] = [];
if (range?.max != null) {
values.push(range.max);
}
if (rangedownPaymentCurrency?.max != null) {
values.push(rangedownPaymentCurrency.max);
}
const max = Math.min(...values);
const [c, _] = state.value.selectedCurrency.key.split("@");
const range = downPaymentRange.value?.[c];
if (currentBalance) {
if (downPaymentAmount || downPaymentAmount !== "") {
const leaseMax = new Dec(max);
const leaseMin = new Dec(range.min);
const price = oracle.prices[state.value.selectedDownPaymentCurrency.key as string];
const max = new Dec(range?.max ?? 0);
const min = new Dec(range?.min ?? 0);
const price = oracle.prices[currentBalance!.ibcData as string];
const leaseMax = max.quo(new Dec(price.amount));
const leaseMin = min.quo(new Dec(price.amount));
const downPaymentAmountInMinimalDenom = CurrencyUtils.convertDenomToMinimalDenom(
downPaymentAmount,
Expand All @@ -357,20 +353,20 @@ function validateMinMaxValues(): boolean {
currentBalance.decimal_digits
).toDec();
if (balance.lt(leaseMin)) {
if (balance.lt(min)) {
state.value.downPaymentErrorMsg = i18n.t("message.lease-min-error", {
minAmount: Math.ceil((range.min / Number(price.amount)) * 1000) / 1000,
maxAmount: Math.ceil((max / Number(price.amount)) * 1000) / 1000,
symbol: currentBalance.shortName
minAmount: leaseMin.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
maxAmount: leaseMax.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
symbol: state.value.selectedDownPaymentCurrency.shortName
});
isValid = false;
}
if (balance.gt(leaseMax)) {
if (balance.gt(max)) {
state.value.downPaymentErrorMsg = i18n.t("message.lease-max-error", {
minAmount: Math.ceil((range.min / Number(price.amount)) * 1000) / 1000,
maxAmount: Math.ceil((max / Number(price.amount)) * 1000) / 1000,
symbol: currentBalance.shortName
minAmount: leaseMin.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
maxAmount: leaseMax.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
symbol: state.value.selectedDownPaymentCurrency.shortName
});
isValid = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { AssetBalance } from "@/common/stores/wallet/types";
import MarketCloseFormComponent from "./MarketCloseFormComponent.vue";
import ConfirmComponent from "../templates/ConfirmComponent.vue";
import { computed, inject, ref, watch, type PropType, onMounted, onUnmounted } from "vue";
import { computed, inject, ref, watch, type PropType, onUnmounted } from "vue";
import { Lease } from "@nolus/nolusjs/build/contracts";
import { CurrencyUtils, NolusClient, NolusWallet } from "@nolus/nolusjs";
import { Dec, Int } from "@keplr-wallet/unit";
Expand Down
7 changes: 3 additions & 4 deletions src/common/components/modals/repay/RepayMainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { AssetBalance } from "@/common/stores/wallet/types";
import RepayFormComponent from "./RepayFormComponent.vue";
import ConfirmComponent from "@/common/components/modals/templates/ConfirmComponent.vue";
import { computed, inject, ref, watch, type PropType, onMounted, onUnmounted } from "vue";
import { computed, inject, ref, watch, type PropType, onUnmounted } from "vue";
import { Lease } from "@nolus/nolusjs/build/contracts";
import { CurrencyUtils, NolusClient, NolusWallet } from "@nolus/nolusjs";
import { Dec, Int } from "@keplr-wallet/unit";
Expand All @@ -42,8 +42,7 @@ import { useI18n } from "vue-i18n";
import { coin } from "@cosmjs/amino";
import { useOracleStore } from "@/common/stores/oracle";
import { useApplicationStore } from "@/common/stores/application";
import { AppUtils } from "@/common/utils";
import { CurrencyDemapping, CurrencyMapping } from "@/config/currencies";
import { CurrencyDemapping } from "@/config/currencies";
import {
NATIVE_ASSET,
Expand Down Expand Up @@ -104,7 +103,7 @@ const balances = computed(() => {
return false;
}
if (IGNORE_DOWNPAYMENT_ASSETS.includes(ticker)) {
if (IGNORE_DOWNPAYMENT_ASSETS.includes(ticker) || IGNORE_DOWNPAYMENT_ASSETS.includes(`${ticker}@${protocol}`)) {
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/common/components/modals/short/ShortFormComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<Tooltip :content="$t('message.borrowed-tooltip')" />
</p>
<p class="align-center mb-2 mt-[14px] flex justify-end text-neutral-typography-200">
<!-- <template v-if="FREE_INTEREST_ASSETS.includes(selectedAssetDenom.shortName)">
<!-- <template v-if="freeInterest?.includes(selectedAssetDenom)">
<span
v-if="annualInterestRate"
class="line-throught-gray text-[#8396B1]"
Expand Down Expand Up @@ -133,7 +133,7 @@ import { CurrencyUtils } from "@nolus/nolusjs";
import { useWalletStore } from "@/common/stores/wallet";
import { Dec } from "@keplr-wallet/unit";
import { useOracleStore } from "@/common/stores/oracle";
import { AssetUtils, getMicroAmount, LeaseUtils, SkipRouter } from "@/common/utils";
import { AppUtils, AssetUtils, LeaseUtils, SkipRouter } from "@/common/utils";
import { useApplicationStore } from "@/common/stores/application";

import { MONTHS, NATIVE_NETWORK, PERMILLE, PositionTypes, ProtocolsConfig } from "@/config/global";
Expand All @@ -145,8 +145,10 @@ const swapFee = ref(0);

const timeOut = 200;
let time: NodeJS.Timeout;
let freeInterest = ref<string[]>();

onMounted(() => {
onMounted(async () => {
freeInterest.value = await AppUtils.getFreeInterest();
if (props.modelValue.dialogSelectedCurrency) {
const [ticker, protocol] = props.modelValue.dialogSelectedCurrency.split("@");
for (const balance of totalBalances.value) {
Expand Down
52 changes: 24 additions & 28 deletions src/common/components/modals/short/ShortMainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ const state = ref({
const getLeases = inject("getLeases", () => {});
let leaseAssetPrice: string | null;
let downPaymentRange: { [key: string]: { min: number; max: number } };
const downPaymentRange = ref<{ [key: string]: { min: number; max: number } }>();
onMounted(async () => {
downPaymentRange = await AppUtils.getDownpaymentRange();
setDownpaymentRange();
});
watch(walletRef.balances, async () => {
Expand Down Expand Up @@ -177,6 +177,7 @@ watch(
() => state.value.selectedCurrency,
() => {
calculate();
setDownpaymentRange();
}
);
Expand All @@ -187,6 +188,11 @@ watch(
}
);
async function setDownpaymentRange() {
const [_, p] = state.value.selectedCurrency.key.split("@");
downPaymentRange.value = await AppUtils.getDownpaymentRange(p);
}
async function calculate() {
try {
const downPaymentAmount = state.value.downPayment;
Expand Down Expand Up @@ -309,28 +315,18 @@ function validateMinMaxValues(): boolean {
const downPaymentAmount = state.value.downPayment;
const currentBalance = state.value.selectedDownPaymentCurrency;
const currency = state.value.selectedCurrency;
const downPaymentCurrency = state.value.selectedDownPaymentCurrency;
const range = downPaymentRange?.[currency.ticker];
const rangedownPaymentCurrency = downPaymentRange?.[downPaymentCurrency.ticker];
const values: number[] = [];
if (range?.max != null) {
values.push(range.max);
}
if (rangedownPaymentCurrency?.max != null) {
values.push(rangedownPaymentCurrency.max);
}
const max = Math.min(...values);
const [c, _] = state.value.selectedCurrency.key.split("@");
const range = downPaymentRange.value?.[c];
if (currentBalance) {
if (downPaymentAmount || downPaymentAmount !== "") {
const leaseMax = new Dec(max);
const leaseMin = new Dec(range.min);
const price = oracle.prices[state.value.selectedDownPaymentCurrency.key as string];
const max = new Dec(range?.max ?? 0);
const min = new Dec(range?.min ?? 0);
const price = oracle.prices[currentBalance!.ibcData as string];
const leaseMax = max.quo(new Dec(price.amount));
const leaseMin = min.quo(new Dec(price.amount));
const downPaymentAmountInMinimalDenom = CurrencyUtils.convertDenomToMinimalDenom(
downPaymentAmount,
Expand All @@ -343,20 +339,20 @@ function validateMinMaxValues(): boolean {
currentBalance.decimal_digits
).toDec();
if (balance.lt(leaseMin)) {
if (balance.lt(min)) {
state.value.downPaymentErrorMsg = i18n.t("message.lease-min-error", {
minAmount: Math.ceil((range.min / Number(price.amount)) * 1000) / 1000,
maxAmount: Math.ceil((max / Number(price.amount)) * 1000) / 1000,
symbol: currentBalance.shortName
minAmount: leaseMin.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
maxAmount: leaseMax.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
symbol: state.value.selectedDownPaymentCurrency.shortName
});
isValid = false;
}
if (balance.gt(leaseMax)) {
if (balance.gt(max)) {
state.value.downPaymentErrorMsg = i18n.t("message.lease-max-error", {
minAmount: Math.ceil((range.min / Number(price.amount)) * 1000) / 1000,
maxAmount: Math.ceil((max / Number(price.amount)) * 1000) / 1000,
symbol: currentBalance.shortName
minAmount: leaseMin.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
maxAmount: leaseMax.toString(state.value.selectedDownPaymentCurrency.decimal_digits),
symbol: state.value.selectedDownPaymentCurrency.shortName
});
isValid = false;
}
Expand Down
Loading

0 comments on commit 6c08e2b

Please sign in to comment.