Plan: TokenAmount type for Spark-token amounts (int128)#699
Closed
peterrojs wants to merge 1 commit into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
uint128end-to-end in the Spark protocol, but the Grid OpenAPI spec narrows every amount toformat: int64. The narrowing sits exactly at this repo's boundary — sparkcore stores/carriesuint128, and downstream (webdev/grid-apivendored client,observatory) faithfully consumes the int64.TokenAmountscalar (string-encoded uint128) and a matchingTokenCurrencyAmountobject; use them only on fields that carry Spark-token amounts. Fiat-only fields stayint64.Approach
Surgical, typed migration:
common/TokenAmount.yaml:type: string, pattern: '^[0-9]+$', documented decoder guidance (parse asbigint/int/BigInteger/Decimal; never as JSnumber).common/TokenCurrencyAmount.yaml: mirrorsCurrencyAmountbut withTokenAmount.DelegatedKeySpendingLimit.maxPerTransaction) switch directly toTokenAmount.InternalAccount.balance,Quote.*Amount,ExchangeRate.*Amount,Transaction.sent/received/fees,RateDetails.*Fee*,AgentTransferDetails.amount,TransferIn/OutRequest.amount) switch tooneOf: [CurrencyAmount, TokenCurrencyAmount]or scalaroneOf: [{int64}, TokenAmount].info.version2025-10-13→2026-07-17and a matchingservers.url— existing pinned clients keep the old int64 shape until they migrate.Alternatives considered and rejected (details in plan file): uniform string across every amount (too broad, breaks all fiat clients); sibling
fiatAmount/tokenAmountfields (bigger diff for no schema clarity gain); keep int64 +maximum(silent overflow already caused a real production incident — see the treasury snapshot memory).Peter confirmed on Slack that (a) the ongoing team int64→int128 audit does not cover this spec, and (b) the OpenAPI
CurrencyAmountis fair game (only the GraphQLCurrencyAmount { value: Long! }in sparkcore is off-limits).Changes: 22 items across
openapi/components/schemas/common/TokenAmount.yaml(new)common/TokenCurrencyAmount.yaml(new)customers/InternalAccount.yaml—balance,totalBalance→ oneOfquotes/Quote.yaml—totalSendingAmount,totalReceivingAmount,feesIncluded→ oneOfquotes/QuoteRequest.yaml—lockedCurrencyAmount→ oneOfexchange_rates/ExchangeRate.yaml— sending/min/max/receivingAmount → oneOfexchange_rates/ExchangeRateFees.yaml—fixed,total→ oneOftransactions/IncomingTransaction.yaml—receivedAmount,fees→ oneOftransactions/OutgoingTransaction.yaml—sentAmount,receivedAmount,fees→ oneOftransactions/IncomingRateDetails.yaml—gridApiFixedFee,gridApiVariableFeeAmount→ oneOf (+ fixes straytype: number, format: int64)transactions/OutgoingRateDetails.yaml—counterpartyFixedFee,gridApiFixedFee,gridApiVariableFeeAmount→ oneOf (+ same fix)cards/CardPullSummary.yaml,CardRefundSummary.yaml,CardSettlementSummary.yaml—totalAmount→ direct TokenAmount (USDB v1)cards/CardTransaction.yaml—authorizedAmount,settledAmount,refundedAmount→ oneOfauth/DelegatedKeySpendingLimit.yaml—maxPerTransaction→ direct TokenAmount (USDB v1)agents/AgentTransferDetails.yaml—amount→ oneOftransfers/TransferInRequest.yaml,TransferOutRequest.yaml—amount→ oneOfsandbox/SandboxFundRequest.yaml,SandboxSendRequest.yaml,SandboxUmaReceiveRequest.yaml— amount fields → oneOfconfig/PlatformCurrencyConfig.yaml,invitations/UmaInvitation*.yaml,receiver/CurrencyPreference.yaml— per-file audit during implementationopenapi/openapi.yaml+openapi.yamlbundle — register new schemas; bumpinfo.version+servers.url; regenerate bundle viamake buildmintlify/covering theTokenAmountencoding + JS-number pitfallFull plan (code sketches for every field, verification checklist, risks):
docs/plans/2026-07-17-token-amount-int128.mdin this PR's diff.Reply with a comment (e.g. LGTM) to approve — emoji reactions don't notify me here.
Requested by @peterrojs
Original PR: #698