Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed May 24, 2024
1 parent 78ecf70 commit fa5c96d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
38 changes: 28 additions & 10 deletions src/commonMain/kotlin/exchange.dydx.abacus/output/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,7 @@ data class TradingRewards(
// item is newer than obj
val modified = item.mutable()
modified.safeSet("cumulativeAmount", cumulativeAmount)

val synced =
HistoricalTradingReward.create(null, parser, modified, period)
addHistoricalTradingRewards(result, synced!!, period, lastStart)
Expand All @@ -1819,24 +1820,33 @@ data class TradingRewards(

(comparison == ComparisonOrder.descending) -> {
// item is older than obj
addHistoricalTradingRewards(result, obj, period, lastStart)
result.add(obj)
val modified = mapOf(
"amount" to obj.amount,
"cumulativeAmount" to cumulativeAmount,
"startedAt" to obj.startedAt,
"endedAt" to obj.endedAt,
)

val synced = HistoricalTradingReward.create(obj, parser, modified, period)
addHistoricalTradingRewards(result, synced!!, period, lastStart)
result.add(synced)
objIndex++
lastStart = obj.startedAtInMilliseconds
cumulativeAmount = obj.cumulativeAmount - obj.amount
lastStart = synced.startedAtInMilliseconds
cumulativeAmount = cumulativeAmount - obj.amount
}

else -> {
val modified = item.mutable()
modified.safeSet("cumulativeAmount", obj.cumulativeAmount)
modified.safeSet("cumulativeAmount", cumulativeAmount)

val synced =
HistoricalTradingReward.create(obj, parser, modified, period)
addHistoricalTradingRewards(result, obj, period, lastStart)
result.add(synced!!)
objIndex++
dataIndex++
lastStart = obj.startedAtInMilliseconds
cumulativeAmount = obj.cumulativeAmount - obj.amount
lastStart = synced.startedAtInMilliseconds
cumulativeAmount = cumulativeAmount - obj.amount
}
}
} else {
Expand All @@ -1846,11 +1856,19 @@ data class TradingRewards(
if (objs != null) {
while (objIndex < objs.size) {
val obj = objs[objIndex]
addHistoricalTradingRewards(result, obj, period, lastStart)
result.add(obj)
val modified = mapOf(
"amount" to obj.amount,
"cumulativeAmount" to cumulativeAmount,
"startedAt" to obj.startedAt,
"endedAt" to obj.endedAt,
)

val synced = HistoricalTradingReward.create(obj, parser, modified, period)
addHistoricalTradingRewards(result, synced!!, period, lastStart)
result.add(synced)
objIndex++
lastStart = obj.startedAtInMilliseconds
cumulativeAmount = obj.cumulativeAmount - obj.amount
cumulativeAmount = cumulativeAmount - obj.amount
}
}
while (dataIndex < data.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ class TradingRewardsTests {

@Test
fun testHistoricalDailyTradingRewardsWithExisting() {
val total = 200.0
val tradingRewards = TradingRewards.create(
TradingRewards(
200.0,
total,
iListOf(
BlockReward(1.0, yesterday.toEpochMilliseconds().toDouble(), 1),
),
mapOf(
"DAILY" to iListOf(
HistoricalTradingReward(
2.0,
197.0,
total,
yesterday.toEpochMilliseconds().toDouble(),
today.toEpochMilliseconds().toDouble(),
),
Expand All @@ -106,7 +107,7 @@ class TradingRewardsTests {
),
parser,
mapOf(
"total" to 200.0,
"total" to total,
"historical" to mapOf(
"DAILY" to iListOf(
mapOf(
Expand All @@ -127,7 +128,7 @@ class TradingRewardsTests {
).toIMap(),
)

assertEquals(200.0, tradingRewards?.total)
assertEquals(total, tradingRewards?.total)

// DAILY
// day before yesterday -> yesterday, yesterday -> today, today -> tomorrow
Expand All @@ -137,7 +138,7 @@ class TradingRewardsTests {
iListOf(
HistoricalTradingReward(
3.0,
200.0,
total,
today.toEpochMilliseconds().toDouble(),
tomorrow.toEpochMilliseconds().toDouble(),
),
Expand Down

0 comments on commit fa5c96d

Please sign in to comment.