Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

event_info.gno

1.52 Kb · 45 lines
 1package pool
 2
 3import (
 4	"gno.land/p/gnoswap/utils/v1"
 5
 6	pl "gno.land/r/gnoswap/pool"
 7)
 8
 9type tickEventInfo struct {
10	tickID   int32
11	tickInfo pl.TickInfo
12}
13
14// ToString serializes tick event information as a compact JSON object.
15// The object includes the tick index and every persisted TickInfo field using
16// the short event keys documented below.
17//
18// Returns:
19//   - string: JSON object containing tick, liquidity, fee-growth, cumulative-time, and initialization fields.
20func (t *tickEventInfo) ToString() string {
21	return "{\"t\":" + utils.FormatInt(t.tickID) +
22		",\"lg\":\"" + t.tickInfo.LiquidityGross() + "\"" +
23		",\"ln\":\"" + t.tickInfo.LiquidityNet() + "\"" +
24		",\"fg0\":\"" + t.tickInfo.FeeGrowthOutside0X128() + "\"" +
25		",\"fg1\":\"" + t.tickInfo.FeeGrowthOutside1X128() + "\"" +
26		",\"tco\":\"" + utils.FormatInt(t.tickInfo.TickCumulativeOutside()) + "\"" +
27		",\"spl\":\"" + t.tickInfo.SecondsPerLiquidityOutsideX128() + "\"" +
28		",\"so\":\"" + utils.FormatUint(t.tickInfo.SecondsOutside()) + "\"" +
29		",\"i\":\"" + utils.FormatBool(t.tickInfo.Initialized()) + "\"}"
30}
31
32// NewTickEventInfo creates event data for one tick and its persisted state.
33//
34// Parameters:
35//   - tickID: tick index represented by the event.
36//   - tickInfo: tick state whose fields are serialized by ToString.
37//
38// Returns:
39//   - *tickEventInfo: event information value retaining the supplied tick index and state.
40func NewTickEventInfo(tickID int32, tickInfo pl.TickInfo) *tickEventInfo {
41	return &tickEventInfo{
42		tickID:   tickID,
43		tickInfo: tickInfo,
44	}
45}