Contract code entry provides catalog of app protocols and events supported #1596
Replies: 2 comments 11 replies
-
I think contracts already have the components in place to solve problems like this. Contract WASMs have two custom sections that can contain entries that describe both the interface and meta information about the contract within. Any system that indexes contracts can extract that data as needed. Both the spec and meta live in the custom sections and are unprocessed by the network because they have no impact on the network. In much the same way the app catalogue as proposed above has no use to the network itself, it's just more meta to be interpreted by off-chain systems. The two custom sections that already exist today are:
I believe a solution to the problem can be built using the existing meta, and maybe the existing spec if the spec is expanded to capture event schemas (stellar/rs-soroban-sdk#1097). No one has proposed this yet, but it could be as simple as specifying, for example:
@sreuland If this is something you'd like to experiment with, extracting this information, lmk and we can do a walk through of the logic to get at it and parse it, which is relatively small amount of logic and would be easy to replicate in another application or indexer you're building. |
Beta Was this translation helpful? Give feedback.
-
I believe we need a SEP to define the standard for NFT contracts. This SEP should also canonicalize the events emitted by an NFT contract, ensuring consistency across implementations. For contracts that do not adhere to an existing SEP, they should define their event schemas in the custom WASM section, as Leigh suggested, so consumers know what to expect regarding event structure. Event schema should be required part of a contract interface description. Also Errors too (we will leave that for another day). |
Beta Was this translation helpful? Give feedback.
-
Background
ScVal
, there are no requirements on format of values set in topics.Problem
Downstream applications cannot determine what app protocols a soroban contract participates or events it may emit from current state of ledger. Instead downstream apps employ various custom approaches in order to identify what contracts adhere to an application protocol and therefore their system can process ensuing events, often requires an ingestion pipeline to parse historical and ongoing event flows to identify contracts which are emitting events with names that align to the application protocol of interest. Or the downstream application maintains a static list of contract addresses for which it knows are related to the protocol of interest.
App protocols which contracts can adhere to such as for tokenization, defi, etc may require the contract implementing programmatic interfaces but the protocols may also require a series or sequence of events to be emitted by the contract during the invocations and lifetime cycles. Each protocol can stipulate these events are required through documentation only, possibly even with overlapping event names of other protocols.
There is no mechanism for the contract programmatic interfaces to enforce the event behaviors, therefore, a contract could implement the protocol's interface but not emit all of the events during invocation, leading to inconsistency for downstream applications to correctly process the contract data relevant to a protocol.
Proposal
Enable key use cases:
(1) Downstream apps can identify latest app protocols and events a contract instance supports while on the network based on its executable reference to the contract's code ledger entry via (
ContractCodeEntry
) which could provide a standardized catalog of protocol and event names supported by the contract's code.(2) Downstream apps can focus ingestion pipeline on this catalog from the contract's code ledger entry as a standard way to determine a contract instance's protocol support, and therefore any related event parsing. Allowing app data pipelines to more dynamically parse incoming events accurately to a protocol spec, and remove the need for custom, out-of-band type approaches to determine event parsing rules.
(3) Downstream apps could leverage the catalog ledger entry as a standard way to dynamically discover contracts on the network which are compliant with an app protocol and therefore can invoke functions from the protocol interface as such.
(4) The existing convention of the first topic of an event emitted by contract is the logical name of the event must continue to be followed, as it's the only way to identify discrete event types.
(5) Only the contract code can assert the protocols and events it's able to participate in by specifying the optional catalog at wasm upload time, enhancing the CAP-00460-02 host function to accept the catalog at same time as the wasm
upload_wasm(wasm: Bytes, catalog: AppProtocolCatalog)
and same update to allow catalog in related InvokeHostFnHOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM
.Example of the contract application protocol catalog as an extension of the
ContractCodeEntry
:Beta Was this translation helpful? Give feedback.
All reactions