-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TransferPriceImpactValidator (#762)
- Loading branch information
Showing
4 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...commonMain/kotlin/exchange.dydx.abacus/validator/transfer/TransferPriceImpactValidator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package exchange.dydx.abacus.validator.transfer | ||
|
||
import exchange.dydx.abacus.output.input.ErrorType | ||
import exchange.dydx.abacus.output.input.TransferType | ||
import exchange.dydx.abacus.output.input.ValidationError | ||
import exchange.dydx.abacus.protocols.LocalizerProtocol | ||
import exchange.dydx.abacus.protocols.ParserProtocol | ||
import exchange.dydx.abacus.state.app.helper.Formatter | ||
import exchange.dydx.abacus.state.internalstate.InternalState | ||
import exchange.dydx.abacus.state.manager.BlockAndTime | ||
import exchange.dydx.abacus.state.manager.V4Environment | ||
import exchange.dydx.abacus.validator.BaseInputValidator | ||
import exchange.dydx.abacus.validator.TransferValidatorProtocol | ||
|
||
internal class TransferPriceImpactValidator( | ||
localizer: LocalizerProtocol?, | ||
formatter: Formatter?, | ||
parser: ParserProtocol, | ||
) : BaseInputValidator(localizer, formatter, parser), TransferValidatorProtocol { | ||
override fun validateTransfer( | ||
internalState: InternalState, | ||
currentBlockAndHeight: BlockAndTime?, | ||
restricted: Boolean, | ||
environment: V4Environment? | ||
): List<ValidationError>? { | ||
val transfer = internalState.input.transfer | ||
val type = transfer.type ?: return null | ||
val aggregatePriceImpact = transfer.summary?.aggregatePriceImpact ?: return null | ||
|
||
val maxPriceImpact = 0.02 // 2% | ||
|
||
when (type) { | ||
TransferType.deposit, TransferType.withdrawal -> { | ||
if (aggregatePriceImpact >= maxPriceImpact) { | ||
return listOf( | ||
error( | ||
type = ErrorType.error, | ||
errorCode = "PRICE_IMPACT_TOO_HIGH", | ||
fields = null, | ||
actionStringKey = null, | ||
titleStringKey = "APP.TRADE.PRICE_IMPACT", | ||
textStringKey = "ERRORS.ONBOARDING.PRICE_IMPACT_TOO_HIGH", | ||
), | ||
) | ||
} else { | ||
return null | ||
} | ||
} | ||
TransferType.transferOut -> return null | ||
} | ||
} | ||
|
||
override fun validateTransferDeprecated( | ||
wallet: Map<String, Any>?, | ||
subaccount: Map<String, Any>?, | ||
transfer: Map<String, Any>, | ||
configs: Map<String, Any>?, | ||
currentBlockAndHeight: BlockAndTime?, | ||
restricted: Boolean, | ||
environment: V4Environment? | ||
): List<Any>? { | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters