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

Tick methods implementation in precompile #100

Merged
merged 16 commits into from
Aug 31, 2023
Merged

Conversation

lumos42
Copy link

@lumos42 lumos42 commented Aug 19, 2023

No description provided.

bidsHead := bibliophile.GetBidsHead(input.Amm)
if input.Tick.Cmp(bidsHead) != -1 {
return nil, fmt.Errorf("tick %d is greater than or equal to bidsHead %d", input.Tick, bidsHead)
}

Choose a reason for hiding this comment

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

We dont need this check. It is already covered in contract and logic will return bidsHead if called anyway.
Same for asks

@@ -386,6 +387,114 @@ func validateExecuteIOCOrder(bibliophile b.BibliophileClient, order *orderbook.I
}, nil
}

func GetPrevTick(bibliophile b.BibliophileClient, input GetPrevTickInput) (*big.Int, error) {
if input.Tick.Sign() == 0 {

Choose a reason for hiding this comment

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

Dont need to check if input == 0. Logic can handle it. We allow 0 price orders

Choose a reason for hiding this comment

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

we dont allow 0 price orders

precompile/contracts/bibliophile/amm.go Outdated Show resolved Hide resolved
Comment on lines +486 to +497
func GetQuote(bibliophile b.BibliophileClient, ammAddress common.Address, baseAssetQuantity *big.Int) *big.Int {
return new(big.Int).Div(new(big.Int).Mul(new(big.Int).Abs(baseAssetQuantity), bibliophile.GetLastPrice(ammAddress)), big.NewInt(1e18))
}

func GetBaseQuote(bibliophile b.BibliophileClient, ammAddress common.Address, quoteAssetQuantity *big.Int) *big.Int {
isLong := quoteAssetQuantity.Sign() >= 0
baseAssetQuantity := new(big.Int).Div(new(big.Int).Mul(quoteAssetQuantity, big.NewInt(1e6)), bibliophile.GetLastPrice(ammAddress))
if isLong {
return baseAssetQuantity
}
return new(big.Int).Neg(baseAssetQuantity)
}

Choose a reason for hiding this comment

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

The intent for these 2 methods was to return the impact based on the orderbook depth.

precompile/contracts/juror/logic.go Outdated Show resolved Hide resolved
precompile/contracts/juror/logic.go Outdated Show resolved Hide resolved
precompile/contracts/bibliophile/orderbook.go Outdated Show resolved Hide resolved
precompile/contracts/juror/logic.go Outdated Show resolved Hide resolved
precompile/contracts/bibliophile/client.go Outdated Show resolved Hide resolved
precompile/contracts/bibliophile/margin_account.go Outdated Show resolved Hide resolved
@atvanguard atvanguard merged commit 3238788 into post-only Aug 31, 2023
2 checks passed
@atvanguard atvanguard deleted the postonly_tick_methods branch August 31, 2023 12:28
@atvanguard atvanguard mentioned this pull request Aug 31, 2023
atvanguard added a commit that referenced this pull request Sep 3, 2023
* 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]>
atvanguard added a commit that referenced this pull request Sep 30, 2023
* 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]>
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.

3 participants