Skip to content

Commit

Permalink
add params into abacus
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Aug 26, 2024
1 parent 8222dea commit e50f625
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ data class EnvironmentLinks(
val statusPage: String?,
val withdrawalGateLearnMore: String?,
val complianceSupportEmail: String?,
val equityTiersLearnMore: String?,
) {
companion object {
fun parse(
Expand All @@ -100,6 +101,7 @@ data class EnvironmentLinks(
val statusPage = parser.asString(data["statusPage"])
val withdrawalGateLearnMore = parser.asString(data["withdrawalGateLearnMore"])
val complianceSupportEmail = parser.asString(data["complianceSupportEmail"])
val equityTiersLearnMore = parser.asString(data["equityTiersLearnMore"])
return EnvironmentLinks(
tos,
privacy,
Expand All @@ -114,6 +116,7 @@ data class EnvironmentLinks(
statusPage,
withdrawalGateLearnMore,
complianceSupportEmail,
equityTiersLearnMore,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class TradeOrderInputValidator(
}
OrderType.Limit, OrderType.StopLimit, OrderType.TakeProfitLimit -> {
val errors = mutableListOf<ValidationError>()
validateIsolatedMarginMinSize(subaccount, trade)?.let {
validateIsolatedMarginMinSize(subaccount, trade, environment)?.let {
errors.add(it)
}
errors
Expand All @@ -81,7 +81,7 @@ internal class TradeOrderInputValidator(
trade,
restricted,
)
OrderType.Limit, OrderType.StopLimit, OrderType.TakeProfitLimit -> validateLimitOrder(subaccount, trade, restricted)
OrderType.Limit, OrderType.StopLimit, OrderType.TakeProfitLimit -> validateLimitOrder(subaccount, trade, restricted, environment)

else -> null
}
Expand Down Expand Up @@ -112,17 +112,18 @@ internal class TradeOrderInputValidator(
private fun validateLimitOrder(
subaccount: Map<String, Any>?,
trade: Map<String, Any>,
restricted: Boolean
restricted: Boolean,
environment: V4Environment?
): List<Any>? {
val errors = mutableListOf<Any>()
var error = isolatedMarginMinSize(subaccount, trade, restricted)
var error = isolatedMarginMinSize(subaccount, trade, restricted, environment)
if (error != null) {
errors.add(error)
}
return if (errors.size > 0) errors else null
}

private fun isolatedMarginMinSize(subaccount: Map<String, Any>?, trade: Map<String, Any>, restricted: Boolean): Map<String, Any>? {
private fun isolatedMarginMinSize(subaccount: Map<String, Any>?, trade: Map<String, Any>, restricted: Boolean, environment: V4Environment?): Map<String, Any>? {
val marginMode = parser.asString(trade.get("marginMode"))?.let {
MarginMode.invoke(it)
}
Expand All @@ -145,6 +146,7 @@ internal class TradeOrderInputValidator(
"format" to "price",
),
),
learnMoreLink = environment?.links?.equityTiersLearnMore,
)
} else {
return null
Expand All @@ -154,7 +156,7 @@ internal class TradeOrderInputValidator(
}
}

private fun validateIsolatedMarginMinSize(subaccount: InternalSubaccountState, trade: InternalTradeInputState): ValidationError? {
private fun validateIsolatedMarginMinSize(subaccount: InternalSubaccountState, trade: InternalTradeInputState, environment: V4Environment?): ValidationError? {
return when (trade.marginMode) {
MarginMode.Isolated -> {
val currentFreeCollateral = subaccount.calculated.get(CalculationPeriod.current)?.freeCollateral ?: return null
Expand All @@ -173,6 +175,7 @@ internal class TradeOrderInputValidator(
"format" to "price",
),
),
learnMoreLink = environment?.links?.equityTiersLearnMore,
)
}
return null
Expand Down Expand Up @@ -353,7 +356,8 @@ internal class TradeOrderInputValidator(
errorCode: String,
fields: List<String>? = null,
actionStringKey: String? = null,
textParams: Map<String, Any>? = null
textParams: Map<String, Any>? = null,
learnMoreLink: String? = null,
): Map<String, Any> {
return errorDeprecated(
type = errorLevel,
Expand All @@ -363,6 +367,12 @@ internal class TradeOrderInputValidator(
titleStringKey = "ERRORS.TRADE_BOX_TITLE.$errorCode",
textStringKey = "ERRORS.TRADE_BOX.$errorCode",
textParams = textParams,
link = learnMoreLink,
linkText = if (learnMoreLink != null) {
"APP.GENERAL.LEARN_MORE_ARROW"
} else {
null
},
)
}

Expand All @@ -371,7 +381,8 @@ internal class TradeOrderInputValidator(
errorCode: String,
fields: List<String>? = null,
actionStringKey: String? = null,
textParams: Map<String, Any>? = null
textParams: Map<String, Any>? = null,
learnMoreLink: String? = null,
): ValidationError {
return error(
type = errorLevel,
Expand All @@ -381,6 +392,12 @@ internal class TradeOrderInputValidator(
titleStringKey = "ERRORS.TRADE_BOX_TITLE.$errorCode",
textStringKey = "ERRORS.TRADE_BOX.$errorCode",
textParams = textParams,
link = learnMoreLink,
linkText = if (learnMoreLink != null) {
"APP.GENERAL.LEARN_MORE_ARROW"
} else {
null
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ open class V4TradeInputTests : V4BaseTests() {
"fields": [
"size.size"
],
"linkText": "APP.GENERAL.LEARN_MORE_ARROW",
"link": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
"resources": {
"title": {
"stringKey": "ERRORS.TRADE_BOX_TITLE.ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exchange.dydx.abacus.tests.payloads
import exchange.dydx.abacus.state.app.adaptors.AbUrl
import exchange.dydx.abacus.state.manager.EnvironmentEndpoints
import exchange.dydx.abacus.state.manager.EnvironmentFeatureFlags
import exchange.dydx.abacus.state.manager.EnvironmentLinks
import exchange.dydx.abacus.state.manager.TokenInfo
import exchange.dydx.abacus.state.manager.V4Environment
import exchange.dydx.abacus.state.manager.WalletConnect
Expand Down Expand Up @@ -69,7 +70,22 @@ class AbacusMockData {
nobleValidator = null,
geo = null,
),
null,
EnvironmentLinks(
tos = "https://dydx.exchange/v4-terms",
privacy = "https://dydx.exchange/privacy",
mintscan = "https://testnet.mintscan.io/dydx-testnet/txs/{tx_hash}",
mintscanBase = "https://testnet.mintscan.io/dydx-testnet",
documentation = "https://v4-teacher.vercel.app/",
community = "https://discord.com/invite/dydx",
feedback = "https://docs.google.com/forms/d/e/1FAIpQLSezLsWCKvAYDEb7L-2O4wOON1T56xxro9A2Azvl6IxXHP_15Q/viewform",
blogs = "https://www.dydx.foundation/blog",
help = "https://help.dydx.exchange/",
launchIncentive = "https://dydx.exchange/v4-launch-incentive",
statusPage = "https://status.v4testnet.dydx.exchange/",
withdrawalGateLearnMore = "https://help.dydx.exchange/en/articles/8981384-withdrawals-on-dydx-chain#h_23e97bc665",
complianceSupportEmail = "[email protected]",
equityTiersLearnMore = "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
),
WalletConnection(
WalletConnect(
WalletConnectClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class EnvironmentsMock {
"community":"https://discord.com/invite/dydx",
"feedback":"https://docs.google.com/forms/d/e/1FAIpQLSezLsWCKvAYDEb7L-2O4wOON1T56xxro9A2Azvl6IxXHP_15Q/viewform",
"launchIncentive":"https://dydx.exchange/v4-launch-incentive",
"complianceSupportEmail":"[email protected]"
"complianceSupportEmail":"[email protected]",
"equityTiersLearnMore":"https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits"
}
},
"wallets": {
Expand Down

0 comments on commit e50f625

Please sign in to comment.