Skip to content

Commit

Permalink
fix: add a little tolerance for floating point precision (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Oct 17, 2024
1 parent 0796110 commit 455ae5b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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.0"
version = "1.13.1"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ object VaultDepositWithdrawFormValidator {
private const val SLIPPAGE_PERCENT_WARN = 0.01
private const val SLIPPAGE_PERCENT_ACK = 0.04
private const val SLIPPAGE_TOLERANCE = 0.01
private const val EPSILON_FOR_ERRORS = 0.0001

private const val MIN_DEPOSIT_FE_THRESHOLD = 20.0

Expand Down Expand Up @@ -370,15 +371,15 @@ object VaultDepositWithdrawFormValidator {

when (formData.action) {
VaultFormAction.DEPOSIT -> {
if (postOpFreeCollateral != null && postOpFreeCollateral < 0) {
if (postOpFreeCollateral != null && postOpFreeCollateral < -EPSILON_FOR_ERRORS) {
errors.add(vaultFormValidationErrors.depositTooHigh())
}
if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD) {
errors.add(vaultFormValidationErrors.depositTooLow())
}
}
VaultFormAction.WITHDRAW -> {
if (postOpVaultBalance != null && postOpVaultBalance < 0) {
if (postOpVaultBalance < -EPSILON_FOR_ERRORS) {
errors.add(vaultFormValidationErrors.withdrawTooHigh())
}
if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD) {
Expand All @@ -391,7 +392,7 @@ object VaultDepositWithdrawFormValidator {
errors.add(vaultFormValidationErrors.withdrawTooLow())
}
}
if (postOpVaultBalance != null && postOpVaultBalance >= 0 && amount > 0 &&
if (postOpVaultBalance >= -EPSILON_FOR_ERRORS && amount > 0 &&
vaultAccount?.withdrawableUsdc != null && amount > vaultAccount.withdrawableUsdc
) {
errors.add(vaultFormValidationErrors.withdrawingLockedBalance())
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.0'
spec.version = '1.13.1'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 455ae5b

Please sign in to comment.