-
Notifications
You must be signed in to change notification settings - Fork 114
Determine Amulet total supply by ACS snapshot when possible #2334
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
Changes from all commits
859ca1e
2685bc9
0efd90f
f31b19c
886a16a
79e319e
79d2574
edddf1f
c7c65d2
1b0dac9
767edf4
5ecd0cd
d4ab6f5
d426a88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,18 +4,25 @@ | |
| package org.lfdecentralizedtrust.splice.scan.admin.http | ||
|
|
||
| import cats.data.OptionT | ||
| import com.digitalasset.canton.data.CantonTimestamp | ||
| import com.digitalasset.canton.logging.{NamedLoggerFactory, NamedLogging} | ||
| import com.digitalasset.canton.time.Clock | ||
| import com.digitalasset.canton.tracing.{Spanning, TraceContext} | ||
| import org.lfdecentralizedtrust.splice.config.SpliceInstanceNamesConfig | ||
| import org.lfdecentralizedtrust.splice.environment.PackageVersionSupport | ||
| import org.lfdecentralizedtrust.splice.scan.admin.http.HttpTokenStandardMetadataHandler.TotalSupply | ||
| import org.lfdecentralizedtrust.tokenstandard.metadata.v1 | ||
| import org.lfdecentralizedtrust.splice.scan.store.ScanStore | ||
| import org.lfdecentralizedtrust.splice.scan.store.{AcsSnapshotStore, ScanStore} | ||
|
|
||
| import java.time.ZoneOffset | ||
| import java.time.{Instant, ZoneOffset} | ||
| import scala.concurrent.{ExecutionContext, Future} | ||
|
|
||
| class HttpTokenStandardMetadataHandler( | ||
| store: ScanStore, | ||
| acsSnapshotStore: AcsSnapshotStore, | ||
| spliceInstanceNames: SpliceInstanceNamesConfig, | ||
| packageVersionSupport: PackageVersionSupport, | ||
| clock: Clock, | ||
| protected val loggerFactory: NamedLoggerFactory, | ||
| )(implicit ec: ExecutionContext) | ||
| extends v1.Handler[TraceContext] | ||
|
|
@@ -60,12 +67,43 @@ class HttpTokenStandardMetadataHandler( | |
| } | ||
| } | ||
|
|
||
| private def lookupTotalSupply()(implicit ec: ExecutionContext, tc: TraceContext) = ( | ||
| private def lookupTotalSupplyByLatestRound()(implicit ec: ExecutionContext, tc: TraceContext) = | ||
| for { | ||
| (latestRoundNr, effectiveAt) <- OptionT(store.lookupRoundOfLatestData()) | ||
| totalSupply <- OptionT.liftF(store.getTotalAmuletBalance(latestRoundNr)) | ||
| } yield (totalSupply, effectiveAt) | ||
| ).value | ||
| } yield TotalSupply(amount = totalSupply, asOfTimestamp = effectiveAt) | ||
|
|
||
| private def lookupTotalSupplyByLatestAcsSnapshot()(implicit tc: TraceContext) = { | ||
| for { | ||
| latestSnapshot <- OptionT( | ||
| acsSnapshotStore.lookupSnapshotBefore( | ||
| acsSnapshotStore.currentMigrationId, | ||
| CantonTimestamp.now(), | ||
| ) | ||
| ) | ||
| unlocked <- OptionT.fromOption[Future](latestSnapshot.unlockedAmuletBalance) | ||
| locked <- OptionT.fromOption[Future](latestSnapshot.lockedAmuletBalance) | ||
| } yield TotalSupply( | ||
| amount = locked + unlocked, | ||
| asOfTimestamp = latestSnapshot.snapshotRecordTime.toInstant, | ||
| ) | ||
| } | ||
|
|
||
| private def lookupTotalSupply()(implicit tc: TraceContext) = { | ||
| for { | ||
| noHoldingFeesOnTransfers <- packageVersionSupport.noHoldingFeesOnTransfers( | ||
| store.key.dsoParty, | ||
| clock.now, | ||
| ) | ||
| deductHoldingFees = !noHoldingFeesOnTransfers.supported | ||
| result <- | ||
| if (deductHoldingFees) { | ||
| lookupTotalSupplyByLatestRound().value | ||
| } else { | ||
| lookupTotalSupplyByLatestAcsSnapshot().orElse(lookupTotalSupplyByLatestRound()).value | ||
| } | ||
| } yield result | ||
| } | ||
|
|
||
| private def getAmuletInstrument()(implicit ec: ExecutionContext, tc: TraceContext) = | ||
| for { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. called in the line just below this there aren't any tests... I'm also not sure there's much value in one since there already are for the endpoints that use the 2 options directly, but lmk
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, at least it can be checked in the sanity plugin: #2318 (review) |
||
|
|
@@ -75,8 +113,8 @@ class HttpTokenStandardMetadataHandler( | |
| name = spliceInstanceNames.amuletName, | ||
| symbol = spliceInstanceNames.amuletNameAcronym, | ||
| decimals = 10, | ||
| totalSupply = optSupply.map(_._1.toString()), | ||
| totalSupplyAsOf = optSupply.map(_._2.atOffset(ZoneOffset.UTC)), | ||
| totalSupply = optSupply.map(_.amount.toString()), | ||
| totalSupplyAsOf = optSupply.map(_.asOfTimestamp.atOffset(ZoneOffset.UTC)), | ||
| supportedApis = Map( | ||
| "splice-api-token-metadata-v1" -> 1, | ||
| "splice-api-token-holding-v1" -> 1, | ||
|
|
@@ -89,3 +127,7 @@ class HttpTokenStandardMetadataHandler( | |
| ) | ||
|
|
||
| } | ||
|
|
||
| object HttpTokenStandardMetadataHandler { | ||
| case class TotalSupply(amount: BigDecimal, asOfTimestamp: Instant) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.