Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo committed Oct 16, 2024
2 parents a64fff2 + e52720c commit 8b081f0
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,17 @@ object VaultAccountCalculator {
}

fun calculateUserVaultInfo(
vaultInfo: OnChainAccountVaultResponse,
vaultInfo: OnChainAccountVaultResponse?,
vaultTransfers: IndexerTransferBetweenResponse,
): VaultAccount {
val presentValue = vaultInfo.equity?.let { it / 1_000_000 }
val presentValue = (vaultInfo?.equity ?: 0.0) / 1_000_000
val netTransfers = parser.asDouble(vaultTransfers.totalNetTransfers)
val withdrawable = vaultInfo.withdrawableEquity?.let { it / 1_000_000 }
val allTimeReturn =
if (presentValue != null && netTransfers != null) (presentValue - netTransfers) else null
val withdrawable = (vaultInfo?.withdrawableEquity ?: 0.0) / 1_000_000
val allTimeReturn = if (netTransfers != null) (presentValue - netTransfers) else null

val impliedShareValue: Double = if (
vaultInfo.shares?.numShares != null &&
vaultInfo.shares.numShares > 0 &&
presentValue != null
vaultInfo?.shares?.numShares != null &&
vaultInfo.shares.numShares > 0
) {
presentValue / vaultInfo.shares.numShares
} else {
Expand All @@ -92,8 +90,8 @@ object VaultAccountCalculator {

return VaultAccount(
balanceUsdc = presentValue,
balanceShares = vaultInfo.shares?.numShares,
lockedShares = vaultInfo.shareUnlocks?.sumOf { el -> el.shares?.numShares ?: 0.0 },
balanceShares = vaultInfo?.shares?.numShares ?: 0.0,
lockedShares = vaultInfo?.shareUnlocks?.sumOf { el -> el.shares?.numShares ?: 0.0 } ?: 0.0,
withdrawableUsdc = withdrawable,
allTimeReturnUsdc = allTimeReturn,
totalVaultTransfersCount = vaultTransfers.totalResults,
Expand All @@ -110,7 +108,7 @@ object VaultAccountCalculator {
transactionHash = el.transactionHash,
)
}?.toIList(),
vaultShareUnlocks = vaultInfo.shareUnlocks?.map { el ->
vaultShareUnlocks = vaultInfo?.shareUnlocks?.map { el ->
VaultShareUnlock(
unlockBlockHeight = el.unlockBlockHeight,
amountUsdc = el.shares?.numShares?.let { it * impliedShareValue },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ data object StatsigConfig {
var ff_enable_timestamp_nonce: Boolean = false
}

@JsExport
@Suppress("PropertyName")
data object AutoSweepConfig {
var disable_autosweep: Boolean = false
}

@JsExport
class AppSettings(
val ios: AppSetting?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import exchange.dydx.abacus.state.app.adaptors.V4TransactionErrors
import exchange.dydx.abacus.state.changes.Changes
import exchange.dydx.abacus.state.changes.StateChanges
import exchange.dydx.abacus.state.manager.ApiData
import exchange.dydx.abacus.state.manager.AutoSweepConfig
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.HistoricalTradingRewardsPeriod
import exchange.dydx.abacus.state.manager.HumanReadableCancelAllOrdersPayload
Expand Down Expand Up @@ -468,6 +469,9 @@ internal open class AccountSupervisor(
nobleBalancesTimer = null
return
}
if (AutoSweepConfig.disable_autosweep) {
return
}
val timer = helper.ioImplementations.timer ?: CoroutineTimer.instance
nobleBalancesTimer =
timer.schedule(0.0, nobleBalancePollingDuration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,58 @@ class VaultAccountTests {

assertEquals(expectedVaultAccount, vaultAccount)
}

@Test
fun calculateUserVaultInfo_empty() {
val vaultTransfers = IndexerTransferBetweenResponse(
totalResults = 2,
totalNetTransfers = "-500.0",
transfersSubset = arrayOf(
IndexerTransferResponseObject(
id = "1",
createdAt = Instant.fromEpochMilliseconds(1659465600000).toString(),
size = "6000.0",
type = IndexerTransferType.TRANSFER_OUT,
transactionHash = "tx1",
),
IndexerTransferResponseObject(
id = "2",
createdAt = Instant.fromEpochMilliseconds(1659552000000).toString(),
size = "6500.0",
type = IndexerTransferType.TRANSFER_IN,
transactionHash = "tx2",
),
),
)

val vaultAccount = calculateUserVaultInfo(null, vaultTransfers)

val expectedVaultAccount = VaultAccount(
balanceUsdc = 0.0,
withdrawableUsdc = 0.0,
allTimeReturnUsdc = 500.0,
totalVaultTransfersCount = 2,
balanceShares = 0.0,
lockedShares = 0.0,
vaultTransfers = iListOf(
VaultTransfer(
timestampMs = 1659465600000.0,
amountUsdc = 6000.0,
type = VaultTransferType.DEPOSIT,
id = "1",
transactionHash = "tx1",
),
VaultTransfer(
timestampMs = 1659552000000.0,
amountUsdc = 6500.0,
type = VaultTransferType.WITHDRAWAL,
id = "2",
transactionHash = "tx2",
),
),
vaultShareUnlocks = null,
)

assertEquals(expectedVaultAccount, vaultAccount)
}
}

0 comments on commit 8b081f0

Please sign in to comment.