Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dust fix introduced bug when account isn't provided #711

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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