Skip to content

Commit

Permalink
fix: min vault deposit amount (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Sep 30, 2024
1 parent f4fd3a2 commit 0fb3d15
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 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.6"
version = "1.12.7"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ object VaultFormValidationErrors {
textKey = "APP.VAULTS.DEPOSIT_TOO_HIGH",
)

fun depositTooLow() = createError(
code = "DEPOSIT_TOO_LOW",
type = ErrorType.error,
fields = listOf("amount"),
titleKey = "APP.TRADE.MODIFY_SIZE_FIELD",
textKey = "APP.VAULTS.DEPOSIT_TOO_LOW",
)

fun withdrawTooHigh() = createError(
code = "WITHDRAW_TOO_HIGH",
type = ErrorType.error,
Expand Down Expand Up @@ -198,6 +206,8 @@ object VaultDepositWithdrawFormValidator {
private const val SLIPPAGE_PERCENT_ACK = 0.04
private const val SLIPPAGE_TOLERANCE = 0.01

private const val MIN_DEPOSIT_FE_THRESHOLD = 20.0

fun getVaultDepositWithdrawSlippageResponse(apiResponse: String): OnChainVaultDepositWithdrawSlippageResponse? {
return parser.asTypedObject<OnChainVaultDepositWithdrawSlippageResponse>(apiResponse)
}
Expand Down Expand Up @@ -298,6 +308,9 @@ object VaultDepositWithdrawFormValidator {
if (postOpFreeCollateral != null && postOpFreeCollateral < 0) {
errors.add(VaultFormValidationErrors.depositTooHigh())
}
if (amount > 0 && amount < MIN_DEPOSIT_FE_THRESHOLD) {
errors.add(VaultFormValidationErrors.depositTooLow())
}
}
VaultFormAction.WITHDRAW -> {
if (postOpVaultBalance != null && postOpVaultBalance < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,46 @@ class VaultFormTests {
result,
)
}

@Test
fun testLowWithdraw() {
val result = VaultDepositWithdrawFormValidator.validateVaultForm(
formData = VaultFormData(
action = VaultFormAction.DEPOSIT,
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 = null,
)

assertEquals(
VaultFormValidationResult(
errors = iListOf(
VaultFormValidationErrors.depositTooLow(),
),
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = false,
marginUsage = 0.5025125628140703,
freeCollateral = 990.0,
vaultBalance = 1010.0,
withdrawableVaultBalance = 510.0,
estimatedSlippage = 0.0,
estimatedAmountReceived = null,
),
),
result,
)
}
}
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.6'
spec.version = '1.12.7'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 0fb3d15

Please sign in to comment.