From e13a8696cceacc949918c994f636be9e1a09f9ae Mon Sep 17 00:00:00 2001 From: Rui <102453770+ruixhuang@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:48:27 -0700 Subject: [PATCH] Fix issue of gas token not setting after validator is reconnected (#692) --- build.gradle.kts | 2 +- .../functional/vault/VaultAccount.kt | 10 +++++++++- .../functional/vault/VaultDepositWithdrawForm.kt | 13 ++++--------- .../state/v2/manager/AsyncAbacusStateManagerV2.kt | 1 + v4_abacus.podspec | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index eeff6415b..746474421 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,7 +52,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.12.9" +version = "1.12.10" repositories { google() diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt index 39214d757..fce08e605 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultAccount.kt @@ -24,7 +24,15 @@ data class VaultAccount( val vaultTransfers: IList?, val totalVaultTransfersCount: Int?, val vaultShareUnlocks: IList?, -) +) { + val shareValue: Double? + get() = + if (balanceShares != null && balanceUsdc != null && balanceShares > 0) { + balanceUsdc / balanceShares + } else { + null + } +} @JsExport @Serializable diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt index f0229a9f2..689bc8b24 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/functional/vault/VaultDepositWithdrawForm.kt @@ -216,12 +216,11 @@ object VaultDepositWithdrawFormValidator { vaultAccount: VaultAccount?, amount: Double ): Double { - if (vaultAccount?.balanceUsdc == null || vaultAccount.balanceUsdc == 0.0 || - vaultAccount.balanceShares == null || vaultAccount.balanceShares == 0.0 - ) { + val shareValue = vaultAccount?.shareValue ?: 0.0 + if (shareValue == 0.0) { return 0.0 } - return (amount / (vaultAccount.balanceUsdc / vaultAccount.balanceShares)).toLong().toDouble() + return (amount / shareValue).toLong().toDouble() } fun validateVaultForm( @@ -236,11 +235,7 @@ object VaultDepositWithdrawFormValidator { // Calculate post-operation values and slippage val amount = formData.amount ?: 0.0 - val shareValue = if (vaultAccount?.balanceUsdc != null && vaultAccount.balanceShares != null && vaultAccount.balanceShares > 0) { - vaultAccount.balanceUsdc / vaultAccount.balanceShares - } else { - null - } + val shareValue = vaultAccount?.shareValue val sharesToAttemptWithdraw = if (amount > 0 && shareValue != null && shareValue > 0) { // shares must be whole numbers floor(amount / shareValue) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt index a8b5123be..013ad4d5e 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/manager/AsyncAbacusStateManagerV2.kt @@ -452,6 +452,7 @@ class AsyncAbacusStateManagerV2( dataNotification = dataNotification, presentationProtocol = presentationProtocol, ) + adaptor?.gasToken = gasToken pushNotificationToken?.let { token -> adaptor?.registerPushNotification(token, pushNotificationLanguageCode) } diff --git a/v4_abacus.podspec b/v4_abacus.podspec index 9c6c71571..2cf16a374 100644 --- a/v4_abacus.podspec +++ b/v4_abacus.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'v4_abacus' - spec.version = '1.12.9' + spec.version = '1.12.10' spec.homepage = 'https://github.com/dydxprotocol/v4-abacus' spec.source = { :http=> ''} spec.authors = ''