diff --git a/package-lock.json b/package-lock.json index 3706287f0..120870317 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "@ledgerhq/hw-transport-webhid": "^6.29.0", "@ledgerhq/hw-transport-webusb": "^6.29.0", "@ledgerhq/logs": "^6.12.0", - "@nolus/nolusjs": "2.4.6", + "@nolus/nolusjs": "2.4.7", "@skip-go/client": "^0.5.1", "chart.js": "^4.4.1", "chartjs-adapter-date-fns": "^3.0.0", @@ -2775,9 +2775,9 @@ } }, "node_modules/@nolus/nolusjs": { - "version": "2.4.6", - "resolved": "https://registry.npmjs.org/@nolus/nolusjs/-/nolusjs-2.4.6.tgz", - "integrity": "sha512-DjFdEnoD2Z3JuwHcLb8mE7k7Iw30X+d+xb/KQFgKxl6gSg21RrnsU7yeck4S7NvAz82FuLQCGi6JCo0QNbtcHA==", + "version": "2.4.7", + "resolved": "https://registry.npmjs.org/@nolus/nolusjs/-/nolusjs-2.4.7.tgz", + "integrity": "sha512-L5XiESFVW7LI/LleqUURVnFeG6vSCUVWaVjTPtOqctuc51/Xadm/W3eASgD/UOp7N4YZcpQo0R0x3Rk7CoUZ9A==", "license": "Apache-2.0", "dependencies": { "@cosmjs/cosmwasm-stargate": "0.32.4", diff --git a/package.json b/package.json index f43773452..8b447c594 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@ledgerhq/hw-transport-webhid": "^6.29.0", "@ledgerhq/hw-transport-webusb": "^6.29.0", "@ledgerhq/logs": "^6.12.0", - "@nolus/nolusjs": "2.4.6", + "@nolus/nolusjs": "2.4.7", "@skip-go/client": "^0.5.1", "chart.js": "^4.4.1", "chartjs-adapter-date-fns": "^3.0.0", diff --git a/src/common/components/modals/market-close/MarketCloseFormComponent.vue b/src/common/components/modals/market-close/MarketCloseFormComponent.vue index 58fd03e69..702ca76d4 100644 --- a/src/common/components/modals/market-close/MarketCloseFormComponent.vue +++ b/src/common/components/modals/market-close/MarketCloseFormComponent.vue @@ -71,7 +71,7 @@ import { computed, type PropType } from "vue"; import { Coin, CoinPretty, Dec, Int } from "@keplr-wallet/unit"; import { CurrencyUtils } from "@nolus/nolusjs"; import { useOracleStore } from "@/common/stores/oracle"; -import { NATIVE_NETWORK, PERCENT, PERMILLE } from "@/config/global"; +import { NATIVE_NETWORK, PERCENT, PERMILLE, PositionTypes, ProtocolsConfig } from "@/config/global"; import { useApplicationStore } from "@/common/stores/application"; import { AssetUtils, LeaseUtils } from "@/common/utils"; import { CurrencyDemapping } from "@/config/currencies"; @@ -254,29 +254,45 @@ function getRepayment(p: number) { const amountToRepay = CurrencyUtils.convertMinimalDenomToDenom( amount.toString(), - currency.ibcData, currency.shortName, + currency.ibcData, currency.decimal_digits ).toDec(); const percent = new Dec(p).quo(new Dec(100)); let repaymentInStable = amountToRepay.mul(percent); - const selectedCurrency = props.modelValue.selectedCurrency; - const price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); const swap = hasSwapFee.value; if (swap) { repaymentInStable = repaymentInStable.add(repaymentInStable.mul(new Dec(props.modelValue.swapFee))); } - const repayment = repaymentInStable.quo(price); + switch (ProtocolsConfig[props.modelValue.protocol].type) { + case PositionTypes.short: { + let lpn = AssetUtils.getLpnByProtocol(props.modelValue.protocol); + const price = new Dec(oracle.prices[lpn!.ibcData as string].amount); + const selected_asset_price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); - return { - repayment, - repaymentInStable, - selectedCurrencyInfo: selectedCurrency - }; + const repayment = repaymentInStable.mul(price); + + return { + repayment: repayment.quo(selected_asset_price), + repaymentInStable: repayment, + selectedCurrencyInfo: selectedCurrency + }; + } + case PositionTypes.long: { + const price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); + const repayment = repaymentInStable.quo(price); + + return { + repayment, + repaymentInStable, + selectedCurrencyInfo: selectedCurrency + }; + } + } } function getLpnSymbol() { diff --git a/src/common/components/modals/repay/RepayFormComponent.vue b/src/common/components/modals/repay/RepayFormComponent.vue index f5195a977..05d52a3f8 100644 --- a/src/common/components/modals/repay/RepayFormComponent.vue +++ b/src/common/components/modals/repay/RepayFormComponent.vue @@ -62,7 +62,7 @@ import { computed, nextTick, type PropType } from "vue"; import { CoinPretty, Dec, Int } from "@keplr-wallet/unit"; import { CurrencyUtils } from "@nolus/nolusjs"; import { useOracleStore } from "@/common/stores/oracle"; -import { NATIVE_NETWORK, PERCENT, PERMILLE } from "@/config/global"; +import { NATIVE_NETWORK, PERCENT, PERMILLE, PositionTypes, ProtocolsConfig } from "@/config/global"; import { useApplicationStore } from "@/common/stores/application"; import { AssetUtils, LeaseUtils } from "@/common/utils"; import type { ExternalCurrency } from "@/common/types"; @@ -131,7 +131,6 @@ function setRepayment(p: number) { function getRepayment(p: number) { const amount = outStandingDebt(); - const ticker = CurrencyDemapping[props.modelValue.leaseInfo.principal_due.ticker!]?.ticker ?? props.modelValue.leaseInfo.principal_due.ticker; @@ -146,22 +145,38 @@ function getRepayment(p: number) { const percent = new Dec(p).quo(new Dec(100)); let repaymentInStable = amountToRepay.mul(percent); - const selectedCurrency = props.modelValue.selectedCurrency; - const price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); const swap = hasSwapFee.value; if (swap) { repaymentInStable = repaymentInStable.add(repaymentInStable.mul(new Dec(props.modelValue.swapFee))); } - const repayment = repaymentInStable.quo(price); - - return { - repayment, - repaymentInStable, - selectedCurrencyInfo: selectedCurrency - }; + switch (ProtocolsConfig[props.modelValue.protocol].type) { + case PositionTypes.short: { + let lpn = AssetUtils.getLpnByProtocol(props.modelValue.protocol); + const price = new Dec(oracle.prices[lpn!.ibcData as string].amount); + const selected_asset_price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); + + const repayment = repaymentInStable.mul(price); + + return { + repayment: repayment.quo(selected_asset_price), + repaymentInStable: repayment, + selectedCurrencyInfo: selectedCurrency + }; + } + case PositionTypes.long: { + const price = new Dec(oracle.prices[selectedCurrency!.ibcData as string].amount); + const repayment = repaymentInStable.quo(price); + + return { + repayment, + repaymentInStable, + selectedCurrencyInfo: selectedCurrency + }; + } + } } const hasSwapFee = computed(() => { diff --git a/src/common/components/modals/short/ShortFormComponent.vue b/src/common/components/modals/short/ShortFormComponent.vue index 013f2e280..236047c3d 100644 --- a/src/common/components/modals/short/ShortFormComponent.vue +++ b/src/common/components/modals/short/ShortFormComponent.vue @@ -8,7 +8,7 @@ { if (props.modelValue.dialogSelectedCurrency) { const [ticker, protocol] = props.modelValue.dialogSelectedCurrency.split("@"); - for (const balance of balances.value) { + for (const balance of totalBalances.value) { const [t, p] = balance.key.split("@"); if (p == protocol) { props.modelValue.selectedDownPaymentCurrency = balance; @@ -204,21 +202,35 @@ const setSwapFee = async () => { }; const totalBalances = computed(() => { - const assets = wallet.balances - .map((item) => { - const currency = { ...AssetUtils.getCurrencyByDenom(item.balance.denom), balance: item.balance }; - return currency; - }) - .filter((item) => { - let [_ticker, protocol] = item.key.split("@"); - - if (ProtocolsConfig[protocol].type != PositionTypes.short) { - return false; - } + let currencies: ExternalCurrency[] = []; + + const protocols = app.protocols; + + for (const protocol of protocols) { + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + const c = + app.lease?.[protocol].map((item) => { + const ticker = CurrencyDemapping[item]?.ticker ?? item; + const currency = app.currenciesData?.[`${ticker}@${protocol}`]; + let balance = wallet.balances.find((item) => item.balance.denom == currency?.ibcData); + const c = { ...currency, balance: balance?.balance }; + return c as ExternalCurrency; + }) ?? []; + currencies = [...currencies, ...c]; + } + } - return true; - }); - return assets; + for (const lpn of app.lpn ?? []) { + const [_, protocol] = lpn.key.split("@"); + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + let balance = wallet.balances.find((item) => item.balance.denom == lpn?.ibcData); + const c = { ...lpn, balance: balance?.balance }; + + currencies.push(c); + } + } + + return currencies; }); const downPaymentSwapFeeStable = computed(() => { @@ -245,60 +257,30 @@ function handleDownPaymentChange(value: string) { props.modelValue.downPayment = value; } -const balances = computed(() => { - return totalBalances.value.filter((item) => { - const [ticker, protocol] = item.key.split("@"); - let cticker = ticker; - - if (!ProtocolsConfig[protocol].lease) { - return false; - } - - if (IGNORE_DOWNPAYMENT_ASSETS.includes(ticker)) { - return false; - } - - const lpns = ((app.lpn ?? []) as ExternalCurrency[]).map((item) => item.key as string); - - if (CurrencyMapping[ticker as keyof typeof CurrencyMapping]) { - cticker = CurrencyMapping[ticker as keyof typeof CurrencyMapping]?.ticker; - } - return lpns.includes(item.key as string) || app.leasesCurrencies.includes(cticker); - }); -}); - const coinList = computed(() => { - return props.modelValue.currentBalance - .filter((item) => { - let [ticker, protocol] = item.key.split("@"); - - const [_currency, downPaymentProtocol] = props.modelValue.selectedDownPaymentCurrency.key.split("@"); - if (downPaymentProtocol != protocol) { - return false; - } - - if (CurrencyMapping[ticker as keyof typeof CurrencyMapping]) { - ticker = CurrencyMapping[ticker as keyof typeof CurrencyMapping]?.ticker; - } - - if (!app.lease?.[protocol].includes(ticker)) { - return false; - } + let currencies: ExternalCurrency[] = []; + + for (const protocol of app.protocols) { + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + const c = + app.lpn?.filter((item) => { + const [_, p] = item.key.split("@"); + if (p == protocol) { + return true; + } + return false; + }) ?? []; + currencies = [...currencies, ...c]; + } + } - if (IGNORE_LEASE_ASSETS.includes(ticker) || IGNORE_LEASE_ASSETS.includes(`${ticker}@${protocol}`)) { - return false; - } - return app.leasesCurrencies.includes(ticker); - }) - .map((item) => { - return { - key: item.key, - ticker: item.ticker, - label: item.shortName as string, - value: item.ibcData, - icon: item.icon as string - }; - }); + return currencies.map((item) => ({ + key: item.key, + ticker: item.ticker, + label: item.shortName as string, + value: item.ibcData, + icon: item.icon as string + })); }); const selectedIndex = computed(() => { diff --git a/src/common/components/modals/short/ShortMainComponent.vue b/src/common/components/modals/short/ShortMainComponent.vue index 81c08451c..95500730c 100644 --- a/src/common/components/modals/short/ShortMainComponent.vue +++ b/src/common/components/modals/short/ShortMainComponent.vue @@ -34,7 +34,7 @@ import { Dec, Int } from "@keplr-wallet/unit"; import { CONFIRM_STEP, type ExternalCurrency, type IObjectKeys } from "@/common/types"; import { TxType } from "@/common/types"; -import { AssetUtils, Logger, getMicroAmount, walletOperation } from "@/common/utils"; +import { Logger, getMicroAmount, walletOperation } from "@/common/utils"; import { useWalletStore } from "@/common/stores/wallet"; import { storeToRefs } from "pinia"; import { useI18n } from "vue-i18n"; @@ -44,7 +44,7 @@ import { useOracleStore } from "@/common/stores/oracle"; import { useApplicationStore } from "@/common/stores/application"; import { AppUtils } from "@/common/utils"; import { useAdminStore } from "@/common/stores/admin"; -import { CurrencyMapping } from "@/config/currencies"; +import { CurrencyDemapping, CurrencyMapping } from "@/config/currencies"; import { NATIVE_ASSET, @@ -56,8 +56,7 @@ import { PERMILLE, ErrorCodes, ProtocolsConfig, - PositionTypes, - IGNORE_LEASE_ASSETS + PositionTypes } from "@/config/global"; const onModalClose = inject("onModalClose", () => {}); @@ -69,57 +68,66 @@ const walletRef = storeToRefs(walletStore); const i18n = useI18n(); const balances = computed(() => { - const assets = walletStore.balances - .map((item) => { - const currency = { ...AssetUtils.getCurrencyByDenom(item.balance.denom), balance: item.balance }; - return currency; - }) - .filter((item) => { - let [_ticker, protocol] = item.key.split("@"); + let currencies: ExternalCurrency[] = []; + + for (const protocol of app.protocols) { + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + const c = + app.lease?.[protocol].map((item) => { + const ticker = CurrencyDemapping[item]?.ticker ?? item; + const currency = app.currenciesData?.[`${ticker}@${protocol}`]; + let balance = walletStore.balances.find((item) => item.balance.denom == currency?.ibcData); + const c = { ...currency, balance: balance?.balance }; + return c as ExternalCurrency; + }) ?? []; + currencies = [...currencies, ...c]; + } + } - if (ProtocolsConfig[protocol].type != PositionTypes.short) { - return false; - } + for (const lpn of app.lpn ?? []) { + const [_, protocol] = lpn.key.split("@"); + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + let balance = walletStore.balances.find((item) => item.balance.denom == lpn?.ibcData); + const c = { ...lpn, balance: balance?.balance }; - return true; - }); - return assets; + currencies.push(c); + } + } + + return currencies; }); const paymentBalances = computed(() => { - const lpns = (app.lpn ?? []).map((item) => item.key); - const b = balances.value.filter((item) => { - const [ticker, protocol] = item.key.split("@"); + const [_, protocol] = item.key.split("@"); if (!ProtocolsConfig[protocol].lease) { return false; } - return lpns.includes(ticker) || app.leasesCurrencies.includes(ticker); + return true; }); return b; }); const leaseBalances = computed(() => { - const c = balances.value - .filter((item) => { - let [ticker, protocol] = item.key.split("@"); - - if (CurrencyMapping[ticker as keyof typeof CurrencyMapping]) { - ticker = CurrencyMapping[ticker as keyof typeof CurrencyMapping]?.ticker; - } - - if (IGNORE_LEASE_ASSETS.includes(ticker) || IGNORE_LEASE_ASSETS.includes(`${ticker}@${protocol}`)) { - return false; - } + let currencies: ExternalCurrency[] = []; + + for (const protocol of app.protocols) { + if (ProtocolsConfig[protocol].type == PositionTypes.short) { + const c = + app.lpn?.filter((item) => { + const [_, p] = item.key.split("@"); + if (p == protocol) { + return true; + } + return false; + }) ?? []; + currencies = [...currencies, ...c]; + } + } - return app.leasesCurrencies.includes(ticker); - }) - .map((item) => { - return item; - }); - return c; + return currencies; }); const step = ref(CONFIRM_STEP.CONFIRM); @@ -207,10 +215,8 @@ async function calculate() { ); const currency = state.value.selectedDownPaymentCurrency; - const lease = state.value.selectedCurrency; let [downPaymentTicker, protocol] = currency.key.split("@"); - let [leaseTicker] = lease.key.split("@"); if ( CurrencyMapping[downPaymentTicker as keyof typeof CurrencyMapping] && @@ -219,10 +225,6 @@ async function calculate() { downPaymentTicker = CurrencyMapping[downPaymentTicker as keyof typeof CurrencyMapping]?.ticker; } - if (CurrencyMapping[leaseTicker as keyof typeof CurrencyMapping]) { - leaseTicker = CurrencyMapping[leaseTicker as keyof typeof CurrencyMapping]?.ticker; - } - const cosmWasmClient = await NolusClient.getInstance().getCosmWasmClient(); const admin = useAdminStore(); @@ -232,7 +234,7 @@ async function calculate() { const makeLeaseApplyResp = await leaserClient.leaseQuote( microAmount.mAmount.amount.toString(), downPaymentTicker, - leaseTicker, + app.lease?.[protocol][0] as string, state.value.ltd ); @@ -417,17 +419,13 @@ async function openLease() { const cosmWasmClient = await NolusClient.getInstance().getCosmWasmClient(); const admin = useAdminStore(); - let [leaseTicker, protocol] = state.value.selectedCurrency.key.split("@"); + let [_, protocol] = state.value.selectedCurrency.key.split("@"); const leaserClient = new Leaser(cosmWasmClient, admin.contracts![protocol].leaser); - if (CurrencyMapping[leaseTicker as keyof typeof CurrencyMapping]) { - leaseTicker = CurrencyMapping[leaseTicker as keyof typeof CurrencyMapping]?.ticker; - } - const { txHash, txBytes, usedFee } = await leaserClient.simulateOpenLeaseTx( wallet, - leaseTicker, + app.lease?.[protocol][0] as string, state.value.ltd, funds ); diff --git a/src/common/stores/wallet/actions/updateBalances.ts b/src/common/stores/wallet/actions/updateBalances.ts index 16578623c..4a81b45b5 100644 --- a/src/common/stores/wallet/actions/updateBalances.ts +++ b/src/common/stores/wallet/actions/updateBalances.ts @@ -13,7 +13,6 @@ export async function updateBalances(this: Store) { const ibcBalances = []; const app = useApplicationStore(); const currencies = app.currenciesData; - console; for (const key in currencies) { const currency = app.currenciesData![key]; let shortName = currency.shortName; diff --git a/src/common/types/LeaseData.ts b/src/common/types/LeaseData.ts index 2e0a1f5b0..07fc9fc29 100644 --- a/src/common/types/LeaseData.ts +++ b/src/common/types/LeaseData.ts @@ -29,4 +29,5 @@ export interface LeaseAttributes { leasePositionStable: Dec; leasePositionTicker: string | null; timestamp: Date; + ls_asset_symbol: string; } diff --git a/src/common/utils/LeaseUtils.ts b/src/common/utils/LeaseUtils.ts index 444dcd2c0..f59505488 100644 --- a/src/common/utils/LeaseUtils.ts +++ b/src/common/utils/LeaseUtils.ts @@ -2,7 +2,7 @@ import type { OpenedLeaseInfo } from "@nolus/nolusjs/build/contracts"; import type { LeaseAttributes } from "../types/LeaseData"; import { Dec } from "@keplr-wallet/unit"; import { CurrencyUtils } from "@nolus/nolusjs"; -import { PERCENT, PERMILLE } from "@/config/global"; +import { PERCENT, PERMILLE, PositionTypes, ProtocolsConfig } from "@/config/global"; import { AppUtils, AssetUtils, EtlApi, Logger } from "."; import { CurrencyDemapping } from "@/config/currencies"; @@ -74,7 +74,17 @@ export class LeaseUtils { const downPaymentCurrency = AssetUtils.getCurrencyByTicker( CurrencyDemapping[downpaymentTicker]?.ticker ?? downpaymentTicker ); - const lpn = AssetUtils.getLpnByProtocol(AssetUtils.getProtocolByContract(result.lease.LS_loan_pool_id)); + + const contract = AssetUtils.getProtocolByContract(result.lease.LS_loan_pool_id); + const lpn = AssetUtils.getLpnByProtocol(contract); + let leasePositionTicker = result.lease.LS_asset_symbol; + + switch (ProtocolsConfig[contract].type) { + case PositionTypes.short: { + leasePositionTicker = lpn.ticker; + break; + } + } const leasePositionStable = new Dec(result.lease.LS_loan_amnt_asset, lpn.decimal_digits); const downPayment = new Dec(result.lease.LS_cltr_amnt_stable, Number(downPaymentCurrency!.decimal_digits)); @@ -86,10 +96,11 @@ export class LeaseUtils { downPaymentFee, downPayment, downpaymentTicker: result.lease.LS_cltr_symbol, - leasePositionTicker: result.lease.LS_asset_symbol, + leasePositionTicker, leasePositionStable: leasePositionStable, timestamp: new Date(result.lease.LS_timestamp), - price: new Dec(result.downpayment_price) + price: new Dec(result.downpayment_price), + ls_asset_symbol: result.lease.LS_asset_symbol }; } catch (error) { Logger.error(error); diff --git a/src/common/utils/SkipRoute.ts b/src/common/utils/SkipRoute.ts index 4fb4629ba..6be11286b 100644 --- a/src/common/utils/SkipRoute.ts +++ b/src/common/utils/SkipRoute.ts @@ -181,7 +181,6 @@ export class SkipRouter { } } } catch (error) { - console.log(error); throw error; } } diff --git a/src/config/global/contracts.ts b/src/config/global/contracts.ts index dfd1cee33..3f686e132 100644 --- a/src/config/global/contracts.ts +++ b/src/config/global/contracts.ts @@ -1,6 +1,7 @@ import type { ContractConfig } from "@/common/types"; import { ProtocolsRila, ProtocolsPirin } from "@nolus/nolusjs/build/types/Networks"; import { NATIVE_ASSET } from "./network"; +import { isDev } from "./modes"; export const CONTRACTS: ContractConfig = { testnet: { @@ -12,7 +13,7 @@ export const CONTRACTS: ContractConfig = { admin: { instance: "nolus17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgsmc5xhq", codeId: "", - ignoreProtocols: ["OSMOSIS-OSMOSIS-USDC_NOBLE", "OSMOSIS-OSMOSIS-USDC_AXELAR", "osmosis-axlusdc"] + ignoreProtocols: [] } }, mainnet: { @@ -45,9 +46,9 @@ export const ProtocolsConfig: { }; } = { "OSMOSIS-OSMOSIS-OSMO": { - only: ["NLS"], + only: [], lease: true, - currencies: ["NLS", "OSMO", "USDC_AXELAR", "ATOM", "AKT", "JUNO"], + currencies: [], ignoreNetowrk: ["NEUTRON"], type: PositionTypes.short, rewards: true @@ -61,9 +62,9 @@ export const ProtocolsConfig: { rewards: true }, "OSMOSIS-OSMOSIS-USDC_AXELAR": { - only: [], - currencies: ["USDC_AXELAR"], - lease: false, + only: ["NLS"], + currencies: ["NLS", "OSMO", "USDC_AXELAR", "ATOM", "AKT", "JUNO"], + lease: isDev() ? true : false, ignoreNetowrk: ["NEUTRON"], type: PositionTypes.long, rewards: false diff --git a/src/config/global/lease.ts b/src/config/global/lease.ts index d0c3914a0..2d04ba610 100644 --- a/src/config/global/lease.ts +++ b/src/config/global/lease.ts @@ -76,9 +76,7 @@ export const IGNORE_LEASE_ASSETS: string[] = [ "PICA", "STK_ATOM", "ATOM@NEUTRON-ASTROPORT-USDC_NOBLE", - "ST_TIA@NEUTRON-ASTROPORT-USDC_NOBLE", - "USDC", - "USDC_AXELAR" + "ST_TIA@NEUTRON-ASTROPORT-USDC_NOBLE" ]; export const IGNORE_DOWNPAYMENT_ASSETS: string[] = ["STK_ATOM"]; diff --git a/src/modules/lease/components/LeaseInfo.vue b/src/modules/lease/components/LeaseInfo.vue index 91d0cac90..f70ba73d7 100644 --- a/src/modules/lease/components/LeaseInfo.vue +++ b/src/modules/lease/components/LeaseInfo.vue @@ -17,6 +17,7 @@
{{ $t("message.chart") }}
+
{ CurrencyDemapping[props.leaseInfo.leaseData?.leasePositionTicker]?.ticker ?? props.leaseInfo.leaseData?.leasePositionTicker; - return oracleStore.prices[`${ticker}@${props.leaseInfo.protocol}`]?.amount ?? "0"; + const currency = app.currenciesData?.[`${ticker}@${props.leaseInfo.protocol}`]; + return oracleStore.prices[currency?.ibcData as string]?.amount ?? "0"; }); async function fetchChartData(intetval: string) { @@ -496,28 +489,32 @@ const asset = computed(() => { return item; } - const ticker = - props.leaseInfo.leaseStatus?.opened?.amount.ticker || - props.leaseInfo.leaseStatus?.paid?.amount.ticker || - props.leaseInfo.leaseStatus?.opening?.downpayment.ticker; - const item = AssetUtils.getCurrencyByTicker(ticker as string); + switch (ProtocolsConfig[props.leaseInfo.protocol].type) { + case PositionTypes.long: { + const ticker = + props.leaseInfo.leaseStatus?.opened?.amount.ticker || + props.leaseInfo.leaseStatus?.paid?.amount.ticker || + props.leaseInfo.leaseStatus?.opening?.downpayment.ticker; + const item = AssetUtils.getCurrencyByTicker(ticker as string); + + const asset = AssetUtils.getCurrencyByDenom(item?.ibcData as string); + return asset; + } + case PositionTypes.short: { + const item = AssetUtils.getCurrencyByTicker(props.leaseInfo.leaseData.leasePositionTicker as string); - const asset = AssetUtils.getCurrencyByDenom(item?.ibcData as string); - return asset; + const asset = AssetUtils.getCurrencyByDenom(item?.ibcData as string); + return asset; + } + } }); const getAssetIcon = computed((): string => { if (props.leaseInfo.leaseStatus?.opening && props.leaseInfo.leaseData) { - // const item = app.currenciesData?.[props.leaseInfo.leaseData?.leasePositionTicker as string]; return app.assetIcons?.[props.leaseInfo.leaseData?.leasePositionTicker as string] as string; } - const ticker = - props.leaseInfo.leaseStatus?.opened?.amount.ticker || - props.leaseInfo.leaseStatus?.opening?.downpayment.ticker || - props.leaseInfo.leaseStatus?.paid?.amount.ticker || - ""; - return app.assetIcons?.[`${ticker}@${props.leaseInfo.protocol}`] as string; + return app.assetIcons?.[`${props.leaseInfo.leaseData?.leasePositionTicker}@${props.leaseInfo.protocol}`] as string; }); const downPayment = computed(() => { @@ -527,11 +524,26 @@ const downPayment = computed(() => { }); const amount = computed(() => { - const data = - props.leaseInfo.leaseStatus?.opened?.amount || - props.leaseInfo.leaseStatus.opening?.downpayment || - props.leaseInfo.leaseStatus.paid?.amount; - return data?.amount ?? "0"; + switch (ProtocolsConfig[props.leaseInfo.protocol].type) { + case PositionTypes.long: { + const data = + props.leaseInfo.leaseStatus?.opened?.amount || + props.leaseInfo.leaseStatus.opening?.downpayment || + props.leaseInfo.leaseStatus.paid?.amount; + return data?.amount ?? "0"; + } + case PositionTypes.short: { + const data = + props.leaseInfo.leaseStatus?.opened?.amount || + props.leaseInfo.leaseStatus.opening?.downpayment || + props.leaseInfo.leaseStatus.paid?.amount; + + const asset = + app.currenciesData?.[`${props.leaseInfo.leaseData.leasePositionTicker}@${props.leaseInfo.protocol}`]; + const price = oracleStore.prices?.[asset?.ibcData as string]; + return new Dec(data.amount).quo(new Dec(price.amount)).toString(); + } + } }); const interestDue = computed(() => { @@ -924,14 +936,33 @@ function getTitleClass() { } const positionInStable = computed(() => { - const amount = - props.leaseInfo.leaseStatus?.opened?.amount || - props.leaseInfo.leaseStatus.opening?.downpayment || - props.leaseInfo.leaseStatus.paid?.amount; - const asset = app.currenciesData?.[`${props.leaseInfo.leaseData.leasePositionTicker}@${props.leaseInfo.protocol}`]; - const price = oracleStore.prices?.[`${props.leaseInfo.leaseData.leasePositionTicker}@${props.leaseInfo.protocol}`]; - const value = new Dec(amount.amount, asset?.decimal_digits).mul(new Dec(price.amount)); - return value.toString(asset?.decimal_digits); + switch (ProtocolsConfig[props.leaseInfo.protocol].type) { + case PositionTypes.long: { + const amount = + props.leaseInfo.leaseStatus?.opened?.amount || + props.leaseInfo.leaseStatus.opening?.downpayment || + props.leaseInfo.leaseStatus.paid?.amount; + const asset = + app.currenciesData?.[`${props.leaseInfo.leaseData.leasePositionTicker}@${props.leaseInfo.protocol}`]; + const price = + oracleStore.prices?.[`${props.leaseInfo.leaseData.leasePositionTicker}@${props.leaseInfo.protocol}`]; + const value = new Dec(amount.amount, asset?.decimal_digits).mul(new Dec(price.amount)); + return value.toString(asset?.decimal_digits); + } + case PositionTypes.short: { + const amount = + props.leaseInfo.leaseStatus?.opened?.amount || + props.leaseInfo.leaseStatus.opening?.downpayment || + props.leaseInfo.leaseStatus.paid?.amount; + + const ticker = + CurrencyDemapping[props.leaseInfo.leaseData.leasePositionTicker]?.ticker ?? + props.leaseInfo.leaseData.leasePositionTicker; + const asset = app.currenciesData?.[`${ticker}@${props.leaseInfo.protocol}`]; + const value = new Dec(amount.amount, asset?.decimal_digits); + return value.toString(asset?.decimal_digits); + } + } }); function onFocusChart(data: string[], index: number) {