Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mob 510 verify isolated position state #357

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.7.14"
version = "1.7.15"

repositories {
google()
Expand Down
4 changes: 2 additions & 2 deletions integration/iOS/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ EXTERNAL SOURCES:
:path: "../.."

SPEC CHECKSUMS:
abacus: a57d55b0ca0d3514389573a87c47507f88eb6b0a
abacus: 46f62be6dc9b3f888093eb2c9952d0267ab40670
CryptoSwift: 562f8eceb40e80796fffc668b0cad9313284cfa6

PODFILE CHECKSUM: b52035db7d56f0cfe37ecfb54b51338a99aca685

COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
1 change: 1 addition & 0 deletions integration/iOS/Pods/Local Podspecs/abacus.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions integration/iOS/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions integration/iOS/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class AccountCalculator(val parser: ParserProtocol, private val useParentSubacco

val childOpenPositions =
parser.asNativeMap(parser.value(subaccount, "openPositions"))
parentSubaccount = if (childOpenPositions != null) {
parentSubaccount = if (!childOpenPositions.isNullOrEmpty()) {
mergeChildOpenPositions(
parentSubaccount,
subaccountNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ internal class V4AccountProcessor(parser: ParserProtocol) : BaseProcessor(parser
info: SocketInfo,
height: BlockAndTime?,
): Map<String, Any>? {
val subaccountNumber = parser.asInt(parser.value(content, "subaccounts.subaccountNumber"))
val subaccountNumber = info.childSubaccountNumber ?: parser.asInt(parser.value(content, "subaccounts.subaccountNumber"))
?: subaccountNumberFromInfo(info)

return if (subaccountNumber != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exchange.dydx.abacus.payload.v4

import exchange.dydx.abacus.responses.StateResponse
import exchange.dydx.abacus.state.app.adaptors.AbUrl
import exchange.dydx.abacus.tests.extensions.loadv4SubaccountsWithPositions
import exchange.dydx.abacus.tests.extensions.log
import exchange.dydx.abacus.utils.ServerTime
Expand Down Expand Up @@ -347,4 +348,203 @@ class V4ParentSubaccountTests : V4BaseTests(true) {
""".trimIndent(),
)
}

@Test
fun testWithRealData() {
loadMarketsConfigurations()
loadMarkets()
perp.parseOnChainEquityTiers(mock.v4OnChainMock.equity_tiers)
loadSubaccountsWithRealData()

testParentSubaccountSubscribedWithPendingPositions()
testParentSubaccountSubscribed()
testParentSubaccountChannelData()
}

internal fun loadSubaccountsWithRealData(): StateResponse {
return test({
perp.rest(
AbUrl.fromString("$testRestUrl/v4/addresses/dydxaddress"),
mock.parentSubaccountsChannel.rest_response,
0,
null,
)
}, null)
}

private fun testParentSubaccountSubscribedWithPendingPositions() {
test(
{
perp.socket(testWsUrl, mock.parentSubaccountsChannel.read_subscribed_with_pending, 0, null)
},
"""
{
"wallet": {
"account": {
"groupedSubaccounts": {
"0": {
"equity": {
"current": 1979.85
},
"freeCollateral": {
"current": 1711.96
},
"quoteBalance": {
"current": 1711.96
},
"openPositions": {
},
"pendingPositions": [
{
"assetId": "LDO",
"firstOrderId": "d1deed71-d743-5528-aff2-cf3daf8b6413",
"quoteBalance": {
"current": 267.89
},
"freeCollateral": {
"current": 267.89
},
"equity": {
"current": 267.89
}
}
]
}
}
}
}
}
""".trimIndent(),
)
}

private fun testParentSubaccountSubscribed() {
test(
{
perp.socket(testWsUrl, mock.parentSubaccountsChannel.real_subscribed, 0, null)
},
"""
{
"wallet": {
"account": {
"groupedSubaccounts": {
"0": {
"equity": {
"current": 1997.66
},
"freeCollateral": {
"current": 1711.96
},
"quoteBalance": {
"current": 1711.96
},
"openPositions": {
"LDO-USD": {
"id": "LDO-USD",
"status": "OPEN",
"size": {
"current": 11.0
},
"assetId": "LDO",
"valueTotal": {
"current": 17.81
},
"notionalTotal": {
"current": 17.81
},
"leverage": {
"current": 0.06
},
"buyingPower": {
"current": 1410.69
},
"childSubaccountNumber": 128,
"quoteBalance": {
"current": 267.89
},
"freeCollateral": {
"current": 282.14
},
"marginUsage": {
"current": 0.012
},
"equity": {
"current": 285.70
}
}
},
"pendingPositions": null
}
}
}
}
}
""".trimIndent(),
)
}

private fun testParentSubaccountChannelData() {
test(
{
perp.socket(testWsUrl, mock.parentSubaccountsChannel.real_channel_batch_data, 0, null)
},
"""
{
"wallet": {
"account": {
"groupedSubaccounts": {
"0": {
"equity": {
"current": 2107.37
},
"freeCollateral": {
"current": 1711.96
},
"quoteBalance": {
"current": 1711.96
},
"openPositions": {
"LDO-USD": {
"id": "LDO-USD",
"status": "OPEN",
"size": {
"current": 17.0
},
"assetId": "LDO",
"valueTotal": {
"current": 27.52
},
"notionalTotal": {
"current": 27.52
},
"leverage": {
"current": 0.07
},
"buyingPower": {
"current": 1949.55
},
"childSubaccountNumber": 128,
"quoteBalance": {
"current": 367.89
},
"freeCollateral": {
"current": 389.91
},
"marginUsage": {
"current": 0.014
},
"equity": {
"current": 395.41
}
}
},
"pendingPositions": null
}
}
}
}
}
""".trimIndent(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ internal class MarketsChannelMock {
"channel": "v3_markets",
"contents": {
"markets": {
"LDO-USD":{
"clobPairId":"26",
"ticker":"LDO-USD",
"status":"ACTIVE",
"oraclePrice":"1.619032989",
"priceChange24H":"-0.049527727",
"volume24H":"1181661.046",
"trades24H":2992,
"nextFundingRate":"0",
"initialMarginFraction":"0.2",
"maintenanceMarginFraction":"0.1",
"openInterest":"83181",
"atomicResolution":-6,
"quantumConversionExponent":-9,
"tickSize":"0.001",
"stepSize":"1",
"stepBaseQuantums":1000000,
"subticksPerTick":1000000
},
"BTC-USD": {
"clobPairId":"0",
"ticker":"BTC-USD",
Expand Down
Loading
Loading