Skip to content

Commit

Permalink
Merge branch 'master' of github.com:InjectiveLabs/injective-helix int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
bangjelkoski committed Jun 17, 2024
2 parents 6f85519 + 1f27773 commit 81097ba
Show file tree
Hide file tree
Showing 31 changed files with 771 additions and 406 deletions.
2 changes: 1 addition & 1 deletion app/client/utils/validation/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const tradeErrorMessages = {
triggerPriceEqualsMarkPrice: () =>
'The trigger price cannot be the same as the mark price',
priceTooFarFromLastTradePrice: () =>
'The execution price for this trade is far away from the last traded price',
'The execution price for this trade is far from the last traded price',
orderPriceHigh: () => 'Order price is too high',
orderPriceLow: () => 'Order price is too low',
maxLeverage: () => 'Please decrease leverage',
Expand Down
26 changes: 15 additions & 11 deletions app/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ export const getAddresses = async (): Promise<string[]> => {
}

if (GEO_IP_RESTRICTIONS_ENABLED) {
const [address] = addresses
const addressIsBlackListed =
blacklistedAddresses.find(
(blacklistedAddress) =>
blacklistedAddress.toLowerCase() === address.toLowerCase()
) !== undefined
const someAddressInWalletIsBlackListed = addresses.some(
(address) =>
blacklistedAddresses.find(
(blacklistedAddress) =>
blacklistedAddress.toLowerCase() === address.toLowerCase()
) !== undefined
)

if (addressIsBlackListed) {
throw new WalletException(new Error('This addresses is restricted.'), {
code: UnspecifiedErrorCode,
type: ErrorType.WalletError
})
if (someAddressInWalletIsBlackListed) {
throw new WalletException(
new Error('This wallet addresses are restricted.'),
{
code: UnspecifiedErrorCode,
type: ErrorType.WalletError
}
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export function hexToString(hex: string) {
str += char
}

return decodeURIComponent(str)
return str
}
50 changes: 25 additions & 25 deletions assets/worker/orderbookWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
sharedToBalanceInTokenInBase
} from '@shared/utils/formatter'
import {
OrderbookFormattedRecord,
OrderbookWorkerMessage,
WorkerMessageType,
OrderbookWorkerResult,
WorkerMessageResponseType,
WorkerMessageType
OrderbookWorkerMessage,
OrderbookFormattedRecord,
WorkerMessageResponseType
} from '@/types/worker'

function priceLevelsToMap({
Expand Down Expand Up @@ -62,22 +62,23 @@ function priceMapToAggregatedArray({
>()

priceMap.forEach((quantity, price) => {
const priceInBigNumber = new BigNumberInBase(price)
const aggregatedPrice = aggregatePrice({
price: new BigNumberInBase(price),
isBuy,
aggregation,
isBuy
price: priceInBigNumber
})

if (!aggregatedMap.has(aggregatedPrice)) {
aggregatedMap.set(aggregatedPrice, {
priceSum: [Number(price)],
priceSum: [priceInBigNumber.toNumber()],
totalQuantity: quantity
})
} else {
const { priceSum, totalQuantity } = aggregatedMap.get(aggregatedPrice)!

aggregatedMap.set(aggregatedPrice, {
priceSum: [...priceSum, Number(price)],
priceSum: [...priceSum, priceInBigNumber.toNumber()],
totalQuantity: new BigNumberInBase(totalQuantity)
.plus(quantity)
.toFixed()
Expand Down Expand Up @@ -150,8 +151,6 @@ function priceMapToAggregatedArray({
const buys = new Map<string, string>()
const sells = new Map<string, string>()

let isOrderbookFetched = false

let preFetchBuyRecords: { sequence: number; records: PriceLevel[] }[] = []
let preFetchSellRecords: { sequence: number; records: PriceLevel[] }[] = []

Expand Down Expand Up @@ -227,7 +226,8 @@ self.addEventListener(
break

case WorkerMessageType.Fetch:
isOrderbookFetched = true
buys.clear()
sells.clear()

priceLevelsToMap({
priceMap: buys,
Expand Down Expand Up @@ -259,7 +259,9 @@ self.addEventListener(
})
})

preFetchBuyRecords = []
preFetchBuyRecords = preFetchBuyRecords.filter(
(record) => record.sequence >= data.sequence
)
}

if (preFetchSellRecords.length) {
Expand All @@ -277,25 +279,23 @@ self.addEventListener(
})
})

preFetchSellRecords = []
preFetchSellRecords = preFetchSellRecords.filter(
(record) => record.sequence >= data.sequence
)
}

sendReplaceOrderbook()
break

case WorkerMessageType.Stream:
if (!isOrderbookFetched) {
preFetchBuyRecords.push({
records: data.orderbook.buys,
sequence: data.sequence
})
preFetchSellRecords.push({
records: data.orderbook.sells,
sequence: data.sequence
})

break
}
preFetchBuyRecords.push({
records: data.orderbook.buys,
sequence: data.sequence
})
preFetchSellRecords.push({
records: data.orderbook.sells,
sequence: data.sequence
})

priceLevelsToMap({
priceMap: buys,
Expand Down
4 changes: 2 additions & 2 deletions components/App/Checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defineProps({
</script>

<template>
<SharedBaseCheckbox v-bind="$attrs">
<SharedCheckbox v-bind="$attrs">
<template #checkbox="{ isChecked, isDisabled }">
<div class="grid place-items-center">
<div class="relative w-4 h-4">
Expand All @@ -27,5 +27,5 @@ defineProps({
<span class="text-xs select-none" :data-cy="dataCy">
<slot />
</span>
</SharedBaseCheckbox>
</SharedCheckbox>
</template>
2 changes: 1 addition & 1 deletion components/Common/SubaccountOptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const subaccountOptionsFiltered = computed(() =>
const includeBotsSubaccounts =
props.includeBotsSubaccounts || !isSgtSubaccountId(subaccountId)
const hasBalance = aggregatedPortfolioBalances.value[subaccountId].some(
const hasBalance = aggregatedPortfolioBalances.value[subaccountId]?.some(
(balance) =>
new BigNumberInBase(balance.accountTotalBalance).gte(
DUST_AMOUNT_THRESHOLD
Expand Down
145 changes: 132 additions & 13 deletions components/Modals/ClosedRWAMarket.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,88 @@
<script lang="ts" setup>
import { Modal, MainPage } from '@/types'
import { BigNumberInBase } from '@injectivelabs/utils'
import { UI_DEFAULT_MIN_DISPLAY_DECIMALS } from '@/app/utils/constants'
import {
Modal,
MarketKey,
UiDerivativeMarket,
DerivativeTradeTypes,
DerivativesTradeFormField
} from '@/types'
const modalStore = useModalStore()
const derivativeFormValues = useFormValues()
const derivativeMarket = inject(MarketKey) as Ref<UiDerivativeMarket>
const props = defineProps({
worstPrice: {
type: String,
required: true
}
})
const emit = defineEmits<{
'terms:agreed': []
}>()
function closeModal() {
modalStore.closeModal(Modal.ClosedRWAMarket)
}
const { marketMarkPrice } = useDerivativeLastPrice(
computed(() => derivativeMarket?.value)
)
function onModalClose() {
closeModal()
const executionPrice = computed(() => {
switch (derivativeFormValues.value[DerivativesTradeFormField.Type]) {
case DerivativeTradeTypes.Limit:
return (
derivativeFormValues.value[DerivativesTradeFormField.LimitPrice] || ''
)
case DerivativeTradeTypes.Market:
return props.worstPrice
case DerivativeTradeTypes.StopLimit:
return (
derivativeFormValues.value[DerivativesTradeFormField.LimitPrice] || ''
)
case DerivativeTradeTypes.StopMarket:
return (
derivativeFormValues.value[DerivativesTradeFormField.TriggerPrice] || ''
)
default:
return props.worstPrice
}
})
const { valueToString: executionPriceToString } = useSharedBigNumberFormatter(
computed(() => executionPrice.value),
{
decimalPlaces: UI_DEFAULT_MIN_DISPLAY_DECIMALS,
displayAbsoluteDecimalPlace: true
}
)
return navigateTo({ name: MainPage.Index })
const { valueToString: markPriceToString } = useSharedBigNumberFormatter(
computed(() => marketMarkPrice.value),
{
decimalPlaces: UI_DEFAULT_MIN_DISPLAY_DECIMALS,
displayAbsoluteDecimalPlace: true
}
)
const { valueToString: priceDeviationToString } = useSharedBigNumberFormatter(
computed(() => {
const numerator = new BigNumberInBase(executionPrice.value).minus(
marketMarkPrice.value
)
const denominator = marketMarkPrice.value
return Math.abs(numerator.div(denominator).toNumber()) * 100
}),
{
decimalPlaces: UI_DEFAULT_MIN_DISPLAY_DECIMALS,
displayAbsoluteDecimalPlace: true
}
)
function closeModal() {
modalStore.closeModal(Modal.ClosedRWAMarket)
}
function confirm() {
Expand All @@ -27,7 +95,7 @@ function confirm() {
<AppModal
:is-open="modalStore.modals[Modal.ClosedRWAMarket]"
is-sm
@modal:closed="onModalClose"
@modal:closed="closeModal"
>
<template #title>
<div class="text-orange-300 flex space-x-1 items-center justif-center">
Expand Down Expand Up @@ -55,12 +123,63 @@ function confirm() {
</NuxtLink>
</template>
</i18n-t>
</div>

<div class="mt-6 flex items-center justify-center gap-2">
<AppButton class="bg-blue-500 text-blue-900 w-full" @click="confirm">
{{ $t('trade.rwa.acknowledge') }}
</AppButton>
<div class="flex flex-col space-y-2">
<div class="flex">
<span class="flex-1 text-left">{{
$t('trade.previousMarkPrice')
}}</span>
<span class="flex-1 text-left">
{{ markPriceToString }}
{{ derivativeMarket.quoteToken.symbol }}
</span>
</div>
<div class="flex">
<span class="flex-1 text-left">
<span
v-if="
[
DerivativeTradeTypes.Limit,
DerivativeTradeTypes.StopLimit
].includes(
derivativeFormValues[DerivativesTradeFormField.Type]
)
"
>{{ $t('trade.limitPrice') }}
</span>
<span
v-else-if="
derivativeFormValues[DerivativesTradeFormField.Type] ===
DerivativeTradeTypes.Market
"
>{{ $t('trade.averagePrice') }}
</span>
<span
v-else-if="
derivativeFormValues[DerivativesTradeFormField.Type] ===
DerivativeTradeTypes.StopMarket
"
>{{ $t('trade.triggerPrice') }}
</span>
</span>
<span class="flex-1 text-left">
{{ executionPriceToString }}
{{ derivativeMarket.quoteToken.symbol }}
</span>
</div>
<div class="flex">
<span class="flex-1 text-left">{{
$t('trade.priceDeviation')
}}</span>
<span class="flex-1 text-left">{{ priceDeviationToString }}%</span>
</div>
</div>

<div class="mt-6 flex items-center justify-center gap-2">
<AppButton class="bg-blue-500 text-blue-900 w-full" @click="confirm">
{{ $t('trade.rwa.acknowledge') }}
</AppButton>
</div>
</div>
</div>
</AppModal>
Expand Down
Loading

0 comments on commit 81097ba

Please sign in to comment.