Closed poly-rodr closed 2 years ago
Hey @poly-rodr some notes and apologies for not giving a clearer and more informed ticket. I didn’t look closely enough at the args that are provided in the OrderFilled
event, but I think we should essentially forget about events from the LOP contract and only index FilledOrder
events from the OrderExecutor. A few things about that:
FilledOrder
event because we are missing some things we need. TRADE_TYPE_BUY_LIMIT
FilledOrder
event should register a buy and a sell
I am going to throw an event on the calendar Monday to go over this. Have a great weekend!
Running locally for mumbai
{
accounts {
id
}
}
{
"data": {
"accounts": [
{
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
{
"id": "0xe3d9bfa896af6988f80027bfd13440a42c5ed02b"
},
{
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
}
]
}
}
{
filledOrderGlobals {
id
tradesQuantity
buysQuantity
sellsQuantity
collateralVolume
scaledCollateralVolume
collateralBuyVolume
scaledCollateralBuyVolume
collateralSellVolume
scaledCollateralSellVolume
}
}
{
"data": {
"filledOrderGlobals": [
{
"buysQuantity": "0",
"collateralBuyVolume": "0",
"collateralSellVolume": "4100000000",
"collateralVolume": "4100000000",
"id": "",
"scaledCollateralBuyVolume": "0",
"scaledCollateralSellVolume": "4100",
"scaledCollateralVolume": "4100",
"sellsQuantity": "4",
"tradesQuantity": "4"
}
]
}
}
{
filledOrdersEvents {
id
timestamp
taker {
id
}
makerAsset
takerAsset
makerAssetID
takerAssetID
makerAmountFilled
takerAmountFilled
}
}
{
"data": {
"filledOrdersEvents": [
{
"id": "0x33c389933dacd13cee47305f5a192ff944282df6ce4a837c1b4c70b79ed70385",
"makerAmountFilled": "50000000",
"makerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"makerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"taker": {
"id": "0xe3d9bfa896af6988f80027bfd13440a42c5ed02b"
},
"takerAmountFilled": "100000000",
"takerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"takerAssetID": "0",
"timestamp": "1648064258"
},
{
"id": "0x78e0b9b8c8ddc8057568f8e2d389066c03669bbb3e5e885769d2275485dd5fa2",
"makerAmountFilled": "550000000",
"makerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"makerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"taker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"takerAmountFilled": "1000000000",
"takerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"takerAssetID": "0",
"timestamp": "1648105122"
},
{
"id": "0x9c81bd0efcb0d8bbc980ce7e73cac522e04232ec3575069921bfa5b8598de7a3",
"makerAmountFilled": "1100000000",
"makerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"makerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"taker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"takerAmountFilled": "2000000000",
"takerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"takerAssetID": "0",
"timestamp": "1648078501"
},
{
"id": "0xc3c731a89f069657a51a214941cece4fa08795a3c55b18abf6c870dbe6118c62",
"makerAmountFilled": "550000000",
"makerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"makerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"taker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"takerAmountFilled": "1000000000",
"takerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"takerAssetID": "0",
"timestamp": "1648105052"
}
]
}
}
{
orderFilledEvents {
id
timestamp
orderHash
maker {
id
}
taker {
id
}
makerAsset
takerAsset
makerAssetID
takerAssetID
makerAmountFilled
takerAmountFilled
remainingAmount
}
}
{
"data": {
"orderFilledEvents": [
{
"id": "0x33c389933dacd13cee47305f5a192ff944282df6ce4a837c1b4c70b79ed70385",
"maker": {
"id": "0xe3d9bfa896af6988f80027bfd13440a42c5ed02b"
},
"makerAmountFilled": "50000000",
"makerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"makerAssetID": "0",
"orderHash": "0xcaea64f66fc40c53ff391e8076b1a2987a6a6a0acf2b8a8bdabaf676900c3978",
"remainingAmount": "0",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"takerAmountFilled": "100000000",
"takerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"takerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"timestamp": "1648064258"
},
{
"id": "0x78e0b9b8c8ddc8057568f8e2d389066c03669bbb3e5e885769d2275485dd5fa2",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"makerAmountFilled": "550000000",
"makerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"makerAssetID": "0",
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"remainingAmount": "0",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"takerAmountFilled": "1000000000",
"takerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"takerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"timestamp": "1648105122"
},
{
"id": "0x9c81bd0efcb0d8bbc980ce7e73cac522e04232ec3575069921bfa5b8598de7a3",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"makerAmountFilled": "55000000",
"makerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"makerAssetID": "0",
"orderHash": "0x729cbd93cc6b94ae93f985384f8e84c2157c305dc57581935d2a3479d54a23b8",
"remainingAmount": "0",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"takerAmountFilled": "100000000",
"takerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"takerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"timestamp": "1648078501"
},
{
"id": "0xc3c731a89f069657a51a214941cece4fa08795a3c55b18abf6c870dbe6118c62",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"makerAmountFilled": "550000000",
"makerAsset": "0x2e8dcfe708d44ae2e406a1c02dfe2fa13012f961",
"makerAssetID": "0",
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"remainingAmount": "550000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"takerAmountFilled": "1000000000",
"takerAsset": "0x7d8610e9567d2a6c9fbf66a5a13e9ba8bb120d43",
"takerAssetID": "16678291189211314787145083999015737376658799626183230671758641503291735614088",
"timestamp": "1648105052"
}
]
}
}
{
filledOrders {
id
timestamp
maker {
id
}
taker {
id
}
orderHash
market {
id
}
side
size
price
}
}
{
"data": {
"filledOrders": [
{
"id": "0x33c389933dacd13cee47305f5a192ff944282df6ce4a837c1b4c70b79ed70385",
"maker": {
"id": "0xe3d9bfa896af6988f80027bfd13440a42c5ed02b"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xcaea64f66fc40c53ff391e8076b1a2987a6a6a0acf2b8a8bdabaf676900c3978",
"price": "0.5",
"side": "Limit_Buy",
"size": "50000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648064258"
},
{
"id": "0x78e0b9b8c8ddc8057568f8e2d389066c03669bbb3e5e885769d2275485dd5fa2",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"price": "0.55",
"side": "Limit_Buy",
"size": "550000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648105122"
},
{
"id": "0x9c81bd0efcb0d8bbc980ce7e73cac522e04232ec3575069921bfa5b8598de7a3",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0x729cbd93cc6b94ae93f985384f8e84c2157c305dc57581935d2a3479d54a23b8",
"price": "0.55",
"side": "Limit_Buy",
"size": "55000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648078501"
},
{
"id": "0xc3c731a89f069657a51a214941cece4fa08795a3c55b18abf6c870dbe6118c62",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"price": "0.55",
"side": "Limit_Buy",
"size": "550000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648105052"
}
]
}
}
{
filledOrderBooks {
id
tradesQuantity
buysQuantity
sellsQuantity
collateralVolume
scaledCollateralVolume
collateralBuyVolume
scaledCollateralBuyVolume
collateralSellVolume
scaledCollateralSellVolume
lastActiveDay
buys {
id
timestamp
maker {
id
}
taker {
id
}
orderHash
market {
id
}
side
size
price
}
sells {
id
timestamp
maker {
id
}
taker {
id
}
orderHash
market {
id
}
side
size
price
}
}
}
{
"data": {
"filledOrderBooks": [
{
"buys": [
{
"id": "0x33c389933dacd13cee47305f5a192ff944282df6ce4a837c1b4c70b79ed70385",
"maker": {
"id": "0xe3d9bfa896af6988f80027bfd13440a42c5ed02b"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xcaea64f66fc40c53ff391e8076b1a2987a6a6a0acf2b8a8bdabaf676900c3978",
"price": "0.5",
"side": "Limit_Buy",
"size": "50000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648064258"
},
{
"id": "0x78e0b9b8c8ddc8057568f8e2d389066c03669bbb3e5e885769d2275485dd5fa2",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"price": "0.55",
"side": "Limit_Buy",
"size": "550000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648105122"
},
{
"id": "0x9c81bd0efcb0d8bbc980ce7e73cac522e04232ec3575069921bfa5b8598de7a3",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0x729cbd93cc6b94ae93f985384f8e84c2157c305dc57581935d2a3479d54a23b8",
"price": "0.55",
"side": "Limit_Buy",
"size": "55000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648078501"
},
{
"id": "0xc3c731a89f069657a51a214941cece4fa08795a3c55b18abf6c870dbe6118c62",
"maker": {
"id": "0xea5981ca48dc40c950fc1b2496c4a0ef900bb841"
},
"market": {
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288"
},
"orderHash": "0xc6a82e11e89c757d72de4ccfe6ef1f9c84deab548083edc335bf3bbe1bf4dd12",
"price": "0.55",
"side": "Limit_Buy",
"size": "550000000",
"taker": {
"id": "0x1199443d6806de23a9c976193f07a381542f81df"
},
"timestamp": "1648105052"
}
],
"buysQuantity": "4",
"collateralBuyVolume": "2250000000",
"collateralSellVolume": "0",
"collateralVolume": "2250000000",
"id": "0x24df940a9eaa302a342777ae853d5de64ddafb80d8fc98be3ac8e09b779d2288",
"lastActiveDay": "19075",
"scaledCollateralBuyVolume": "2250",
"scaledCollateralSellVolume": "0",
"scaledCollateralVolume": "2250",
"sells": [],
"sellsQuantity": "0",
"tradesQuantity": "4"
}
]
}
}
All this looks good, just one thing. It is a bit confusing I think for FilledOrder
to have 4 buys and then FilledOrderGlobal
has recorded 4 sells. I get why this is the case but I think we should maybe just:
1) swap maker/taker in handleFilledOrders
2) swap maker/taker in recordEvent
in OrderExecutorV2Mapping.ts
This would mean the market order creator is always the taker (even in the context of the OrderExecutor) and the limit order creator is always the maker.
All this looks good, just one thing. It is a bit confusing I think for
FilledOrder
to have 4 buys and thenFilledOrderGlobal
has recorded 4 sells. I get why this is the case but I think we should maybe just:
- swap maker/taker in
handleFilledOrders
- swap maker/taker in
recordEvent
in OrderExecutorV2Mapping.tsThis would mean the market order creator is always the taker (even in the context of the OrderExecutor) and the limit order creator is always the maker.
Eventually it might make sense to redo the events on the contracts directly to be inline with this, but for now I think we can just make these changes at the subgraph level.
Summary
Listen for
Filled
event of OrderExecutorV2Notes
I only included contract addresses of
mumbai
becauseOrderExecutorV2
are not deployed onpolygon
yet.OrderExecutorV2
needs to be updated