diff --git a/build.gradle.kts b/build.gradle.kts index f33c22c1c..dba1fedaa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.20" +version = "1.12.21" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt index 06f7659a0..822510a9d 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt @@ -16,6 +16,7 @@ import indexer.models.chain.OnChainVaultDepositWithdrawSlippageResponse import kollections.toIList import kotlinx.serialization.Serializable import kotlin.js.JsExport +import kotlin.math.abs import kotlin.math.floor @JsExport @@ -349,10 +350,15 @@ object VaultDepositWithdrawFormValidator { if (postOpVaultBalance != null && postOpVaultBalance < 0) { errors.add(vaultFormValidationErrors.withdrawTooHigh()) } - if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD && - vaultAccount?.withdrawableUsdc != null && vaultAccount.withdrawableUsdc >= MIN_DEPOSIT_FE_THRESHOLD - ) { - errors.add(vaultFormValidationErrors.withdrawTooLow()) + if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD) { + // only allowed if withdrawing entire balance + if (!( + vaultAccount?.withdrawableUsdc != null && + abs(vaultAccount.withdrawableUsdc - amount) <= 0.01 + ) + ) { + errors.add(vaultFormValidationErrors.withdrawTooLow()) + } } if (postOpVaultBalance != null && postOpVaultBalance >= 0 && amount > 0 && vaultAccount?.withdrawableUsdc != null && amount > vaultAccount.withdrawableUsdc diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt index d5b34137d..25e481928 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt @@ -367,6 +367,51 @@ class VaultFormTests { ) } + @Test + fun testLowWithdrawNonFull() { + val result = VaultDepositWithdrawFormValidator.validateVaultForm( + formData = VaultFormData( + action = VaultFormAction.WITHDRAW, + amount = 6.0, + acknowledgedSlippage = false, + inConfirmationStep = false, + ), + accountData = VaultFormAccountData( + marginUsage = 0.5, + freeCollateral = 1000.0, + canViewAccount = true, + ), + vaultAccount = makeVaultAccount( + balanceUsdc = 1000.0, + withdrawableUsdc = 10.0, + balanceShares = 500.0, + ), + slippageResponse = OnChainVaultDepositWithdrawSlippageResponse( + sharesToWithdraw = OnChainNumShares(numShares = 3.0), + expectedQuoteQuantums = 6.0 * 1_000_000, + ), + ) + + assertEquals( + VaultFormValidationResult( + errors = iListOf( + VaultFormValidationErrors().withdrawTooLow(), + ), + submissionData = null, + summaryData = VaultFormSummaryData( + needSlippageAck = false, + marginUsage = 0.4985044865403788, + freeCollateral = 1006.0, + vaultBalance = 994.0, + withdrawableVaultBalance = 4.0, + estimatedSlippage = 0.0, + estimatedAmountReceived = 6.0, + ), + ), + result, + ) + } + @Test fun testValidHighSlippageWithdrawWithAck() { val result = VaultDepositWithdrawFormValidator.validateVaultForm( diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 2e17d52a8..2538916b5 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.12.20' + spec.version = '1.12.21' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''