Skip to content

Commit

Permalink
Merge branch 'main' into feature/vault_3
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Sep 27, 2024
2 parents 18ab7b9 + 13bfa58 commit aeeb819
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ data class VaultFormSummaryData(
val marginUsage: Double?,
val freeCollateral: Double?,
val vaultBalance: Double?,
val withdrawableVaultBalance: Double?,
val estimatedSlippage: Double?,
val estimatedAmountReceived: Double?
)
Expand Down Expand Up @@ -230,6 +231,10 @@ object VaultDepositWithdrawFormValidator {
VaultFormAction.DEPOSIT -> (vaultAccount?.balanceUsdc ?: 0.0) + amount
VaultFormAction.WITHDRAW -> (vaultAccount?.balanceUsdc ?: 0.0) - amount
}
val postOpWithdrawableVaultBalance = when (formData.action) {
VaultFormAction.DEPOSIT -> (vaultAccount?.withdrawableUsdc ?: 0.0) + amount
VaultFormAction.WITHDRAW -> (vaultAccount?.withdrawableUsdc ?: 0.0) - amount
}

val (postOpFreeCollateral, postOpMarginUsage) = if (accountData?.freeCollateral != null && accountData.marginUsage != null) {
val equity = accountData.freeCollateral / (1 - accountData.marginUsage)
Expand Down Expand Up @@ -346,6 +351,7 @@ object VaultDepositWithdrawFormValidator {
marginUsage = postOpMarginUsage,
freeCollateral = postOpFreeCollateral,
vaultBalance = postOpVaultBalance,
withdrawableVaultBalance = postOpWithdrawableVaultBalance,
estimatedSlippage = slippagePercent,
estimatedAmountReceived = if (formData.action === VaultFormAction.WITHDRAW && withdrawnAmountIncludingSlippage != null) withdrawnAmountIncludingSlippage else null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class VaultFormTests {
marginUsage = 0.5263157894736843,
freeCollateral = 900.0,
vaultBalance = 600.0,
withdrawableVaultBalance = 600.0,
estimatedSlippage = 0.0,
estimatedAmountReceived = null,
),
Expand Down Expand Up @@ -111,6 +112,7 @@ class VaultFormTests {
marginUsage = 0.4766444232602478,
freeCollateral = 1098.0,
vaultBalance = 400.0,
withdrawableVaultBalance = 400.0,
estimatedSlippage = 0.020000000000000018,
estimatedAmountReceived = 98.0,
),
Expand Down Expand Up @@ -157,6 +159,7 @@ class VaultFormTests {
marginUsage = 0.4766444232602478,
freeCollateral = 1098.0,
vaultBalance = 400.0,
withdrawableVaultBalance = 400.0,
estimatedSlippage = 0.020000000000000018, // unfortunate precision issues with direct equality checks
estimatedAmountReceived = 98.0,
),
Expand Down Expand Up @@ -203,6 +206,7 @@ class VaultFormTests {
marginUsage = 0.4,
freeCollateral = 1500.0,
vaultBalance = -100.0,
withdrawableVaultBalance = -100.0,
estimatedSlippage = 0.16666666666666663,
estimatedAmountReceived = 500.0,
),
Expand Down

0 comments on commit aeeb819

Please sign in to comment.