Skip to content

Commit

Permalink
Add slippage params
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Sep 19, 2024
1 parent 0f61a04 commit 547e200
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package exchange.dydx.abacus.functional.vault

import exchange.dydx.abacus.output.input.ErrorFormat
import exchange.dydx.abacus.output.input.ErrorParam
import exchange.dydx.abacus.output.input.ErrorResources
import exchange.dydx.abacus.output.input.ErrorString
import exchange.dydx.abacus.output.input.ErrorType
import exchange.dydx.abacus.output.input.ValidationError
import exchange.dydx.abacus.protocols.asTypedObject
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.Parser
import exchange.dydx.abacus.utils.format
import kollections.toIList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
Expand Down Expand Up @@ -49,7 +52,8 @@ object VaultFormValidationErrors {
type: ErrorType,
fields: List<String>? = null,
titleKey: String? = null,
textKey: String? = null
textKey: String? = null,
textKeyParams: List<ErrorParam>? = null
): ValidationError {
return ValidationError(
code = code,
Expand All @@ -60,7 +64,13 @@ object VaultFormValidationErrors {
linkText = null,
resources = ErrorResources(
title = titleKey?.let { ErrorString(stringKey = it, params = null, localized = null) },
text = textKey?.let { ErrorString(stringKey = it, params = null, localized = null) },
text = textKey?.let {
ErrorString(
stringKey = it,
params = textKeyParams?.toIList(),
localized = null,
)
},
action = null,
),
)
Expand Down Expand Up @@ -111,10 +121,14 @@ object VaultFormValidationErrors {
textKey = "APP.VAULTS.WITHDRAW_TOO_HIGH",
)

fun slippageTooHigh() = createError(
fun slippageTooHigh(slippagePercent: Double) = createError(
code = "SLIPPAGE_TOO_HIGH",
type = ErrorType.warning,
textKey = "APP.VAULTS.SLIPPAGE_WARNING",
textKeyParams = listOf(
ErrorParam(key = "AMOUNT", value = slippagePercent.format(4), format = ErrorFormat.Percent),
ErrorParam(key = "LINK", value = "", format = null),
),
)

fun mustAckSlippage() = createError(
Expand Down Expand Up @@ -303,7 +317,7 @@ object VaultDepositWithdrawFormValidator {
)
}
if (needSlippageAck) {
errors.add(VaultFormValidationErrors.slippageTooHigh())
errors.add(VaultFormValidationErrors.slippageTooHigh(slippagePercent))
if (slippagePercent >= SLIPPAGE_PERCENT_ACK && !formData.acknowledgedSlippage && formData.inConfirmationStep) {
errors.add(VaultFormValidationErrors.mustAckSlippage())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class VaultFormTests {
assertEquals(
VaultFormValidationResult(
errors = iListOf(
VaultFormValidationErrors.slippageTooHigh(),
VaultFormValidationErrors.slippageTooHigh(0.02),
),
submissionData = VaultDepositWithdrawSubmissionData(
deposit = null,
Expand Down Expand Up @@ -146,7 +146,7 @@ class VaultFormTests {
VaultFormValidationResult(
errors = iListOf(
VaultFormValidationErrors.slippageResponseWrongShares(),
VaultFormValidationErrors.slippageTooHigh(),
VaultFormValidationErrors.slippageTooHigh(0.02),
),
submissionData = null,
summaryData = VaultFormSummaryData(
Expand Down Expand Up @@ -191,7 +191,7 @@ class VaultFormTests {
VaultFormValidationResult(
errors = iListOf(
VaultFormValidationErrors.withdrawTooHigh(),
VaultFormValidationErrors.slippageTooHigh(),
VaultFormValidationErrors.slippageTooHigh(0.166666),
VaultFormValidationErrors.mustAckSlippage(),
),
submissionData = null,
Expand Down

0 comments on commit 547e200

Please sign in to comment.