Skip to content

Commit

Permalink
Merge branch 'main' into tu/vault-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Sep 19, 2024
2 parents 547e200 + 5dd1ce8 commit 6e1b751
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import exchange.dydx.abacus.state.internalstate.InternalSubaccountState
import exchange.dydx.abacus.utils.IList
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.Parser
import indexer.codegen.IndexerMegavaultHistoricalPnlResponse
import indexer.codegen.IndexerMegavaultPositionResponse
import indexer.codegen.IndexerVaultHistoricalPnl
import indexer.codegen.IndexerVaultPosition
import indexer.codegen.IndexerVaultsHistoricalPnlResponse
import kollections.toIList
import kotlinx.datetime.Clock
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -74,24 +79,24 @@ object VaultCalculator {
private val assetPositionProcessor = AssetPositionProcessor(parser)
private val subaccountCalculator = SubaccountCalculatorV2(parser)

fun getVaultHistoricalPnlResponse(apiResponse: String): IndexerVaultHistoricalPnlResponse? {
return parser.asTypedObject<IndexerVaultHistoricalPnlResponse>(apiResponse)
fun getVaultHistoricalPnlResponse(apiResponse: String): IndexerMegavaultHistoricalPnlResponse? {
return parser.asTypedObject<IndexerMegavaultHistoricalPnlResponse>(apiResponse)
}

fun getSubvaultHistoricalPnlResponse(apiResponse: String): IndexerSubvaultHistoricalPnlResponse? {
return parser.asTypedObject<IndexerSubvaultHistoricalPnlResponse>(apiResponse)
fun getSubvaultHistoricalPnlResponse(apiResponse: String): IndexerVaultsHistoricalPnlResponse? {
return parser.asTypedObject<IndexerVaultsHistoricalPnlResponse>(apiResponse)
}

fun getVaultPositionsResponse(apiResponse: String): IndexerVaultPositionResponse? {
return parser.asTypedObject<IndexerVaultPositionResponse>(apiResponse)
fun getVaultPositionsResponse(apiResponse: String): IndexerMegavaultPositionResponse? {
return parser.asTypedObject<IndexerMegavaultPositionResponse>(apiResponse)
}

fun calculateVaultSummary(historical: IndexerVaultHistoricalPnlResponse?): VaultDetails? {
if (historical?.vaultOfVaultsPnl.isNullOrEmpty()) {
fun calculateVaultSummary(historical: IndexerMegavaultHistoricalPnlResponse?): VaultDetails? {
if (historical?.megavaultPnl.isNullOrEmpty()) {
return null
}

val vaultOfVaultsPnl = historical!!.vaultOfVaultsPnl!!.sortedByDescending { parser.asDouble(it.createdAt) }
val vaultOfVaultsPnl = historical!!.megavaultPnl!!.sortedByDescending { parser.asDouble(it.createdAt) }

val history = vaultOfVaultsPnl.mapNotNull { entry ->
parser.asDouble(entry.createdAt)?.let { createdAt ->
Expand Down Expand Up @@ -132,21 +137,21 @@ object VaultCalculator {
}

fun calculateVaultPositions(
positions: IndexerVaultPositionResponse?,
histories: IndexerSubvaultHistoricalPnlResponse?,
positions: IndexerMegavaultPositionResponse?,
histories: IndexerVaultsHistoricalPnlResponse?,
markets: IMap<String, PerpetualMarket>?
): VaultPositions? {
if (positions?.positions == null) {
return null
}

val historiesMap = histories?.vaultsPnl?.associateBy { it.marketId }
val historiesMap = histories?.vaultsPnl?.associateBy { it.ticker }

return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.market), markets?.get(it.market)) }.toIList())
return VaultPositions(positions = positions.positions.mapNotNull { calculateVaultPosition(it, historiesMap?.get(it.ticker), markets?.get(it.ticker)) }.toIList())
}

fun calculateVaultPosition(position: IndexerVaultPosition, history: IndexerVaultHistoricalPnl?, perpetualMarket: PerpetualMarket?): VaultPosition? {
if (position.market == null) {
if (position.ticker == null) {
return null
}
val perpetualPosition = perpetualPositionProcessor.process(null, position.perpetualPosition)
Expand All @@ -165,15 +170,15 @@ object VaultCalculator {
),

),
marketsSummary = InternalMarketSummaryState(markets = mutableMapOf(position.market to InternalMarketState(perpetualMarket = perpetualMarket))),
marketsSummary = InternalMarketSummaryState(markets = mutableMapOf(position.ticker to InternalMarketState(perpetualMarket = perpetualMarket))),
periods = setOf(CalculationPeriod.current),
price = null,
configs = null,
)
val calculated = subaccount?.calculated?.get(CalculationPeriod.current)
val perpCalculated = perpetualPosition?.calculated?.get(CalculationPeriod.current)
return VaultPosition(
marketId = position.market,
marketId = position.ticker,
marginUsdc = calculated?.equity,
currentLeverageMultiple = perpCalculated?.leverage,
currentPosition = CurrentPosition(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param language
* @param token
*/
@JsExport
@Serializable
data class AddressRegisterTokenBody(

val language: kotlin.String? = null,
val token: kotlin.String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param address
*/
@JsExport
@Serializable
data class IndexerAffiliateAddressResponse(

val address: kotlin.String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param referralCode
* @param isVolumeEligible
* @param isAffiliate
*/
@JsExport
@Serializable
data class IndexerAffiliateMetadataResponse(

val referralCode: kotlin.String? = null,
val isVolumeEligible: kotlin.Boolean? = null,
val isAffiliate: kotlin.Boolean? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param affiliateList
* @param total
* @param currentOffset
*/
@JsExport
@Serializable
data class IndexerAffiliateSnapshotResponse(

val affiliateList: kotlin.Array<IndexerAffiliateSnapshotResponseObject>? = null,
val total: kotlin.Double? = null,
val currentOffset: kotlin.Double? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param affiliateAddress
* @param affiliateReferralCode
* @param affiliateEarnings
* @param affiliateReferredTrades
* @param affiliateTotalReferredFees
* @param affiliateReferredUsers
* @param affiliateReferredNetProtocolEarnings
* @param affiliateReferredTotalVolume
*/
@JsExport
@Serializable
data class IndexerAffiliateSnapshotResponseObject(

val affiliateAddress: kotlin.String? = null,
val affiliateReferralCode: kotlin.String? = null,
val affiliateEarnings: kotlin.Double? = null,
val affiliateReferredTrades: kotlin.Double? = null,
val affiliateTotalReferredFees: kotlin.Double? = null,
val affiliateReferredUsers: kotlin.Double? = null,
val affiliateReferredNetProtocolEarnings: kotlin.Double? = null,
val affiliateReferredTotalVolume: kotlin.Double? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param totalVolume
*/
@JsExport
@Serializable
data class IndexerAffiliateTotalVolumeResponse(

val totalVolume: kotlin.Double? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import kotlin.js.JsExport
* @param price
* @param size
* @param fee
* @param affiliateRevShare
* @param createdAt
* @param createdAtHeight
* @param orderId
Expand All @@ -44,6 +45,7 @@ data class IndexerFillResponseObject(
val price: kotlin.String? = null,
val size: kotlin.String? = null,
val fee: kotlin.String? = null,
val affiliateRevShare: kotlin.String? = null,
val createdAt: IndexerIsoString? = null,
val createdAtHeight: kotlin.String? = null,
val orderId: kotlin.String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param megavaultPnl
*/
@JsExport
@Serializable
data class IndexerMegavaultHistoricalPnlResponse(

val megavaultPnl: kotlin.Array<IndexerPnlTicksResponseObject>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Indexer API
* No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
*
* OpenAPI spec version: v1.0.0
*
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
package indexer.codegen

import kotlinx.serialization.Serializable
import kotlin.js.JsExport

/**
*
* @param positions
*/
@JsExport
@Serializable
data class IndexerMegavaultPositionResponse(

val positions: kotlin.Array<IndexerVaultPosition>? = null
)
Loading

0 comments on commit 6e1b751

Please sign in to comment.