Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

feat: Add marketmap module/keeper #114

Merged
merged 5 commits into from
Feb 12, 2024

Conversation

Eric-Warehime
Copy link
Collaborator

Adds marketmap module and keeper implementation.

I've adhered generally to the proto implementations that were committed to the feature branch, although I think a broader conversation should be had about how those are laid out (we can change that in a separate PR if we agree on a different data layout there).

I've written this initial implementation around the idea of 2 access patterns:

  • Reasoning about which providers to run and the sets of tickers each provider needs to retrieve
  • Reasoning about which tickers to return in the oracle's Prices API and how to calculate each of those prices

Managing them separately seems the most reasonable to me since it enables us to have a 2 phase operation in which we turn on new currency pair feeds in the MarketConfigs and subsequently enable the prices in the x/oracle module by creating an aggregation config.

I've left out validation for now--happy to add that logic and tests in if it's crucial for this PR, I think a lot of it already exists in the proto types package already.

BLO-879

@Eric-Warehime Eric-Warehime changed the title fea: Add marketmap module/keeper feat: Add marketmap module/keeper Feb 11, 2024
Copy link

codecov bot commented Feb 11, 2024

Codecov Report

Attention: 26 lines in your changes are missing coverage. Please review.

Comparison is base (98a56c2) 75.08% compared to head (0643803) 74.94%.

Files Patch % Lines
x/marketmap/keeper/keeper.go 69.81% 8 Missing and 8 partials ⚠️
x/marketmap/types/errors.go 0.00% 8 Missing ⚠️
x/marketmap/types/codec.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           feat/marketmap     #114      +/-   ##
==================================================
- Coverage           75.08%   74.94%   -0.15%     
==================================================
  Files                 141      144       +3     
  Lines                5775     5838      +63     
==================================================
+ Hits                 4336     4375      +39     
- Misses               1086     1102      +16     
- Partials              353      361       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cdc codec.BinaryCodec

// keeper dependencies
oracleKeeper types.OracleKeeper
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we really should not be adding anything from x/oracle as a dependency into x/marketmap. My thinking was for x/marketmap to expose hooks in a pattern similar to how some other cosmos sdk modules do.

Something like AfterMarketMapUpdate() which can be used by x/oracle (or x/prices) to get a view of changes without adding a direct keeper dependency

Copy link
Contributor

Choose a reason for hiding this comment

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

Could get around this via an interface + implementation for the x/oracle module?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removing oracleKeeper interface from deps here. Plan is to have a follow up PR which includes hooks.

marketConfigs collections.Map[string, types.MarketConfig]
// aggregationConfigs is keyed by CurrencyPair string (BASE/QUOTE) and contains the PathsConfig used
// to do price aggregation for a given canonical Ticker
aggregationConfigs collections.Map[string, types.PathsConfig]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not in the scope of this PR, but I'm wondering if we could/should introduce a type alias

type TickerString string

so we can more easily reason about the types of keys we are using to index into maps throughout the codebase

Copy link
Contributor

Choose a reason for hiding this comment

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

is it not possible to use the CurrencyPair obj. as they key to this Map?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that seems like a great idea. 🚀

Copy link
Contributor

@aljo242 aljo242 left a comment

Choose a reason for hiding this comment

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

lgtm.

Regarding my other comment, maybe we can open an issue / discussion on this. Not blocking moving forward.

Comment on lines +29 to +35
// MarketProvider is the unique name used to key the MarketConfigs in the marketmap module.
// It is identical to the MarketConfig.Name property which is stored as the value in the Keeper.marketConfigs map.
type MarketProvider string

// TickerString is the key used to identify unique pairs of Base/Quote with corresponding PathsConfig objects--or in other words AggregationConfigs.
// The TickerString is identical to Slinky's CurrencyPair.String() output in that it is `Base` and `Quote` joined by `/` i.e. `$BASE/$QUOTE`.
type TickerString string
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to put these in ./pkg/types as common types?

@Eric-Warehime
Copy link
Collaborator Author

lgtm.

Regarding my other comment, maybe we can open an issue / discussion on this. Not blocking moving forward.

Done--BLO-904

@Eric-Warehime Eric-Warehime merged commit 2edc66c into feat/marketmap Feb 12, 2024
@Eric-Warehime Eric-Warehime deleted the eric/marketmap-keeper branch February 12, 2024 22:32
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.

3 participants