Skip to content

Commit

Permalink
fix: ack vault terms (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Oct 16, 2024
1 parent e52720c commit 3e73b6f
Show file tree
Hide file tree
Showing 6 changed files with 41 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.30"
version = "1.12.31"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data class VaultFormData(
val action: VaultFormAction,
val amount: Double?,
val acknowledgedSlippage: Boolean,
val acknowledgedTerms: Boolean,
val inConfirmationStep: Boolean,
)

Expand Down Expand Up @@ -164,6 +165,13 @@ internal class VaultFormValidationErrors(
titleKey = "APP.VAULTS.ACKNOWLEDGE_HIGH_SLIPPAGE",
)

fun mustAckTerms() = createError(
code = "MUST_ACK_TERMS",
type = ErrorType.error,
fields = listOf("acknowledgeTerms"),
titleKey = "APP.VAULTS.ACKNOWLEDGE_MEGAVAULT_TERMS",
)

fun vaultAccountMissing() = createError(
code = "VAULT_ACCOUNT_MISSING",
type = ErrorType.error,
Expand Down Expand Up @@ -206,6 +214,7 @@ data class VaultWithdrawData(
@Serializable
data class VaultFormSummaryData(
val needSlippageAck: Boolean?,
val needTermsAck: Boolean?,
val marginUsage: Double?,
val freeCollateral: Double?,
val vaultBalance: Double?,
Expand Down Expand Up @@ -328,6 +337,7 @@ object VaultDepositWithdrawFormValidator {
0.0
}
val needSlippageAck = slippagePercent >= SLIPPAGE_PERCENT_ACK && formData.inConfirmationStep
val needTermsAck = formData.action == VaultFormAction.DEPOSIT && formData.inConfirmationStep

// Perform validation checks and populate errors list
if (accountData == null) {
Expand All @@ -354,6 +364,10 @@ object VaultDepositWithdrawFormValidator {
}
}

if (needTermsAck && !formData.acknowledgedTerms) {
errors.add(vaultFormValidationErrors.mustAckTerms())
}

when (formData.action) {
VaultFormAction.DEPOSIT -> {
if (postOpFreeCollateral != null && postOpFreeCollateral < 0) {
Expand Down Expand Up @@ -424,6 +438,7 @@ object VaultDepositWithdrawFormValidator {
// Prepare summary data
val summaryData = VaultFormSummaryData(
needSlippageAck = needSlippageAck,
needTermsAck = needTermsAck,
marginUsage = postOpMarginUsage,
freeCollateral = postOpFreeCollateral,
vaultBalance = postOpVaultBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ data class EnvironmentLinks(
val blogs: String?,
val help: String?,
val vaultLearnMore: String?,
val vaultTos: String?,
val launchIncentive: String?,
val statusPage: String?,
val withdrawalGateLearnMore: String?,
Expand All @@ -102,6 +103,7 @@ data class EnvironmentLinks(
val statusPage = parser.asString(data["statusPage"])
val withdrawalGateLearnMore = parser.asString(data["withdrawalGateLearnMore"])
val equityTiersLearnMore = parser.asString(data["equityTiersLearnMore"])
val vaultTos = parser.asString(data["vaultTos"])
return EnvironmentLinks(
tos,
privacy,
Expand All @@ -113,6 +115,7 @@ data class EnvironmentLinks(
blogs,
help,
vaultLearnMore,
vaultTos,
launchIncentive,
statusPage,
withdrawalGateLearnMore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class VaultFormTests {
action = VaultFormAction.DEPOSIT,
amount = 100.0,
acknowledgedSlippage = true,
acknowledgedTerms = true,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -160,6 +161,7 @@ class VaultFormTests {
),
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = true,
marginUsage = 0.5263157894736843,
freeCollateral = 900.0,
vaultBalance = 600.0,
Expand All @@ -179,6 +181,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 100.0,
acknowledgedSlippage = true,
acknowledgedTerms = false,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -212,6 +215,7 @@ class VaultFormTests {
),
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.4766444232602478,
freeCollateral = 1098.0,
vaultBalance = 400.0,
Expand All @@ -232,6 +236,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 100.0,
acknowledgedSlippage = true,
acknowledgedTerms = false,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -259,6 +264,7 @@ class VaultFormTests {
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.4766444232602478,
freeCollateral = 1098.0,
vaultBalance = 400.0,
Expand All @@ -278,6 +284,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 600.0,
acknowledgedSlippage = false,
acknowledgedTerms = false,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -306,6 +313,7 @@ class VaultFormTests {
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = true,
needTermsAck = false,
marginUsage = 0.4,
freeCollateral = 1500.0,
vaultBalance = -100.0,
Expand All @@ -325,6 +333,7 @@ class VaultFormTests {
action = VaultFormAction.DEPOSIT,
amount = 10.0,
acknowledgedSlippage = false,
acknowledgedTerms = false,
inConfirmationStep = false,
),
accountData = VaultFormAccountData(
Expand All @@ -348,6 +357,7 @@ class VaultFormTests {
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.5025125628140703,
freeCollateral = 990.0,
vaultBalance = 1010.0,
Expand All @@ -367,6 +377,7 @@ class VaultFormTests {
action = VaultFormAction.DEPOSIT,
amount = 100.0,
acknowledgedSlippage = true,
acknowledgedTerms = true,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand All @@ -391,6 +402,7 @@ class VaultFormTests {
),
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = true,
marginUsage = 0.5263157894736843,
freeCollateral = 900.0,
vaultBalance = 100.0,
Expand All @@ -410,6 +422,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 10.0,
acknowledgedSlippage = false,
acknowledgedTerms = false,
inConfirmationStep = false,
),
accountData = VaultFormAccountData(
Expand All @@ -436,6 +449,7 @@ class VaultFormTests {
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.49751243781094523,
freeCollateral = 1010.0,
vaultBalance = 990.0,
Expand All @@ -455,6 +469,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 10.0,
acknowledgedSlippage = false,
acknowledgedTerms = false,
inConfirmationStep = false,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -486,6 +501,7 @@ class VaultFormTests {
),
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.49751243781094523,
freeCollateral = 1010.0,
vaultBalance = 990.0,
Expand All @@ -505,6 +521,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 6.0,
acknowledgedSlippage = false,
acknowledgedTerms = false,
inConfirmationStep = false,
),
accountData = VaultFormAccountData(
Expand All @@ -531,6 +548,7 @@ class VaultFormTests {
submissionData = null,
summaryData = VaultFormSummaryData(
needSlippageAck = false,
needTermsAck = false,
marginUsage = 0.4985044865403788,
freeCollateral = 1006.0,
vaultBalance = 994.0,
Expand All @@ -550,6 +568,7 @@ class VaultFormTests {
action = VaultFormAction.WITHDRAW,
amount = 500.0,
acknowledgedSlippage = true,
acknowledgedTerms = false,
inConfirmationStep = true,
),
accountData = VaultFormAccountData(
Expand Down Expand Up @@ -583,6 +602,7 @@ class VaultFormTests {
),
summaryData = VaultFormSummaryData(
needSlippageAck = true,
needTermsAck = false,
marginUsage = 0.41666666666666663,
freeCollateral = 1400.0,
vaultBalance = 0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class AbacusMockData {
blogs = "https://www.dydx.foundation/blog",
help = "https://help.dydx.exchange/",
vaultLearnMore = "https://help.dydx.exchange/",
vaultTos = "https://help.dydx.exchange/",
launchIncentive = "https://dydx.exchange/v4-launch-incentive",
statusPage = "https://status.v4testnet.dydx.exchange/",
withdrawalGateLearnMore = "https://help.dydx.exchange/en/articles/8981384-withdrawals-on-dydx-chain#h_23e97bc665",
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.30'
spec.version = '1.12.31'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 3e73b6f

Please sign in to comment.