Skip to content

Commit

Permalink
feat(x/twap): whitelist GeometricTwap and GeometricTwapToNow (#3852)
Browse files Browse the repository at this point in the history
* feat(x/twap): GeometricTwap and GeometricTwapToNow queries added to Stargate whitelist

* update docs
  • Loading branch information
p0mvn committed Dec 23, 2022
1 parent b57d6d7 commit f1fb63f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#3708](https://github.com/osmosis-labs/osmosis/pull/3708) `Exp2` function to compute 2^decimal.
* [#3693](https://github.com/osmosis-labs/osmosis/pull/3693) Add `EstimateSwapExactAmountOut` query to stargate whitelist
* [#3731](https://github.com/osmosis-labs/osmosis/pull/3731) BigDec Power functions with decimal exponent.
* [#3847](https://github.com/osmosis-labs/osmosis/pull/3847) GeometricTwap and GeometricTwapToNow queries added to Stargate whitelist.

### API breaks

Expand Down
2 changes: 2 additions & 0 deletions wasmbinding/stargate_whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ func init() {
// twap
setWhitelistedQuery("/osmosis.twap.v1beta1.Query/ArithmeticTwap", &twapquerytypes.ArithmeticTwapResponse{})
setWhitelistedQuery("/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow", &twapquerytypes.ArithmeticTwapToNowResponse{})
setWhitelistedQuery("/osmosis.twap.v1beta1.Query/GeometricTwap", &twapquerytypes.GeometricTwapResponse{})
setWhitelistedQuery("/osmosis.twap.v1beta1.Query/GeometricTwapToNow", &twapquerytypes.GeometricTwapToNowResponse{})
setWhitelistedQuery("/osmosis.twap.v1beta1.Query/Params", &twapquerytypes.ParamsResponse{})

// downtime-detector
Expand Down
7 changes: 6 additions & 1 deletion x/twap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Given these interpolated accumulation values, we can compute the TWAP as before.

## Module API

The primary intended API is `GetArithmeticTwap`, which is documented below, and has a similar cosmwasm binding.
The primary intended APIs are `GetArithmeticTwap` and `GetGeometricTwap`, which are documented below,
and have a similar cosmwasm binding.

```go
// GetArithmeticTwap returns an arithmetic time weighted average price.
Expand Down Expand Up @@ -91,6 +92,10 @@ func (k Keeper) GetArithmeticTwap(ctx sdk.Context,
There are convenience methods for `GetArithmeticTwapToNow` which sets `endTime = ctx.BlockTime()`, and has minor gas reduction.
For users who need TWAPs outside the 48 hours stored in the state machine, you can get the latest accumulation store record from `GetBeginBlockAccumulatorRecord`.

Geometric TWAP has comparable methods with the same parameters. Namely, `GetGeometricTwap` and `GetGeometricTwapToNow`.
The semantics of these methods are the same with the arithmetic version. The only difference is the low-level
computation of the TWAP, which is done via the geometric mean.

## Code layout

**api.go** is the main file you should look at as a user of this module.
Expand Down

0 comments on commit f1fb63f

Please sign in to comment.