-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add test for order quotes #331
Changes from all commits
00f19da
ef1bb80
41aba0b
cc6dfc5
93d209e
49e887d
907f46d
e3ec33a
35b96ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
DROP TABLE IF EXISTS orders; | ||
DROP TYPE IF EXISTS OrderKind; | ||
DROP TABLE IF EXISTS order_quotes; | ||
DROP TABLE IF EXISTS trades; | ||
|
||
|
||
-- orders table | ||
CREATE TYPE OrderKind AS ENUM ('buy', 'sell'); | ||
|
||
CREATE TABLE IF NOT EXISTS orders | ||
( | ||
uid bytea PRIMARY KEY, | ||
sell_amount numeric(78,0) NOT NULL, | ||
buy_amount numeric(78,0) NOT NULL, | ||
fee_amount numeric(78,0) NOT NULL, | ||
kind OrderKind NOT NULL, | ||
partially_fillable boolean NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS order_quotes | ||
( | ||
order_uid bytea PRIMARY KEY, | ||
sell_amount numeric(78, 0) NOT NULL, | ||
buy_amount numeric(78, 0) NOT NULL, | ||
solver bytea NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS trades | ||
( | ||
block_number bigint NOT NULL, | ||
log_index bigint NOT NULL, | ||
order_uid bytea NOT NULL, | ||
sell_amount numeric(78, 0) NOT NULL, | ||
buy_amount numeric(78, 0) NOT NULL, | ||
|
||
PRIMARY KEY (block_number, log_index) | ||
); | ||
|
||
|
||
TRUNCATE orders; | ||
TRUNCATE order_quotes; | ||
TRUNCATE trades; | ||
|
||
|
||
INSERT INTO orders (uid, sell_amount, buy_amount, fee_amount, kind, partially_fillable) | ||
VALUES ('\x01'::bytea, 95000000, 94000000000000000000, 5000000, 'sell', 'f'), -- normal sell market order | ||
('\x02'::bytea, 101000000, 100000000000000000000, 5000000, 'buy', 'f'), -- normal buy market order | ||
('\x03'::bytea, 100000000, 100000000000000000000, 0, 'sell', 't'), -- partially fillable sell limit order | ||
('\x04'::bytea, 100000000, 100000000000000000000, 0, 'buy', 't'), -- partially fillable buy limit order | ||
('\x05'::bytea, 100000000, 94000000000000000000, 0, 'sell', 'f'), -- in market sell limit order | ||
('\x06'::bytea, 106000000, 100000000000000000000, 0, 'buy', 'f'); -- in market buy limit order | ||
|
||
INSERT INTO order_quotes (order_uid, sell_amount, buy_amount, solver) | ||
VALUES ('\x01'::bytea, 95000000, 95000000000000000000, '\x01'::bytea), | ||
('\x02'::bytea, 101000000, 100000000000000000000, '\x02'::bytea), | ||
('\x03'::bytea, 100000000, 95000000000000000000, '\x03'::bytea), | ||
('\x04'::bytea, 105000000, 100000000000000000000, '\x03'::bytea), | ||
('\x05'::bytea, 100000000, 95000000000000000000, '\x03'::bytea), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's look at order \x05. I think that we should have order_quotes.sell_amount < orders.sell_amount, as the quote takes into account the fee. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just checked our database and it seems that for limit orders, the sell amount is not reduced by some fee amount. E.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you are probably right, although I find this a bit confusing and want to look into how the |
||
('\x06'::bytea, 105000000, 100000000000000000000, '\x03'::bytea); | ||
|
||
INSERT INTO trades (block_number, log_index, order_uid, sell_amount, buy_amount) | ||
VALUES (1, 0, '\x01'::bytea, 100000000, 95000000000000000000), | ||
(2, 0, '\x02'::bytea, 106000000, 100000000000000000000), | ||
(3, 0, '\x03'::bytea, 100000000, 101000000000000000000), | ||
(4, 0, '\x04'::bytea, 99000000, 100000000000000000000), | ||
(5, 0, '\x05'::bytea, 100000000, 95000000000000000000), | ||
(6, 0, '\x06'::bytea, 105000000, 100000000000000000000); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest | ||
|
||
import pandas.testing | ||
from pandas import DataFrame | ||
|
||
from src.pg_client import MultiInstanceDBFetcher | ||
|
||
|
||
class TestQuoteRewards(unittest.TestCase): | ||
def setUp(self) -> None: | ||
db_url = "postgres:postgres@localhost:5432/postgres" | ||
self.fetcher = MultiInstanceDBFetcher([db_url]) | ||
with open( | ||
"./tests/queries/quote_rewards_test_db.sql", "r", encoding="utf-8" | ||
) as file: | ||
self.fetcher.connections[0].execute(file.read()) | ||
|
||
def test_get_quote_rewards(self): | ||
start_block, end_block = "0", "100" | ||
quote_rewards = self.fetcher.get_quote_rewards(start_block, end_block) | ||
expected = DataFrame( | ||
{ | ||
"solver": [ | ||
"0x01", | ||
"0x02", | ||
"0x03", | ||
], | ||
"num_quotes": [ | ||
1, | ||
1, | ||
2, | ||
], | ||
} | ||
) | ||
self.assertIsNone(pandas.testing.assert_frame_equal(expected, quote_rewards)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the order_quotes table does have a fee entry but i am fine with assuming there is none here and instead treat sell_amount as the total amount users need to send to the contract, according to the quote.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the
order_quotes
table does not have a fee entry. It does havegas_amount
,gas_price
, andsellt_token_price
but due to hooks this is not enough to recover fees.For market orders we can use the amount in the
orders
ortrades
table. For limit orders I am not sure what to do. Is there a way to recover the estimated fee amount or does quoting maybe work differently for such orders?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you are right, it is implicit.