-
Notifications
You must be signed in to change notification settings - Fork 503
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
SPIKE: Parsing Ledger Close Meta in Stellar Blockchain to Generate Token Transfer Events #5573
Comments
The For SAC events, note that the |
thinking further on potential for event portability over-the-wire and model evolutions over time, might be able to address those concerns with serialization pattern and defer the real transfer event schema to an IDL rather than manual code binding:
It would use a deser lib and its associated tooling, to define an IDL per transfer event schema and leverage code-gen from tooling for client-side code binding to the IDL in various languages. rather than manual code binding(struct per detail transfer type per language). FlatBuffers as a suggestion. Could store the transfer event IDL's in GH repo as the 'schema registry', clients in various langauges would refer to that for code-gen. |
That is a good idea. I will make the change
I agree that Type is very ambigous. But. I'd argue so is Basis. Perhaps a more descriptive name would be Re portablility and Use of IDL + schema registry: Protobufs are better than creating the Event as a payload of bytes and embedding the schema name in it, as you are suggesting. That being said, that is a bit too expansive for this ask. By ask, I mean the "new processors library" in general TL;dr - I think that might be overkill |
If each field has the appropriate |
Three reasons to have the
|
True, agreed that having the field makes filtering and rendering far simpler. Otherwise, like in the situations you outlined, while you could still infer direction ( |
Was going to suggest
The Protobuffers .protobuf files are the schema registry, those are external and need to exist somewhere, same as .fbs files for IDL source in FlatBuffers. Both tools are similar, they propose an IDL file and provide codegen tooling for deser purposes, either would be usable in this kind of proposal, Avro probably would be another option too.
not sure what is meant since that is what the codegen'd stubs from an IDL deser tooling provide, maybe you are inferring to how the app selects which generated code to use for deser of payloads. The token transfer processor will be implemented in go, what is the intended interface, i.e. is it a pure function with an input of LCM and an output of |
another variation that could happen in parallel and leverages the usage of IDL is to package the go token transformer implementation into an executable cli tool which can run as o/s process which just emits serialized |
Nice work Karthik! I'm taking a closer look at this and will add some more thoughts later, but on first jump, I noticed that the TokenTransferEvent does not have the operation/transaction that caused the token transfer, which is something we need for the state change indexer wallet backend will be building. Maybe add that as a field to TokenTransferDetails? |
The
Other than that, you dont need the operation or the operation result, since you will use the You really shouldnt be having to work with the operation itself when going through a processor
Thanks for bringing that up. The |
I understand that the Details field captures the cause and effect of an operation, but wallet backend would like the option of presenting to a client the operation as well as the resulting state change. Clients may want to inspect this operation for their own purposes/reasons. They may want more details than what is captured by the Details field. You could argue that the txhash may be sufficient for this, but we don't want to dig into the transaction and try to figure out the exact operation that caused the change It may also reduce the burden of having to model complex operations like path strict send. The actual change can only capture some key details of the token transfer and the rest of the details clients can get by deserializing the operation xdr string |
You mention a source account in your CreateClaimableBalanceDetails struct and yet I don't see it in the struct definition: type CreateClaimableBalanceDetails struct { Is there a reason for this? Also if it is a source account's balance that goes down, why list all the destinationAccounts here (whose balance only goes up when they claim this claimable balance), although I get that this information is available in the operation ? |
For ClaimClaimableBalanceDetails, how do we know the account that actually claimed the balance? type ClaimClaimableBalanceDetails struct { |
To answer your question about ClawbackClaimableBalanceDetails we'd like to model (at least for now) getting assigned as a claimant on the balance as a state change, so yes, we'd like this to be included as well |
Maybe we can use "pending_credit" or "pending_debit" for claimable balances, since they aren't crediting or debiting your balance until they're claimed. |
This particular
The TokenTransferEvent was caused in response to the operation
Same reasoning as above. This particular --
This is not true.
That comment was more of a footnote for me. A EDIT: I didnt remove it, but rather left a note detailing as to why this operation wont generate a |
Also, instead of a txHash, can you add the actual tx xdr string instead? I feel like that's a more useful field since it can be deserialized and the transaction examined if need be by anyone using this library. |
Question - would it be possible to track WHEN a TokenTransferEvent took place? In the indexer we are building for the wallet backend, we'd like to have this piece of information so users can get state changes for their accounts for a particular time slice |
Your design for CreateClaimableBalanceDetails and ClaimClaimableBalanceDetails makes sense, but now I'm curious - why have a source account for type CreateAccountDetails struct { type SimplePaymentDetails struct { and type AccountMergeDetails struct { Couldn't the above events be modeled the same way? For example, for SimplePaymentDetails, can't the entityId be the sourceAccount? |
WIP-------
This issue deals with capturing the task of creating a generic token transfer processor library/package that parses the LedgerCloseMeta to generate a list of TokenTransfer events that detail how balances have been updated for Ledger Entries of the type LedgerEntryTypeAccount or LedgerEntryTypeTrustline
The endgoal for this issue is to define and agree upon a data model for the
type TokenTransferEvent struct
Scope:
Not in Scope:
Basic TokenTransferEvent DataModel
It is intuitive to think of a token transfer as an event that impacts an entity's balance. The entity could be a trustline, an account, or a smart contract.
Transfers can be classified as either a Debit or a Credit, with the reason for the transfer varying widely—stemming from classic operations in Stellar, a transaction fee, or one of the [Transfer, Mint, Burn, Clawback] events generated by a smart contract.
The following represents the basic fields that are common to all TokenTransferEvent, no matter the cause
What causes an account's balance to change
This section highlights all the reasons that can cause an account/trustline/smart contract's balance to be updated, and what can be included in the
Details TokenTransferDetails
field for each reason.Broadly, reasons for account balance updates can be categorized as:
Transaction Fees
Paid for by the source of the transaction when submitted to Horizon or Soroban
Sample Details to be included:
Classic Operations
This will cause the source's balance to ⬇ and newly created account's balance to ⬆
This will cause the sourceAccount to stop existing (and thus cause it's balance to go ⬇ ), and the destination account's balance to go ⬆
Note: There is nothing here in details
This will cause the source account's balance to ⬇
This will cause the account's (that is claiming this CB) balance to go ⬆
Clawback Claimable Balance
NOTE - A
ClawbackClaimableBalance
operation does not cause any account or trustline's balance to go up or down. Meaning, there never will be aTokenTransferEvent
generated in response to aClawbackClaimableBalanceOperation
. I am simply adding this section for articulating the above point.LiquidityPool Deposit
LiquidityPool Withdraw
Manage Offer Buy
The kind of events to expect when a
ManageBuyOffer
operation is successful is best understood with an example.Existing State of the Ledger:
Suppose 3 sell offers of BTC-USD exist on the orderbook.
1. offerId = 123, sellerID = account X
2. offerId = 234, sellerID = account Y
3. offerID = 456, sellerId = account Z
Given a
ManageOfferBuy
operation for BTC-USD with a sourceAccount = Account P, that fills against the 3 existing offers, we will generate 6 events for account P, and 2 each for account X, Y, Z, so a total of 12 events.In general, number of transfer events = len(claimAtom list) * 2 * 2
This is what will be included in the Details section
Manage Sell Offer
Path Payment Strict Send
Path Payment Strict Receive
Smart Contract Events
Smart Contract events are emiited as a part of the transaction meta when the an
InvokeHostFn
operation is executed.There are four types of events emitted that deal with token movement, as described in SEP-41 and CAP-46-6
**Note: The names of the fields in these events are named so as to conform to the topic and field names as specified in CAP-46-6 **
Refer to these snippets in CAP-46-6
The text was updated successfully, but these errors were encountered: