Skip to content

Commit

Permalink
Fix position snapshots dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Nov 25, 2024
1 parent aa243e6 commit b4ca69d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 13 deletions.
37 changes: 28 additions & 9 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,25 @@ type ClockTick @entity(immutable: true) {
type Investor @entity {
"The investor address"
id: Bytes!

"All investor beefy positions"
positions: [ClmPosition!]! @derivedFrom(field: "investor")
"All investor interactions"
interactions: [ClmPositionInteraction!]! @derivedFrom(field: "investor")

"All investor classic positions"
classicPositions: [ClassicPosition!]! @derivedFrom(field: "investor")
"All investor classic snapshots"
classicSnapshots: [ClassicPositionSnapshot!]! @derivedFrom(field: "investor")
"All investor classic interactions"
classicInteractions: [ClassicPositionInteraction!]! @derivedFrom(field: "investor")

"All investor clm positions"
clmPositions: [ClmPosition!]! @derivedFrom(field: "investor")
"All investor clm snapshots"
clmSnapshots: [ClmPositionSnapshot!]! @derivedFrom(field: "investor")
"All investor clm interactions"
clmInteractions: [ClmPositionInteraction!]! @derivedFrom(field: "investor")
}

"""
Expand Down Expand Up @@ -377,7 +392,7 @@ type ClassicPosition @entity {
interactions: [ClassicPositionInteraction!]! @derivedFrom(field: "investorPosition")

"All snapshots of the investor position"
snapshots: [ClassicPositionSnapshot!]! @derivedFrom(field: "position")
snapshots: [ClassicPositionSnapshot!]! @derivedFrom(field: "investorPosition")
}

enum ClassicPositionInteractionType {
Expand Down Expand Up @@ -475,8 +490,10 @@ type ClassicPositionSnapshot @entity {

"The Classic the snapshot is for"
classic: Classic!
"The Classic position the snapshot is for"
position: ClassicPosition!
"The investor that has a position in the Classic"
investor: Investor!
"The investor position the snapshot is for"
investorPosition: ClassicPosition!

"""
Duration of the snapshot period in seconds.
Expand Down Expand Up @@ -863,11 +880,11 @@ type ClmPosition @entity {
"Total amount of CLM shares the investor holds. Should always equal to managerBalance + rewardPoolBalance. This is mostly used for filtering."
totalBalance: BigInt!

"All snapshots of the investor position"
snapshots: [ClmPositionSnapshot!]! @derivedFrom(field: "position")

"All investor position interactions"
interactions: [ClmPositionInteraction!]! @derivedFrom(field: "investorPosition")

"All snapshots of the investor position"
snapshots: [ClmPositionSnapshot!]! @derivedFrom(field: "investorPosition")
}

enum ClmPositionInteractionType {
Expand Down Expand Up @@ -955,10 +972,12 @@ type ClmPositionSnapshot @entity {
"ClmPosition.id + period + timestamp"
id: Bytes!

"The CLM the snapshot is for"
"The CLM the investor has a position in"
clm: CLM!
"The CLM position the snapshot is for"
position: ClmPosition!
"The investor that has a position in the CLM"
investor: Investor!
"The investor position the interaction is for"
investorPosition: ClmPosition!

"""
Duration of the snapshot period in seconds.
Expand Down
10 changes: 9 additions & 1 deletion sentio/ai.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# prompt intro
# prompt

write the sql query for XXX in @XXX.md, use everything need in @schema.graphql and @sentio

# context

<context>
<agent>
You are a data analyist writing SQL for a clickhouse database. You are asked to create SQL reports on a database that contains Beefy's indexer pre-processed data and format in in the required specification's format.
</agent>
<summary>
The goal is to transform our data, currenty stored in an SQL database into a standardized format that follows the sentio specifications.
</summary>
Expand All @@ -15,6 +22,7 @@
- use `JSONExtract(col, 'Array(String)')` to extract data from columns of BigInt[]
- enums column names are postfixed with `__`. Exeample: `type: ClassicPositionInteractionType!` -> `column name: type__`
- convert timestamps with `fromUnixTimestamp(toInt64(col))`
- there is rarely a
</availableTools>

<resources>
Expand Down
48 changes: 47 additions & 1 deletion sentio/clm_alm.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ List of pools in the protocol.
| strategy_vault_receipt_token_decimals | The decimal amount of the ERC20 receipt token. | number |
| strategy_vault_receipt_token_symbol | The symbol of the receipt token. | string |


```SQL
SELECT
42161 as chain_id,
tx.blockTimestamp as timestamp,
tx.blockNumber as creation_block_number,
strategy.id as strategy_vault_contract_address,
clm.underlyingProtocolPool as liquidity_pool_address,
managerToken.id as strategy_vault_receipt_token_address,
managerToken.decimals as strategy_vault_receipt_token_decimals,
managerToken.symbol as strategy_vault_receipt_token_symbol
FROM CLM clm
JOIN ClmManager manager ON clm.manager = manager.id
JOIN Transaction tx ON manager.createdWith = tx.id
JOIN ClmStrategy strategy ON clm.strategy = strategy.id
JOIN Token managerToken ON clm.managerToken = managerToken.id
ORDER BY timestamp DESC
```


### Position Snapshot

Snapshot of the pool users.
Expand All @@ -37,6 +57,10 @@ Snapshot of the pool users.
| underlying_token_amount_usd | The amount based on the user's share of the total underlying token, in USD. | number |
| total_fees_usd | The total amount of revenue and fees paid in this pool in the given snapshot, in USD. | number |

```SQL

```

### Pool Snapshot

TVL, fees, and incentives data at the pool level.
Expand All @@ -54,6 +78,12 @@ TVL, fees, and incentives data at the pool level.
| underlying_token_amount_usd | The amount of underlying tokens supplied in this pool, in USD. | number |
| total_fees_usd | The total amount of revenue and fees paid in this pool in the given snapshot, in USD. | number |


```SQL

```


### ERC LP Token Transfer Events

All LP Token transfer events
Expand All @@ -71,6 +101,12 @@ All LP Token transfer events
| amount | The amount of token transacted, decimal normalized. | number |
| event_type | The type of event, corresponds to the action taken by the user (ie, deposit, withdrawal). | string |


```SQL

```


### Events

All user events (ie, Deposit, Withdrawal)
Expand All @@ -89,6 +125,12 @@ All user events (ie, Deposit, Withdrawal)
| amount_usd | The amount of token transacted, in USD. | number |
| event_type | The type of event, corresponds to the action taken by the user (ie, deposit, withdrawal). | string |


```SQL

```


### Incentive Claim Data

Transactional data on user level incentives claimed data.
Expand All @@ -106,4 +148,8 @@ Transactional data on user level incentives claimed data.
| amount_usd | The amount of claimed tokens in USD. | number |
| other_incentive_usd | (Optional) Any incentives outside of the claimed token, in this transaction, summed up in USD terms. | number |

> Note: This markdown file is auto-generated.

```SQL

```

3 changes: 2 additions & 1 deletion src/classic/entity/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export function getClassicPositionSnapshot(
if (!snapshot) {
snapshot = new ClassicPositionSnapshot(snapshotId)
snapshot.classic = position.classic
snapshot.position = position.id
snapshot.investor = position.investor
snapshot.investorPosition = position.id

snapshot.period = period
snapshot.timestamp = timestamp
Expand Down
3 changes: 2 additions & 1 deletion src/clm/entity/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function getClmPositionSnapshot(position: ClmPosition, timestamp: BigInt,
if (!snapshot) {
snapshot = new ClmPositionSnapshot(snapshotId)
snapshot.clm = position.clm
snapshot.position = position.id
snapshot.investor = position.investor
snapshot.investorPosition = position.id

snapshot.period = period
snapshot.timestamp = timestamp
Expand Down

0 comments on commit b4ca69d

Please sign in to comment.