Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG2-213 Use displayable asset ID for token name in validation messages #769

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.13.43"
version = "1.13.44"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exchange.dydx.abacus.validator

import abs
import exchange.dydx.abacus.calculator.CalculationPeriod
import exchange.dydx.abacus.output.Asset
import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.InputType
import exchange.dydx.abacus.output.input.OrderSide
Expand Down Expand Up @@ -56,20 +57,20 @@ internal class TriggerOrdersInputValidator(
val tickSize = market?.perpetualMarket?.configs?.tickSize ?: 0.01
val oraclePrice = market?.perpetualMarket?.oraclePrice ?: return null

validateTriggerOrders(triggerOrders, market)?.let {
validateTriggerOrders(triggerOrders, market, internalState.assets)?.let {
errors.addAll(it)
}

val takeProfitOrder = triggerOrders.takeProfitOrder
val stopLossOrder = triggerOrders.stopLossOrder

if (takeProfitOrder != null) {
validateTriggerOrder(takeProfitOrder, market, oraclePrice, tickSize, position)?.let {
validateTriggerOrder(takeProfitOrder, market, internalState.assets, oraclePrice, tickSize, position)?.let {
errors.addAll(it)
}
}
if (stopLossOrder != null) {
validateTriggerOrder(stopLossOrder, market, oraclePrice, tickSize, position)?.let {
validateTriggerOrder(stopLossOrder, market, internalState.assets, oraclePrice, tickSize, position)?.let {
errors.addAll(it)
}
}
Expand Down Expand Up @@ -149,11 +150,12 @@ internal class TriggerOrdersInputValidator(

private fun validateTriggerOrders(
triggerOrders: InternalTriggerOrdersInputState,
market: InternalMarketState?
market: InternalMarketState?,
assets: Map<String, Asset>?,
): List<ValidationError>? {
val errors = mutableListOf<ValidationError>()

validateSize(triggerOrders.size, market)?.let {
validateSize(triggerOrders.size, market, assets)?.let {
/*
ORDER_SIZE_BELOW_MIN_SIZE
*/
Expand All @@ -180,6 +182,7 @@ internal class TriggerOrdersInputValidator(
private fun validateTriggerOrder(
triggerOrder: InternalTriggerOrderState,
market: InternalMarketState?,
assets: Map<String, Asset>?,
oraclePrice: Double,
tickSize: Double,
position: InternalPerpetualPosition,
Expand All @@ -193,7 +196,7 @@ internal class TriggerOrdersInputValidator(
triggerErrors.addAll(it)
}

validateSize(triggerOrder.summary?.size, market)?.let {
validateSize(triggerOrder.summary?.size, market, assets)?.let {
/*
ORDER_SIZE_BELOW_MIN_SIZE
*/
Expand Down Expand Up @@ -813,8 +816,10 @@ internal class TriggerOrdersInputValidator(
private fun validateSize(
orderSize: Double?,
market: InternalMarketState?,
assets: Map<String, Asset>?,
): List<ValidationError>? {
val symbol = market?.perpetualMarket?.assetId ?: return null
val assetId = market?.perpetualMarket?.assetId ?: return null
val symbol = assets?.get(assetId)?.displayableAssetId ?: return null
val orderSize = orderSize ?: return null
val minOrderSize = market.perpetualMarket?.configs?.minOrderSize ?: return null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exchange.dydx.abacus.validator.trade

import abs
import exchange.dydx.abacus.output.Asset
import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.InputType
import exchange.dydx.abacus.output.input.OrderSide
Expand Down Expand Up @@ -60,6 +61,7 @@ internal class TradeInputDataValidator(
validateSize(
trade = internalState.input.trade,
market = market,
assets = internalState.assets,
)?.let {
errors.addAll(it)
}
Expand Down Expand Up @@ -128,11 +130,13 @@ internal class TradeInputDataValidator(
private fun validateSize(
trade: InternalTradeInputState,
market: InternalMarketState?,
assets: Map<String, Asset>?
): List<ValidationError>? {
/*
ORDER_SIZE_BELOW_MIN_SIZE
*/
val symbol = market?.perpetualMarket?.assetId ?: return null
val assetId = market?.perpetualMarket?.assetId ?: return null
val symbol = assets?.get(assetId)?.displayableAssetId ?: return null
val size = trade.size?.size ?: return null
val minOrderSize = market.perpetualMarket?.configs?.minOrderSize ?: return null
return if (size.abs() < minOrderSize) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exchange.dydx.abacus.validator.trade

import exchange.dydx.abacus.calculator.CalculationPeriod
import exchange.dydx.abacus.output.Asset
import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.InputType
import exchange.dydx.abacus.output.input.ValidationError
Expand Down Expand Up @@ -42,6 +43,7 @@ internal class TradePositionStateValidator(
validatePositionSize(
position = position,
market = internalState.marketsSummary.markets[trade.marketId],
assets = internalState.assets,
)?.let {
errors.add(it)
}
Expand Down Expand Up @@ -99,6 +101,7 @@ internal class TradePositionStateValidator(
private fun validatePositionSize(
position: InternalPerpetualPosition?,
market: InternalMarketState?,
assets: Map<String, Asset>?,
): ValidationError? {
/*
NEW_POSITION_SIZE_OVER_MAX
Expand All @@ -108,7 +111,8 @@ internal class TradePositionStateValidator(
if (maxSize == Numeric.double.ZERO) {
return null
}
val symbol = market?.perpetualMarket?.assetId ?: return null
val assetId = market?.perpetualMarket?.assetId ?: return null
val symbol = assets?.get(assetId)?.displayableAssetId ?: return null
return if (size > maxSize) {
error(
type = ErrorType.error,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exchange.dydx.abacus.validator.trade

import exchange.dydx.abacus.output.Asset
import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.InputType
import exchange.dydx.abacus.output.input.ValidationError
Expand Down Expand Up @@ -35,6 +36,7 @@ internal class TradeResctrictedValidator(
val closeOnlyError =
validateClosingOnly(
market = market,
assets = internalState.assets,
change = change,
restricted = restricted,
)
Expand Down Expand Up @@ -64,10 +66,12 @@ internal class TradeResctrictedValidator(

private fun validateClosingOnly(
market: InternalMarketState?,
assets: Map<String, Asset>?,
change: PositionChange,
restricted: Boolean,
): ValidationError? {
val marketId = market?.perpetualMarket?.assetId ?: ""
val assetId = market?.perpetualMarket?.assetId ?: return null
val marketId = assets?.get(assetId)?.displayableAssetId ?: return null
val canTrade = market?.perpetualMarket?.status?.canTrade ?: true
val canReduce = market?.perpetualMarket?.status?.canReduce ?: true

Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.13.43'
spec.version = '1.13.44'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down