Skip to content

Commit

Permalink
First incentive claim query
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Nov 25, 2024
1 parent 85337c0 commit 7d2a880
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/opera.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"network": "optimism",
"network": "10",

"multicall3Address": "0xcA11bde05977b3631167028862bE2a173976CA11",
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
Expand Down
33 changes: 22 additions & 11 deletions sentio/alm_general.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
# Intro

- Requirements: https://github.com/delta-hq/schemas/blob/main/schemas/general/SCHEMA.md
- FAQ: https://openblock.notion.site/Onboarding-FAQs-571951f8ecff4e7ca927fab4e27e8401
- clickhouse docs:
- https://clickhouse.com/docs/en/sql-reference/functions/array-functions#arrayzip
- https://clickhouse.com/docs/en/sql-reference/functions/array-join
- Schema: `../schema.graphql`

# prompt help

- Given SQL access to the given @schema.graphql schema where each type is accessible as a standard SQL table and relations are accessible though join.
- the id of the relation is available as the relation name. Example: do NOT use `table.relation.id`, use `table.relation`.
- you have access to clickhouse functions and should write in clickhouse SQL format
- escape names with backticks
- use `toDecimal256()` to convert BigInt to numbers,
- example: `toDecimal256(any(p.underlying_token_amount_str), 18) as underlying_token_amount`
- use `array*` functions to deal with arrays (`arrayZip`, `arrayMap`, `arrayJoin`, etc)
- use `JSONExtract(col, 'Array(String)')` to extract data from columns of BigInt[]
- enums column names are postfixed with `__`. Exeample: `type: ClassicPositionInteractionType!` -> `column name: type__`

# General

Expand Down Expand Up @@ -39,26 +47,29 @@ Transactional data on user level incentives claimed data.
SELECT
interaction.timestamp,
42161 as chain_id,
hex(tx.id) as transaction_hash,
hex(interaction.createdWith) as transaction_hash,
interaction.logIndex as log_index,
hex(tx.sender) as transaction_signer,
hex(interaction.investor.id) as user_address,
arrayJoin(clm.rewardTokensOrder) as claimed_token_address,
arrayJoin(interaction.rewardBalancesDelta) as amount,
(
arrayJoin(interaction.rewardBalancesDelta) *
arrayJoin(interaction.rewardToNativePrices) *
interaction.nativeToUSDPrice
) / pow(10, 36) as amount_usd,
hex(interaction.investor) as user_address,
JSONExtract(clm.rewardTokensOrder, 'Array(String)') as claimed_token_address,
JSONExtract(interaction.rewardBalancesDelta, 'Array(String)') as amount,
arrayMap(
x -> (toDecimal256(x.2, 18) * toDecimal256(x.3, 18) * toDecimal256(interaction.nativeToUSDPrice, 18)) / pow(10, 36),
arrayZip(
JSONExtract(clm.rewardTokensOrder, 'Array(String)'),
JSONExtract(interaction.rewardBalancesDelta, 'Array(String)'),
JSONExtract(interaction.rewardToNativePrices, 'Array(String)')
)
) as amount_usd,
0 as other_incentive_usd
FROM
ClmPositionInteraction interaction
`ClmPositionInteraction` interaction
JOIN
CLM clm ON interaction.clm = clm.id
JOIN
Transaction tx ON interaction.createdWith = tx.id
WHERE
interaction.type = 'CLM_REWARD_POOL_CLAIM'
type__ = 'CLM_REWARD_POOL_CLAIM'
ORDER BY
interaction.timestamp DESC
```
Expand Down
2 changes: 1 addition & 1 deletion src/config.template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"

export const NETWORK_NAME = "{{network}}"
export const NETWORK_NAME = ""{{{network}}}""
export const WNATIVE_TOKEN_ADDRESS = Address.fromString("{{wrappedNativeAddress}}")
export const WNATIVE_DECIMALS = BigInt.fromU32({{wrappedNativeDecimals}})
export const PRICE_ORACLE_TYPE: string = "{{priceOracleType}}"
Expand Down
28 changes: 14 additions & 14 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ indexerHints:
dataSources:
- kind: ethereum/contract
name: ClmManagerFactory
network: {{network}}
network: "{{{network}}}"
source:
address: "{{clmManagerFactoryAddress}}"
abi: ClmManagerFactory
Expand Down Expand Up @@ -68,7 +68,7 @@ dataSources:

- kind: ethereum/contract
name: ClmStrategyFactory
network: {{network}}
network: "{{{network}}}"
source:
address: "{{clmStrategyFactoryAddress}}"
abi: ClmStrategyFactory
Expand All @@ -86,7 +86,7 @@ dataSources:

- kind: ethereum/contract
name: RewardPoolFactory
network: {{network}}
network: "{{{network}}}"
source:
address: "{{rewardPoolFactoryAddress}}"
abi: RewardPoolFactory
Expand All @@ -104,7 +104,7 @@ dataSources:

- kind: ethereum/contract
name: Clock
network: {{network}}
network: "{{{network}}}"
source:
address: "{{clmManagerFactoryAddress}}"
abi: ClmManagerFactory
Expand All @@ -125,7 +125,7 @@ dataSources:

- kind: ethereum/contract
name: ClassicVaultFactory
network: {{network}}
network: "{{{network}}}"
source:
address: "{{beefyClassicVaultFactoryAddress}}"
abi: ClassicVaultFactory
Expand Down Expand Up @@ -156,7 +156,7 @@ dataSources:

- kind: ethereum/contract
name: ClassicBoostFactory
network: {{network}}
network: "{{{network}}}"
source:
address: "{{beefyClassicBoostFactoryAddress}}"
abi: ClassicBoostFactory
Expand All @@ -175,7 +175,7 @@ dataSources:
templates:
- name: ClmManager
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: ClmManager
mapping:
Expand All @@ -193,7 +193,7 @@ templates:

- name: ClmStrategy
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: ClmStrategy
mapping:
Expand Down Expand Up @@ -221,7 +221,7 @@ templates:

- name: RewardPool
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: RewardPool
mapping:
Expand All @@ -237,7 +237,7 @@ templates:

- name: ClmRewardPool
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: RewardPool
mapping:
Expand All @@ -259,7 +259,7 @@ templates:

- name: ClassicRewardPool
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: RewardPool
mapping:
Expand All @@ -283,7 +283,7 @@ templates:

- name: ClassicVault
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: ClassicVault
mapping:
Expand All @@ -303,7 +303,7 @@ templates:

- name: ClassicStrategy
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: ClassicStrategy
mapping:
Expand All @@ -325,7 +325,7 @@ templates:

- name: ClassicBoost
kind: ethereum/contract
network: {{network}}
network: "{{{network}}}"
source:
abi: ClassicBoost
mapping:
Expand Down

0 comments on commit 7d2a880

Please sign in to comment.