Skip to content

Commit

Permalink
fix: dust fix introduced bug when account isn't provided (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Oct 15, 2024
1 parent 6d4dadf commit d7ec961
Show file tree
Hide file tree
Showing 4 changed files with 63 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.12.26"
version = "1.12.27"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,24 @@ object VaultDepositWithdrawFormValidator {
val errors = mutableListOf<ValidationError>()
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValidationError>().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(
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.12.25'
spec.version = '1.12.27'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit d7ec961

Please sign in to comment.