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

rewired-0.5.3 vs [email protected] #126

Closed
wants to merge 136 commits into from
Closed

rewired-0.5.3 vs [email protected] #126

wants to merge 136 commits into from

Conversation

lumos42
Copy link

@lumos42 lumos42 commented Oct 1, 2023

No description provided.

0xshinobii 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 <[email protected]>
Co-authored-by: asquare <[email protected]>
* orderbook as genesis

* reduce blocktime and clean tests

* fix tests

Co-authored-by: Atul Agarwal <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
Co-authored-by: fdgod <[email protected]>
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
vipulsharma21 and others added 25 commits August 8, 2023 15:44
* update abis

* expose variables read from contracts in precompile via api

* add tests for variableReadFromSlots

* fix to last commit

* amm test

* fixes as per comments on PR

* fixed as per comments on PR
* add integration tests for bibliophile

* update abis

* expose variables read from contracts in precompile via api

* add tests for variableReadFromSlots

* fix to last commit

* amm test

* update contract abis

* fix tests

* fix bibliophile tests

* add tests for validateLiquidationOrderAndDetermineFillPrice

* add helper functions to utils

* fixes as per comments on PR

* add tests for validateOrdersAndDetermineFillPrice

* add tests

* fixes to tests

* fix tests

* fixed as per comments on PR

* fix testing_api and delete duplicate test file

* move bibliophile tests together and test for getPositionSizesAndUpperBoundsForMarkets
* Add StreamMarketTrades API

* Add custom chain config fields

* Review fixes

* Change Ordertype type

* Update config

* Resolve conflicts
* 🐛 GetOrderFilledAmount

* Fix snapshot - delete overfilled orders

---------

Co-authored-by: Shubham Goyal <[email protected]>
* Fix snapshot logic and add GetSnapshot API

* Add comment

* Fix concurrency issue while adding orderbook txs in tx_pool

* Review fixes

* Remove loadMemoryDBSnapshot

* Add LoadFromSnapshotEnabled config
* Logs

* Fix snapshot bug

* Add block number in event logs

* Change logs and remove sleep
* Improve logs

* Skip already expired IOC orders while matching

* Fix snapshot bug

* Remove info logs

* update UnrealisedFunding

* fix tests

* cache cumPremiumFraction

* init CumulativePremiumFraction map

* event apply fixes

* fix tests/add comments

* resolve comments

---------

Co-authored-by: Shubham Goyal <[email protected]>
* add new methods

* gasCost = 69 for everything

* WIP: Add ValidatePlaceLimitOrder and validateCancelLimitOrder (#98)

* add ValidatePlaceLimitOrder and ValidateCancelLimitOrder

* implement getAvailableMargin function

* fixes as per comment in PR and add tests for validatePlaceLimitOrder

* add tests for validateCancelLimitOrder and fix tests for validatePlaceLimitOrder

* update LONG_OPEN_ORDERS_SLOT and SHORT_OPEN_ORDERS_SLOT

* Tick methods implementation in precompile (#100)

* Tick methods

* fix mock and remove unused methods

* use minAllowableMargin from orderbook and marginAccount as per contracts, fix tests, cleanup

* cleanup

* fix assertions where expected and actual were swapped

* change slot numbers

* fix getPrevTick and add tests

* change logic in SampleImpactAsk and SampleImpactBid as per requirement and add unit tests for both

* remove TwosComplement in GetImpactMarginNotional as it is uint ; minor refactoring

* add trading authority check in ValidatePlaceLimitOrderV2 and ValidateCancelLimitOrderV2

* fix SampleImpactAsk and SampleImpactBid

* read minAllowableMargin and takerFee from clearingHouse

* fix validatePlaceLimitOrderV2 and rename trader to sender in validateCancelLimitOrderV2 and validatePlaceLimitOrderV2

* remove add 0 in GetNextBid and GetNextAsk

* return Hash in asks/bidsStorageSlot

---------

Co-authored-by: fdgod <[email protected]>
Co-authored-by: atvanguard <[email protected]>

* New events for OrderV2 (#104)

* New events for OrderV2

* Fixes

* Add new events in PushtoTraderFeed

* misc things

* improve precision in tick methods

* merge main

* update ABIs

* remove redundant methods

* SDK changes and review fixes (#105)

* fixes + matching works

* missing import

* ch.settleFunding

---------

Co-authored-by: fdgod <[email protected]>
Co-authored-by: Shubham <[email protected]>
* remove debug logs

* Fix snapshot saving error

* Snapshot fix: save snapshot at blockNumber - 1

* Add blockNumber in logs

* assert isValidator when assertLowMargin

* Fix snapshot bug

* Debug margin (#107)

* Fix GetAvailableMargin

* v5activation

---------

Co-authored-by: Shubham Goyal <[email protected]>

* logs

---------

Co-authored-by: Shubham Goyal <[email protected]>
* Remove backward compatible changes/upgrades

* More changes

* Review fixes and more breaking changes

* Rename to BaseOrder
* New DetermineFillPrice

* modify runMatchingEngine

* refactor Accept

* juror.determineLiquidationFillPrice

* fix tests

* remove comment

* migrate oever tests to juror
* delete obsolete files

* update interfaces

* refactor juror precompile

* cleanup order_types

* hubble utils

* remove duplicate fncs

* ticks precompile

* reuse Mul/Div

* cosmetics
* Refactor order structures

* Fix tests and add new test

* update old order type

* Review fixes

* Review fixes

* Review fix

* Handle idx = -1

* Unit tests for Delete

---------

Co-authored-by: atvanguard <[email protected]>
* return BadElement in validateLiquidation response

* misc precompile updates

* fix tests

* referrer and price precision check
* Separate OrderBook and LimitOrderbook

* Add missing files

* Minor changes - self review

* Fix unit tests and logic

* More fixes

* Change address in module.go

* Update MatchingValidationError signature

* Update ValidateOrdersAndDetermineFillPrice error outputs

* Fix Oracle price slot

* Fix LimitOrderBook contract address in juror functions

* Update multiplier slot number

* Add invalid market validation

* Add invalid market validation in ValidatePlaceIOCorder

* nit: update comments

---------

Co-authored-by: atvanguard <[email protected]>
* Separate OrderBook and LimitOrderbook

* Add missing files

* Minor changes - self review

* Fix unit tests and logic

* More fixes

* Change address in module.go

* Update MatchingValidationError signature

* Update ValidateOrdersAndDetermineFillPrice error outputs

* Fix Oracle price slot

* Fix LimitOrderBook contract address in juror functions

* Update multiplier slot number

* remove validator tx from being added to txpool during reorg

---------

Co-authored-by: Shubham Goyal <[email protected]>
Co-authored-by: atvanguard <[email protected]>
* Prevent duplicate match transactions

* Review fixes
* add integration tests for place order and cancel order

* add more tests to juror

* add more tests to juror

* [deba/vipul] tests for stale reduceOnly orders while placing orders

* refactor logic to check stale reduceOnly orders in validatePlaceLimitOrder

* remove tests

* add tests for variables read from slots in precompile

* fix tests

* delete logic.go as per main

* update abis

* fix juror tests

* fix ticks tests

* fix getNotionalPositionAndMargin tests

* fix variablesReadFromSlotTests

* skip failing tests

* fix validateLiquidationOrderAndDeterminFillPrice tests

* remove log statements

* fix variablesReadFromSlotTests

* clean after tests in tick.js

* fix validateOrdersAndDeterminFillPrice tests
…118)

* getNormalisedMargin

* refactor GetAvailableMargin

* fix tests

* update slot

* rename vars

* cleanup comments

* baseSlot for collateral idx*3

* userState/hubbleState in margin_math

* hu.Position

* ticks.getQuote

* misc changes
* Add unit tests for Juror

* Tests for areMatchingOrders

* remove print statements

* remove unused import

---------

Co-authored-by: atvanguard <[email protected]>
* calcMarginFraction -> hu.GetMarginFraction

* lastPrice -> midPrice in precompile

* LastPrices -> MidPrices

* fix e2e tests

* review/safer code

* Add margin_math tests

* review comments

---------

Co-authored-by: Shubham Goyal <[email protected]>
* fix unit tests

* Fix avalanchego version and remove unused files

* delete yarn.lock

---------

Co-authored-by: Shubham Goyal <[email protected]>
miner/miner.go Outdated
@@ -68,6 +68,11 @@ func (miner *Miner) GenerateBlock(predicateContext *precompileconfig.ProposerPre
return miner.worker.commitNewWork(predicateContext)
}

func (miner *Miner) GetLastBlockTime() uint64 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

@@ -54,6 +54,7 @@ func TestSkipStateSync(t *testing.T) {
}

func TestStateSyncFromScratch(t *testing.T) {
t.Skip()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

@@ -67,6 +68,7 @@ func TestStateSyncFromScratch(t *testing.T) {
}

func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
t.Skip()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

@atvanguard atvanguard changed the title Rewire 2 to master-rewire rewired-0.5.3 vs [email protected] Oct 2, 2023
@atvanguard atvanguard closed this Oct 2, 2023
@atvanguard atvanguard deleted the rewire-2 branch October 2, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants