Skip to content
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

The Rise of the Hubblenet #61

Draft
wants to merge 191 commits into
base: master
Choose a base branch
from
Draft

The Rise of the Hubblenet #61

wants to merge 191 commits into from

Conversation

atvanguard
Copy link

@atvanguard atvanguard commented Jun 1, 2023

For Illustration purpose - to review the diff with the original subnet-evm repo. Not meant to be merged.

asquare08 and others added 30 commits November 23, 2022 08:18
* place and save order onchain

* execute matched orders

* changes based on PR comments
* Send a sample tx when a tx is received

It goes into an infinite loop right now

* add limit order processor

* Add ABI parser

* Remove hardcoded ABI

* Order book (#1)

* place and save order onchain

* execute matched orders

* changes based on PR comments

* Make contarct call to OrderBook

* add limit_order database layer to store and get limit_orders from sqlite database

* Fix contract calls to OrderBook

* Insert orders in sqlite database

Read transactions and insert/update orders in database

* Fix db tests

* fix tests

* check for price equality in GetLimitOrderByPositionTypeAndPrice method

* return status in limit_orders in GetLimitOrder method

* add test for updatelimit order status method

* Add new run script

* Review changes

* Execute orders after block production

* Store orders in memory and send tx at buildBlock

* return if len of transaction input data is less than 4 fields

* fix tests

* change public methods to private and use them

* add test for limit_order

* add test for NewLimitOrderProcessor

* minor refactoring

Co-authored-by: vipul sharma <vipulsharma2190@gmail.com>
Co-authored-by: asquare <21087753+asquare08@users.noreply.github.com>
* orderbook as genesis

* reduce blocktime and clean tests

* fix tests

Co-authored-by: Atul Agarwal <21087753+asquare08@users.noreply.github.com>
* add tests for memory_database

* add GetOrdersByPriceAndPositionType method

* remove execute test order and add logic for matching limit orders and making contract call

* refactoring limit_order private methods

* add OrderMatched event in orderbook contract and test event generation

* log error is baseAssetQuantity is zero, add method for position type

* break matching limit order loop if matching order is found

* Use contract address instead of ABI for parseTx

* Use ChainAcceptedEvent instead of NewHeadEvent

* fix syntax error

* refactor memory_database and remove matching logic from limit_order

* add limit order matching engine and call it during buildblock

* add purge local tx before running matching logic

* minor fixes

* check executeMatchedOrder tx status before deleting limit orders

* delete pending executeMatchedOrders txs before running matching engine

Co-authored-by: Shubham Goyal <sgshubham@gmail.com>
* add filledBaseAssetQuantity in limit order

* fix tests

* add test for RunMatchingEngine

* pull changes from hubble-v2

* remove sqlite database files

* add LimitOrderDatabase interface and implement in inMemoryDatabase

* deven|fdgod create LimitOrderTxProcessor interface

* deven|fdgod add tests for limit_order and mocks for LimitOrderDatabase and LimitOrderTxProcessor

* add tests for RunMatchingLogic in limit_order

* fix previous tests

* change memory_database to return object instead of pointer to limit_orders stored in memory_database

* change matching logic to partial match limit orders with different BaseAssetQuantity

* change ExecuteMatchedOrdersTx as per new contract

* delete order if filledBaseAssetQuantity is equal to BaseAssetQuantity

* update filledBaseAssetQuantity after parsing executeMatchedOrders

* return LimitOrder instead of pointer in its memory_database

* add test for GetOrder

* return InMemoryDatabase from NewInMemoryDatabase and remove GetOrder function

* remove GetOrder method from mocks

* change salt to int64

* convert fillAmount to uint

* add parsing logic for two orders in function input and output

* pass orders with type Order to executeMatchedOrders tx

* change logic of skipping already filled orders in RunMatchingEngine method in limit_order

* refactor code
#13)

* change price check in matching engine to match if longOrder price >= shortOrder price

* more aggresive assertions

* Add tests for getUnFilledBaseAssetQuantity

* refactor TestGetUnfilledBaseAssetQuantity

* refactor RunMatchingEngine in limit_order and add tests

Co-authored-by: atvanguard <3612498+atvanguard@users.noreply.github.com>
* add genesis contracts

* update orderbook.sol

* update comments

* precision
* funding skeleton

* Handle events and add liquidation logic

* Fix merge errors

* minor fixes

* Ignore orders matched during liquidation for matching

* add tests for UpdateMargin, UpdatePosition, UpdateUnrealisedFunding method in memory_database

* check for presence of positions for address in ResetUnrealisedFunding and add tests

* fix tests

* add lastPrice when db initialized and add tests

* Liquidation and UnrealisedFunding fixes

* Review changes

* Use big.Int everywhere

* add functions specified in LimitOrderTxProcessor interface

* fix liquidations compare marginFraction logic

* check if position nil in UpdateUnrealisedFunding and fix tests

* Add missing file

* Fetch all logs at once

* Add missing file

* fix: Change multiplication factor

* purge liquidateAndExecuteOrder and settleFunding tx

* Fix precision handling

* refactor liquidations and add tests

* Review fixes

* fix tests

* Fix incorrect amounts in runLiquidations

* Fix errors after merge

* fix tests

* fix tests

* add genesis contracts + mocked orderBook (#14)

* add genesis contracts

* update orderbook.sol

* update comments

* precision

* Review fixes

* Handle OrderCancelled

* Pass notionalPosition in function

* fix tests

* Review fixes

* Change IsFundingPaymentTime

Co-authored-by: Shubham Goyal <sgshubham@gmail.com>
Co-authored-by: fdgod <vipulsharma2190@gmail.com>
expose api which return all database data
* move liquidations from database and change GetLiquidations into a standalone pure function, fix tests

* move out contract events processor from limit_order_tx_processor and add tests
lumos42 and others added 30 commits January 17, 2024 15:03
* Delete expired signed orders and virtual reserved margin

* cache time.Now and Abs(baseAssetQ) when reserving margin

* add SampleImpactPrice unit tests

* Bugfixes from testing

* Fix virtual reserved margin bug

* Remove handling for short orders

---------

Co-authored-by: atvanguard <3612498+atvanguard@users.noreply.github.com>
* remove order specific methods from jurorv2

* dynamically fetch signedOrderBookAddress

* upgrade ts

* set empty orderhash

* misc

* remove logs

* misc

* handle new trader
* Use gob encoding for gossiping orders instead of rlp

* Fix snapshot loading

* Fix nil VirtualReserved error

* Allow gossiping to non validators
* cancel stale reduce only orders

* review comments
* instantiate hState once

* misc
* Update avalanchego version in local scripts

* Update subnet config to allow gossiping to non-validators

* Add more tests for jurorv2 precompile

* Change versions for mainnet

* jurorv2 activation time

* rename deprecated apis

---------

Co-authored-by: atvanguard <3612498+atvanguard@users.noreply.github.com>
* send oracle prices to evaluate availableMargin

* deepcopy hState
* set signedOrderBook addy from precompile call

* hardcode values for aylin
* Store makerbook and snapshot to file

* Update default paths

* Save snapshots only to the file

* minor change

* Fix log

* Revert "Save snapshots only to the file"

This reverts commit 77e92ea.

* Save snapshot only to file

* Fix log again

* Load snapshot from file first

* Return error when file path is not set

* Review fixes

* Review changes

* tiny changes for more idiomatic code

* use channels to queue messages to write to file

* stop closing the channel within consumer logic when shutdown signal comes

* fix ineffectual assignment lint error

* fix order struct

* Add missing Id set

---------

Co-authored-by: wallydrag <debashish.ghatak@gmail.com>
* allow grace period for market orders to be filled

* dont remove IOC orders based on block number

* remove KEEP_IF_MATCHEABLE orderStatus

* trigger matching if possible when signed order is placed

* add log

* check bidsHead only if !isLongOrder

* fix test
push docker images

feature/oonodz-integration. Update variables
* 🐛 check available margin for correct trader

* remove logs

* add err logs
* add support for custom oracle

* add log, clean comment

---------

Co-authored-by: atvanguard <3612498+atvanguard@users.noreply.github.com>
* Match orders in same block as they are placed

* Add metrics

* Changes for latest avalanche cli

* Review fixes

* Fix compile error
* handle settled markets

* Get fresh hubble state (#191)

* misc

* fix settlement price slot

---------

Co-authored-by: Shubham <lumos@hubble.exchange>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants