> For the complete documentation index, see [llms.txt](https://docs.gnoswap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gnoswap.io/contracts/pool/oracle.gno.md).

# oracle.gno

{% embed url="<https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno>" %}

## NewObservationsTree

```go
func NewObservationsTree() *bptree.BPTree
```

NewObservationsTree creates the top-level B+tree that indexes pool observation trees by pool path.

#### Return Values

| Name   | Type            | Description                                                    |
| ------ | --------------- | -------------------------------------------------------------- |
| `tree` | \*bptree.BPTree | Empty B+tree suitable for storing pool-path observation trees. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L144)

## Types

### Observation

```go
type Observation struct
```

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L8)

#### Methods

**BlockTimestamp**

```go
func (o Observation) BlockTimestamp() int64
```

Observation getter methods. BlockTimestamp returns the observation's block timestamp.

#### Return Values

| Name             | Type  | Description                                       |
| ---------------- | ----- | ------------------------------------------------- |
| `blockTimestamp` | int64 | Timestamp at which this observation was recorded. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L20)

**Initialized**

```go
func (o Observation) Initialized() bool
```

Initialized reports whether the observation contains initialized oracle data.

#### Return Values

| Name          | Type | Description                                                                   |
| ------------- | ---- | ----------------------------------------------------------------------------- |
| `initialized` | bool | True when the observation slot has been initialized; false for an empty slot. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L41)

**SecondsPerLiquidityCumulativeX128**

```go
func (o Observation) SecondsPerLiquidityCumulativeX128() string
```

SecondsPerLiquidityCumulativeX128 returns the Q128-encoded cumulative seconds-per-liquidity value recorded by the observation.

#### Return Values

| Name                                | Type   | Description                                                     |
| ----------------------------------- | ------ | --------------------------------------------------------------- |
| `secondsPerLiquidityCumulativeX128` | string | Decimal string containing the cumulative value scaled by 2^128. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L33)

**TickCumulative**

```go
func (o Observation) TickCumulative() int64
```

TickCumulative returns the signed cumulative tick recorded by the observation.

#### Return Values

| Name             | Type  | Description                                              |
| ---------------- | ----- | -------------------------------------------------------- |
| `tickCumulative` | int64 | Cumulative tick value through the observation timestamp. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L26)

#### Constructors

* `func DefaultObservation() Observation` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L71))
* `func GetObservationAt(poolPath string, index uint16) (Observation, error)` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/getter.gno#L399))
* `func MakeObservation(blockTimestamp int64, tickCumulative int64, secondsPerLiquidityCumulativeX128 string, initialized bool) Observation` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L53))

### ObservationTree

```go
type ObservationTree struct
```

ObservationTree is a pool-local oracle ring buffer keyed by index. It owns the B+tree key encoding so oracle code works with uint16 indices.

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L82)

#### Methods

**Get**

```go
func (t *ObservationTree) Get(
	index uint16
) (Observation, bool)
```

Get looks up an observation by its circular-buffer index.

#### Parameters

| Name    | Type   | Description                      |
| ------- | ------ | -------------------------------- |
| `index` | uint16 | uint16 observation slot to read. |

#### Return Values

| Name          | Type        | Description                                                                                                                             |
| ------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `observation` | Observation | Stored observation when the tree contains a value of the expected type; otherwise the zero observation.                                 |
| `ok`          | bool        | True when a stored value was found and decoded as an Observation; false for nil/uninitialized trees, missing slots, or a type mismatch. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L102)

**Has**

```go
func (t *ObservationTree) Has(
	index uint16
) bool
```

Has reports whether an observation slot exists in the tree.

#### Parameters

| Name    | Type   | Description                      |
| ------- | ------ | -------------------------------- |
| `index` | uint16 | uint16 observation slot to test. |

#### Return Values

| Name     | Type | Description                                                                                         |
| -------- | ---- | --------------------------------------------------------------------------------------------------- |
| `exists` | bool | True when the initialized tree contains index; false for nil/uninitialized trees or an absent slot. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L133)

**Set**

```go
func (t *ObservationTree) Set(
	index uint16,
	observation Observation
)
```

Set stores an observation at a circular-buffer index.

#### Parameters

| Name          | Type        | Description                                |
| ------------- | ----------- | ------------------------------------------ |
| `index`       | uint16      | uint16 observation slot to write.          |
| `observation` | Observation | Observation value to associate with index. |

[source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L119)

#### Constructors

* `func NewObservationTree() *ObservationTree` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L90))
* `func NewPoolObservationsTree(currentTime int64) *ObservationTree` ([source](https://github.com/gnoswap-labs/gnoswap/blob/d9d34bd345a36c3eedaccf491c6615b0ac4168cd/contract/r/gnoswap/pool/oracle.gno#L155))
