-
Notifications
You must be signed in to change notification settings - Fork 206
/
price.go
56 lines (44 loc) · 1.23 KB
/
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
50
51
52
53
54
55
56
package action
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/NibiruChain/collections"
"github.com/NibiruChain/nibiru/app"
"github.com/NibiruChain/nibiru/x/common/asset"
"github.com/NibiruChain/nibiru/x/common/testutil/action"
"github.com/NibiruChain/nibiru/x/oracle/types"
)
func SetOraclePrice(pair asset.Pair, price sdk.Dec) action.Action {
return &setPairPrice{
Pair: pair,
Price: price,
}
}
type setPairPrice struct {
Pair asset.Pair
Price sdk.Dec
}
func (s setPairPrice) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
app.OracleKeeper.SetPrice(ctx, s.Pair, s.Price)
return ctx, nil, true
}
func InsertOraclePriceSnapshot(pair asset.Pair, time time.Time, price sdk.Dec) action.Action {
return &insertOraclePriceSnapshot{
Pair: pair,
Time: time,
Price: price,
}
}
type insertOraclePriceSnapshot struct {
Pair asset.Pair
Time time.Time
Price sdk.Dec
}
func (s insertOraclePriceSnapshot) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error, bool) {
app.OracleKeeper.PriceSnapshots.Insert(ctx, collections.Join(s.Pair, s.Time), types.PriceSnapshot{
Pair: s.Pair,
Price: s.Price,
TimestampMs: s.Time.UnixMilli(),
})
return ctx, nil, true
}