-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
…cts, fix tests, cleanup
…t and add unit tests for both
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) | ||
} |
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.
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 { |
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.
Dont need to check if input == 0. Logic can handle it. We allow 0 price 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.
we dont allow 0 price orders
…CancelLimitOrderV2
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) | ||
} |
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 intent for these 2 methods was to return the impact based on the orderbook depth.
…CancelLimitOrderV2 and validatePlaceLimitOrderV2
* 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]>
* 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]>
No description provided.