-
Notifications
You must be signed in to change notification settings - Fork 0
/
price.go
49 lines (43 loc) · 970 Bytes
/
price.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package keeper
import (
"github.com/QuadrateOrg/core/x/stable/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
AtomPrice sdk.Int
TestingMode bool = false
)
func (k Keeper) UpdateAtomPrice(ctx sdk.Context, pair types.Pair) error {
if TestingMode {
return nil
}
if AtomPrice.IsNil() {
AtomPrice = sdk.NewInt(0)
}
price, err := k.oracleKeeper.GetExchangeRate(ctx, pair.AmountInMetadata.Display)
if err != nil {
return err
}
if price.IsNil() {
return types.ErrAtomPriceNil
}
AtomPrice = price.MulInt64(10000).RoundInt()
return nil
}
func (k Keeper) UpdateAtomPriceTesting(ctx sdk.Context, price sdk.Int) error {
if !TestingMode {
return nil
}
AtomPrice = price
return nil
}
func (k Keeper) GetAtomPrice(ctx sdk.Context, pair types.Pair) (sdk.Int, error) {
err := k.UpdateAtomPrice(ctx, pair)
if err != nil {
return sdk.Int{}, err
}
return AtomPrice, err
}
func (k Keeper) SetTestingMode(value bool) {
TestingMode = value
}