Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

orderwatch,rpc: Supply parsed contract events in emitted OrderEvents #396

Closed
fabioberger opened this issue Sep 5, 2019 · 1 comment
Closed
Assignees

Comments

@fabioberger
Copy link
Contributor

Currently, OrderEvents emitted by Mesh represent the order's net fillability changes introduced by all the transactions within a block. Some use-cases require knowing about all smart contract events that led to this net fillability change.

Example: If an order is filled and cancelled within a block, we only emit a CANCELLED order event (since this is the final state of the order). We do include the transaction hashes of both the fill & cancel transactions, but accessing the underlying smart contract events requires clients to do further Ethereum JSON-RPC calls. Since we already have the parsed smart contract events in Mesh, we could simply include them in the response.

Proposed new OrderEvent type:

// OrderEvent is the order event emitted by Mesh nodes on the "orders" topic
// when calling JSON-RPC method `mesh_subscribe`
type OrderEvent struct {
	OrderHash                common.Hash    `json:"orderHash"`
	SignedOrder              *SignedOrder   `json:"signedOrder"`
	Kind                     OrderEventKind `json:"kind"`
	FillableTakerAssetAmount *big.Int       `json:"fillableTakerAssetAmount"`
	Transactions []Transaction `json:"transactions"`
}

// Transaction is a succinct representation of an Ethereum transaction
type Transaction struct {
	TxHash common.Hash `json:"orderHash"`
	Logs   []ParsedLog `json:"logs"`
}

// ParsedLog represents a parsed smart contract event/log
type ParsedLog struct {
	Name       string            `json:"name"`
	Parameters map[string]string `json:"parameters"`
}

Example OrderEvent:

{
    "jsonrpc": "2.0",
    "method": "mesh_subscription",
    "params": {
        "subscription": "0xcd0c3e8af590364c09d0fa6a1210faf5",
        "result": [
            {
                "orderHash": "0x96e6eb6174dbf0458686bdae44c9a330d9a9eb563962512a7be545c4ecc13fd4",
                "signedOrder": {
                    "makerAddress": "0x50f84bbee6fb250d6f49e854fa280445369d64d9",
                    "makerAssetData": "0xf47261b00000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc942",
                    "makerAssetAmount": "4424020538752105500000",
                    "makerFee": "0",
                    "takerAddress": "0x0000000000000000000000000000000000000000",
                    "takerAssetData": "0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                    "takerAssetAmount": "1000000000000000061",
                    "takerFee": "0",
                    "senderAddress": "0x0000000000000000000000000000000000000000",
                    "exchangeAddress": "0x4f833a24e1f95d70f028921e27040ca56e09ab0b",
                    "feeRecipientAddress": "0xa258b39954cef5cb142fd567a46cddb31a670124",
                    "expirationTimeSeconds": "1559422407",
                    "salt": "1559422141994",
                    "signature": "0x1cf16c2f3a210965b5e17f51b57b869ba4ddda33df92b0017b4d8da9dacd3152b122a73844eaf50ccde29a42950239ba36a525ed7f1698a8a5e1896cf7d651aed203"
                },
                "kind": "CANCELLED",
                "fillableTakerAssetAmount": 0,
                "transactions": [
                    {
                        "txHash": "0x84aaae84147fc42fc77b33e2d3e05d86272663792d9cacaa8dc89f207b4d0642",
                        "logs": [
                            {
                                "name": "Fill",
                                "parameters": {
                                        "makerAddress":        "0x50f84bbee6fb250d6f49e854fa280445369d64d9",
                                        "takerAddress":        "0xab1a3e8af590364c09d0fa6a12103ada1bccda31",
                                        "senderAddress":       "0x0000000000000000000000000000000000000000",
                                        "feeRecipientAddress": "0xa258b39954cef5cb142fd567a46cddb31a670124",
                                        "makerAssetFilledAmount": "2212010269376052700000",
                                        "takerAssetFilledAmount": "500000000000000000",
                                        "makerFeePaid":           "0",
                                        "takerFeePaid":           "0",
                                        "orderHash":              "0x96e6eb6174dbf0458686bdae44c9a330d9a9eb563962512a7be545c4ecc13fd4",
                                        "makerAssetData":      "0xf47261b00000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc942",
                                        "takerAssetData":      "0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                                },
                            },
                        ],
                    },
                    {
                        "txHash": "0x9e6830a7044b39e107f410e4f765995fd0d3d69d5c3b3582a1701b9d68167560",
                        "logs": [
                            {
                                "name": "Cancel",
                                "parameters": {
                                    "makerAddress":        "0x50f84bbee6fb250d6f49e854fa280445369d64d9",
                                    "feeRecipientAddress": "0xa258b39954cef5cb142fd567a46cddb31a670124",
                                    "senderAddress":       "0x0000000000000000000000000000000000000000",
                                    "orderHash":           "0x96e6eb6174dbf0458686bdae44c9a330d9a9eb563962512a7be545c4ecc13fd4",
                                    "makerAssetData":      "0xf47261b00000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc942",
                                    "takerAssetData":      "0xf47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
                                },
                            },
                        ],
                    },
                ]
            }
        ]
    }
}

The benefit of this approach is a much better developer experience for use-cases that require the smart contract events (e.g., market-makers who need all contract events for trade execution, operations and bookkeeping purposes). The downside is that each event is not larger in size.

@fabioberger
Copy link
Contributor Author

Open question: Are only the Exchange contract's Fill, Cancel and CancelUpTo events important, or also token Transfer, Approval events that impact order fillability?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant