From 44486ce7a79a6dd519bd6ce9e11d1c6c3f093815 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 15 Oct 2024 16:17:52 -0400 Subject: [PATCH 1/3] fix bug with dust --- build.gradle.kts | 2 +- .../vault/VaultDepositWithdrawForm.kt | 20 +++++++-- .../functional/vault/VaultFormTests.kt | 43 +++++++++++++++++++ v4_abacus.podspec | 2 +- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b8405a825..2809f2342 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.25" +version = "1.12.26" 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 901465672..ae33b9dea 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt @@ -268,9 +268,23 @@ object VaultDepositWithdrawFormValidator { val errors = mutableListOf() var submissionData: VaultDepositWithdrawSubmissionData? = null - // Calculate post-operation values and slippage - val sharesToAttemptWithdraw = calculateSharesToWithdraw(vaultAccount, formData.amount ?: 0.0) - val amount = sharesToAttemptWithdraw * (vaultAccount?.shareValue ?: 0.0) + val sharesToAttemptWithdraw = if (formData.action == VaultFormAction.WITHDRAW && + vaultAccount != null && + (vaultAccount.shareValue ?: 0.0) > 0.0 && + formData.amount != null) { + calculateSharesToWithdraw(vaultAccount, formData.amount) + } else { + null + } + + val amount = when (formData.action) { + VaultFormAction.DEPOSIT -> formData.amount ?: 0.0 + VaultFormAction.WITHDRAW -> if (sharesToAttemptWithdraw != null) { + sharesToAttemptWithdraw * (vaultAccount?.shareValue ?: 0.0) + } else { + formData.amount ?: 0.0 + } + } val withdrawnAmountIncludingSlippage = slippageResponse?.expectedQuoteQuantums?.let { it / 1_000_000.0 } val postOpVaultBalance = when (formData.action) { 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 4577094e5..93ed1829e 100644 --- a/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt +++ b/src/commonTest/kotlin/exchange.dydx.abacus/functional/vault/VaultFormTests.kt @@ -360,6 +360,49 @@ class VaultFormTests { ) } + @Test + fun testDepositWithNoAccount() { + val result = VaultDepositWithdrawFormValidator.validateVaultForm( + formData = VaultFormData( + action = VaultFormAction.DEPOSIT, + amount = 100.0, + acknowledgedSlippage = true, + inConfirmationStep = true, + ), + accountData = VaultFormAccountData( + marginUsage = 0.5, + freeCollateral = 1000.0, + canViewAccount = true, + ), + // null vault account is expected on first deposit + vaultAccount = null, + slippageResponse = null, + ) + + assertEquals( + VaultFormValidationResult( + errors = listOf().toIList(), + submissionData = VaultDepositWithdrawSubmissionData( + deposit = VaultDepositData( + subaccountFrom = "0", + amount = 100.0, + ), + withdraw = null, + ), + summaryData = VaultFormSummaryData( + needSlippageAck = false, + marginUsage = 0.5263157894736843, + freeCollateral = 900.0, + vaultBalance = 100.0, + withdrawableVaultBalance = 100.0, + estimatedSlippage = 0.0, + estimatedAmountReceived = null, + ), + ), + result, + ) + } + @Test fun testLowWithdraw() { val result = VaultDepositWithdrawFormValidator.validateVaultForm( diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 1651704e4..693ef4202 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.25' + spec.version = '1.12.26' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = '' From 2f26d3677d14cee44302911a16cf7c83274479b2 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 15 Oct 2024 16:19:10 -0400 Subject: [PATCH 2/3] fix --- .../functional/vault/VaultDepositWithdrawForm.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ae33b9dea..a4defabe7 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt @@ -271,7 +271,8 @@ object VaultDepositWithdrawFormValidator { val sharesToAttemptWithdraw = if (formData.action == VaultFormAction.WITHDRAW && vaultAccount != null && (vaultAccount.shareValue ?: 0.0) > 0.0 && - formData.amount != null) { + formData.amount != null + ) { calculateSharesToWithdraw(vaultAccount, formData.amount) } else { null From 052ff3a9ebcee967246757556af73d949ff9031f Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 15 Oct 2024 18:00:16 -0400 Subject: [PATCH 3/3] Fix --- build.gradle.kts | 2 +- v4_abacus.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2809f2342..677a91213 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.26" +version = "1.12.27" repositories { google() diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 693ef4202..630ed5e73 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.26' + spec.version = '1.12.27' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''