-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[x/TWAP] Expose a geometric TWAP API (#3529)
* refactored twap api.go for geometric TWAP * added barebon docs * romans feedback * new * fix * nichola feedback * final roman comments
- Loading branch information
1 parent
a278573
commit 0d13512
Showing
2 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package twap | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/osmosis-labs/osmosis/v13/x/twap/types" | ||
) | ||
|
||
// twapStrategy is an interface for computing TWAPs. | ||
// We have two strategies implementing the interface - arithmetic and geometric. | ||
// We expose a common TWAP API to reduce duplication and avoid complexity. | ||
type twapStrategy interface { | ||
// computeTwap calculates the TWAP with specific startRecord and endRecord. | ||
computeTwap(startRecord types.TwapRecord, endRecord types.TwapRecord, quoteAsset string) (sdk.Dec, error) | ||
} | ||
|
||
type arithmetic struct { | ||
keeper Keeper | ||
} | ||
|
||
var _ twapStrategy = &arithmetic{} | ||
|
||
func (s *arithmetic) computeTwap(startRecord types.TwapRecord, endRecord types.TwapRecord, quoteAsset string) (sdk.Dec, error) { | ||
return computeTwap(startRecord, endRecord, quoteAsset, arithmeticTwapType) | ||
} |