diff --git a/build.gradle.kts b/build.gradle.kts index c751a9c6c..a3bea85e6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.17" +version = "1.12.18" 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 c3f44d299..06f7659a0 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt @@ -131,6 +131,14 @@ internal class VaultFormValidationErrors( textKey = "APP.VAULTS.WITHDRAW_TOO_HIGH", ) + fun withdrawTooLow() = createError( + code = "WITHDRAW_TOO_LOW", + type = ErrorType.error, + fields = listOf("amount"), + titleKey = "APP.TRADE.MODIFY_SIZE_FIELD", + textKey = "APP.VAULTS.WITHDRAW_TOO_LOW", + ) + fun withdrawingLockedBalance() = createError( code = "WITHDRAWING_LOCKED_BALANCE", type = ErrorType.error, @@ -341,7 +349,14 @@ object VaultDepositWithdrawFormValidator { if (postOpVaultBalance != null && postOpVaultBalance < 0) { errors.add(vaultFormValidationErrors.withdrawTooHigh()) } - if (postOpVaultBalance != null && postOpVaultBalance >= 0 && amount > 0 && vaultAccount?.withdrawableUsdc != null && amount > vaultAccount.withdrawableUsdc) { + if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD && + vaultAccount?.withdrawableUsdc != null && vaultAccount.withdrawableUsdc >= MIN_DEPOSIT_FE_THRESHOLD + ) { + errors.add(vaultFormValidationErrors.withdrawTooLow()) + } + if (postOpVaultBalance != null && postOpVaultBalance >= 0 && amount > 0 && + vaultAccount?.withdrawableUsdc != null && amount > vaultAccount.withdrawableUsdc + ) { errors.add(vaultFormValidationErrors.withdrawingLockedBalance()) } if (sharesToAttemptWithdraw != null && slippageResponse != null && sharesToAttemptWithdraw != slippageResponse.sharesToWithdraw.numShares) { 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 b4eb876b3..d5b34137d 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt @@ -231,7 +231,7 @@ class VaultFormTests { } @Test - fun testLowWithdraw() { + fun testLowDeposit() { val result = VaultDepositWithdrawFormValidator.validateVaultForm( formData = VaultFormData( action = VaultFormAction.DEPOSIT, @@ -272,6 +272,101 @@ class VaultFormTests { ) } + @Test + fun testLowWithdraw() { + val result = VaultDepositWithdrawFormValidator.validateVaultForm( + formData = VaultFormData( + action = VaultFormAction.WITHDRAW, + amount = 10.0, + acknowledgedSlippage = false, + inConfirmationStep = false, + ), + accountData = VaultFormAccountData( + marginUsage = 0.5, + freeCollateral = 1000.0, + canViewAccount = true, + ), + vaultAccount = makeVaultAccount( + balanceUsdc = 1000.0, + withdrawableUsdc = 500.0, + balanceShares = 500.0, + ), + slippageResponse = OnChainVaultDepositWithdrawSlippageResponse( + sharesToWithdraw = OnChainNumShares(numShares = 5.0), + expectedQuoteQuantums = 10.0 * 1_000_000, + ), + ) + + assertEquals( + VaultFormValidationResult( + errors = iListOf( + VaultFormValidationErrors().withdrawTooLow(), + ), + submissionData = null, + summaryData = VaultFormSummaryData( + needSlippageAck = false, + marginUsage = 0.49751243781094523, + freeCollateral = 1010.0, + vaultBalance = 990.0, + withdrawableVaultBalance = 490.0, + estimatedSlippage = 0.0, + estimatedAmountReceived = 10.0, + ), + ), + result, + ) + } + + @Test + fun testLowWithdrawFull() { + val result = VaultDepositWithdrawFormValidator.validateVaultForm( + formData = VaultFormData( + action = VaultFormAction.WITHDRAW, + amount = 10.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 = 5.0), + expectedQuoteQuantums = 10.0 * 1_000_000, + ), + ) + + assertEquals( + VaultFormValidationResult( + errors = listOf().toIList(), + submissionData = VaultDepositWithdrawSubmissionData( + withdraw = VaultWithdrawData( + subaccountTo = "0", + shares = 5.0, + minAmount = 9.90, + ), + deposit = null, + ), + summaryData = VaultFormSummaryData( + needSlippageAck = false, + marginUsage = 0.49751243781094523, + freeCollateral = 1010.0, + vaultBalance = 990.0, + withdrawableVaultBalance = 0.0, + estimatedSlippage = 0.0, + estimatedAmountReceived = 10.0, + ), + ), + result, + ) + } + @Test fun testValidHighSlippageWithdrawWithAck() { val result = VaultDepositWithdrawFormValidator.validateVaultForm( diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 94ed7973e..a24cefdd2 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.17' + spec.version = '1.12.18' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''