-
Notifications
You must be signed in to change notification settings - Fork 502
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
[epic] horizon: support single balance assets #4722
Comments
Should we emit "payment" effects for smart-contract-induced transfers? Probably yes, but that'll be interesting, but we can get those from events in the txmeta emitted by the built-in asset contract. Coordinate with @sisuresh to make sure those events are emitted as expected. |
The good news is that the horizon accounts endpoint should already display the correct asset balances. We won't need to modify ingestion to update trustline balances because smart-contract-induced transfers will generate tx meta reflecting the changes in the trustlines. All tx-meta, regardless of whether it is caused by a smart-contract operation or a stellar classic operation, is ingested via the trustline processor. However, there are still two horizon endpoints that need to be updated in order to support single balance assets: /assets and /effects. /assets For a any given asset, the /assets endpoint shows information about how many accounts and claimable balances hold the asset and the total amount of the asset:
We could add two extra fields in the response In order to implement these changes we would need to ingest contract data ledger entries into the horizon db. We would also need to modify the asset stats processor to process contract data ledger entry changes. Specifically, we would need to identify if a contract data ledger entry change originates from the builtin token contract. A soroban smart contract can either be compiled from wasm or it can be an instantiation of the builtin token contract. The builtin token contract is a special smart contract which represents a Stellar Classic asset. To determine if a soroban smart contract is a builtin token contract, you can derive a ledger key corresponding to the contract data ledger entry that stores the code for the smart contract. Using that ledger key, we can lookup the contract data ledger entry from the horizon db.
With the ledger entry we can parse the If we have identified that the smart contract is a builtin token, we would need to check if the contract data ledger entry is storing a token balance. If so, we would need to update the deltas in the asset stats processor for smart contract balances. Effects We will need to emit "Account Credited" / "Account Debited" effects whenever a Stellar asset is transferred or clawed back from a Stellar account via a smart contract invocation. This will require modifications to the effects ingestion processor. The changes should be pretty straight forward because we can iterate through the tx meta produced by the invoke host function operation and see if there are any ledger entry changes for trustlines. We could also introduce a new set of effects for when a smart contract receives or spends a Stellar asset ("Smart Contract Credited" / "Smart Contract Debited"). Supporting these new effects will require either processing contract data ledger entry changes (the same workflow described above in the asset stats processor) or processing transfer events emitted by the smart contract. We would also need to implement SEP-23: Add a contract strkey in all the stellar sdks so that the horizon clients could parse the smart contract credited / debited effects from horizon. Payments @bartekn raised a good point: horizon has a payments endpoint which returns all operations that result in a payment to / from an account. Since stellar assets can be transferred via smart contract invocations it would make sense to include those operations in the payments endpoint. Test Cases We should have integration tests which cover the following scenarios:
In all these test cases we should verify that the |
Does the contract data ledger entry for built-in token contract have a well-known/published model(expressed in rust data types) that can be used to locate the asset balances within? |
@sisuresh we discussed supporting single balance assets in horizon during our team meeting today and we realized that it would simplify our ingestion code significantly if there was an easy way to identify if a contract data ledger entry belongs to a token contract (as opposed to a custom contract with WASM). Would it be possible to encode the contract id in such a way that we could differentiate between token contracts and normal wasm contracts? If that's not possible, would it make sense to add another field to the |
Something noteworthy: as of today, Horizon's |
@tamirms the |
@sisuresh I think that only applies for the |
@tamirms Ah yeah I misread your comment. Making the contractID for the SAC special has come up in the past, but it's something I'd like to avoid to keep the experience between using the SAC and a WASM token the same. We could add additional information to the entries, but this isn't ideal and I'm not convinced it's necessary. Wouldn't the consumer already be aware of the |
@sisuresh that would require you to store extra information so you can identify all contract ids which correspond to a SAC. it's doable but I was jut wondering if there was a way to do it without having to record all contract ids which are SAC. |
the test development was carved out to a separate ticket #4726 |
@tamirms We could add another field to |
Design needs to be finalized (what Horizon needs to exposed for contracts). |
I am going to zero out the points on this, and we'll need to point the individual/child tasks within it. I believe that we pointed this quite a long time ago when the scope of this ticket was less well known and before we had actually broken it out into multiple tasks |
horizon: support single balance assets
Acceptance Criteria: Horizon updates to support the new aspects:
Child tasks:
The text was updated successfully, but these errors were encountered: