Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Rename caps in volume filter tests (part of #522) #600

Merged
merged 8 commits into from
Dec 2, 2020

Conversation

debnil
Copy link
Contributor

@debnil debnil commented Dec 2, 2020

This PR renames caps in the volume filter tests, as part of #522. This renames the various fields called SellBaseAssetCap* as BaseAssetCap*. This reduces the bloat for follow-up PRs, which will add functional changes and additional tests.

@debnil debnil requested a review from nikhilsaraf as a code owner December 2, 2020 21:37
Copy link
Contributor

@nikhilsaraf nikhilsaraf left a comment

Choose a reason for hiding this comment

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

let's discuss in our 1-1 slot tomorrow

@@ -110,8 +110,8 @@ func (c *VolumeFilterConfig) Validate() error {

// String is the stringer method
func (c *VolumeFilterConfig) String() string {
return fmt.Sprintf("VolumeFilterConfig[BaseAssetCapInBaseUnits=%s, BaseAssetCapInQuoteUnits=%s, mode=%s, action=%s, additionalMarketIDs=%v, optionalAccountIDs=%v]",
utils.CheckedFloatPtr(c.BaseAssetCapInBaseUnits), utils.CheckedFloatPtr(c.BaseAssetCapInQuoteUnits), c.mode, c.action, c.additionalMarketIDs, c.optionalAccountIDs)
return fmt.Sprintf("VolumeFilterConfig[baseAssetCapInBaseUnits=%s, baseAssetCapInQuoteUnits=%s, mode=%s, additionalMarketIDs=%v, optionalAccountIDs=%v]",
Copy link
Contributor

Choose a reason for hiding this comment

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

baseAssetCapInBaseUnits should remain as BaseAssetCapInBaseUnits as well as for the other field.

these names should follow the variable names. this can be autogenerated at some point, but we can continue to do manually for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

PS: once we eliminate all direct calls to construct VolumeFilterConfig once it all goes through the raw factory method (a pending TODO), then we can un-export these two fields.

if e != nil {
return nil, fmt.Errorf("could not convert price (%s) to float: %s", op.Price, e)
}

amountValueUnitsBeingSold, e := strconv.ParseFloat(op.Amount, 64)
offerAmountValueUnits, e := strconv.ParseFloat(op.Amount, 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

@debnil this variable name change has introduced unwanted ambiguity..

amountValueUnitsBeingSold tells us that the value corresponds to the selling asset in the manageSellOffer.
offerAmountValueUnits does not tell us whether the amount corresponds to the selling asset or buying asset in the manageSellOffer.

  1. need to figure out what this variable means when we use buy types, which is not super-straightforward -- may need to take a TDD approach or intrusive debugging to figure this out.
  2. need to name this variable accordingly so it is super clear.

the reason we need to do the two steps above is because we unfortunately had solved the trivial case previously -- doing a "sell" type operation using a manageSellOffer where amount and price all follow the selling asset (because that's how manageSellOffer works). the hard part is to now figure out what values we will see when we invert it.

let's discuss in our 1-1 session tomorrow (Thursday) about what you end up finding from your debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, got it, ok. I'll revert these names as well.

return opToReturn, nil
}
} else {
// TODO buying side - we need to implement this to support buy side filters; extract common logic from the above sell side case
opToReturn := op
Copy link
Contributor

Choose a reason for hiding this comment

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

As you might have guessed, this is the main meat of the buytwap logic. Everything else we've done so far was basically just plumbing work to get us here.

I think the right thing to do is to extract the common logic from the above sell side case to simplify this. For example, things like projectedBoughtInBaseUnits should logically represent projectedExposureInBaseUnits instead so it can be reused for both buy and sell.

this basically boils down to the fact that selling XLM/USD is the same as buying USD/XLM so we don't need any if conditions or new logic, but we need some sort of "translation layer" that converts both the buy/sell forms to a more general form where we can phrase it as "exposure" to a specific asset (where exposure means the likely consumption of that asset from the balance because we give it up) vs explicitly saying amount is being bought/sold. The end result should make it "immediately obvious" what is happening in the code.

To do this it may be helpful to grok exactly what is going on in the above sell case and refactor the logic to be more generalized to both buy and sell cases. In the past, I've had success with modeling the code blocks as a flowchart with distinct logical blocks. A good separation point for logical blocks could be the if conditions, but that is of course not necessary as there may be some redundant logic there too. When you model the buy side and sell side it will be easy to identify what the overlap is.

This is one the main reasons whey we needed extensive testing of this function with numerous test cases so we know that there are no regressions when we do such a significant refactor.

does this make sense? would be useful to discuss in our 1-1 tomorrow as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, it makes a ton of sense and is super helpful. Now that we've made the associated renames in this PR, I'll work on pulling out that logic in a follow-up :)

plugins/volumeFilter_test.go Show resolved Hide resolved
Copy link
Contributor

@nikhilsaraf nikhilsaraf left a comment

Choose a reason for hiding this comment

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

lgtm, thanks! 🚢

@debnil debnil changed the title Implement buy-side volume filter (part of #522) Rename caps in volume filter tests (part of #522) Dec 2, 2020
@debnil debnil merged commit a1863b7 into stellar-deprecated:master Dec 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants