Skip to content

Commit

Permalink
Handle reward pool token list and prices (#17)
Browse files Browse the repository at this point in the history
* Handle reward pool token list and prices

* Remove outputToken

* Fix multicall

* Handle reward pool token list and prices
  • Loading branch information
prevostc authored Jun 20, 2024
1 parent 06481bd commit f836d04
Show file tree
Hide file tree
Showing 22 changed files with 261 additions and 107 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ yarn test:lint # run prettier linter
- clmStrategyFactory: GlobalPause(bool)
- clmStrategy.pool()
- clmStrategy.vault()
- clmStrategy.output()
- clmStrategy.price()
- clmStrategy.range()
- clmStrategy.balanceOfPool()
- clmStrategy.lpToken1ToNativePrice()
- clmStrategy.lpToken0ToNativePrice()
- clmStrategy.ouptutToNativePrice()
- clmStrategy: Initialized(uint8)
- clmStrategy: Paused(address)
- clmStrategy: Unpaused(address)
Expand All @@ -182,5 +180,13 @@ yarn test:lint # run prettier linter
- rewardPoolFactory: ProxyCreated(address)
- rewardPool.stakedToken()
- rewardPool.totalSupply()
- rewardPool: Initialized(uint8)
```

## Other contracts

```text
beefySwapper: getAmountOut(address,address,uint256)
beefyOracle: getFreshPrice(address)
```
4 changes: 2 additions & 2 deletions bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function publish_goldsky {
DEPLOY_KEY=$3
echo "publishing $SUBGRAPH to goldsky"
goldsky subgraph deploy $SUBGRAPH/$VERSION --path . --token $DEPLOY_KEY
sleep 10 # wait for the subgraph to propagate
goldsky subgraph tag create $SUBGRAPH/$VERSIO --token $DEPLOY_KEY --tag next
sleep 5 # wait for the subgraph to propagate
goldsky subgraph tag create $SUBGRAPH/$VERSION --token $DEPLOY_KEY --tag next
}

function publish {
Expand Down
4 changes: 3 additions & 1 deletion config/arbitrum-beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0xCee843CD04E3758dDC5BCFf08647DddB117151D0",
"beefyOracleAddress": "0x5C7c7Bb0c9251821cB5a1D9c08F21B0DAD5efe65"
}
6 changes: 4 additions & 2 deletions config/arbitrum.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"beefyClassicVaultFactoryAddress": "0x8396f3d25d07531a80770Ce3DEA025932C4953f7",
"beefyClassicVaultFactoryStartBlock": 219696027,
"beefyClassicBoostFactoryAddress": "0x2951c806a75b19954ce0bed477676a54f3c1c200",
"beefyClassicBoostFactoryStartBlock": 197959279,
"beefyClassicBoostFactoryStartBlock": 219696027,
"clockTickBlocks": 1300,

"wrappedNativeAddress": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0xCee843CD04E3758dDC5BCFf08647DddB117151D0",
"beefyOracleAddress": "0x5C7c7Bb0c9251821cB5a1D9c08F21B0DAD5efe65"
}
4 changes: 3 additions & 1 deletion config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0x4200000000000000000000000000000000000006",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0x9F8c6a094434C6E6f5F2792088Bb4d2D5971DdCc",
"beefyOracleAddress": "0x1BfA205114678c7d17b97DB7A71819D3E6718eb4"
}
4 changes: 3 additions & 1 deletion config/linea.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x3c6Cd9Cc7c7a4c2Cf5a82734CD249D7D593354dA",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0x5aD159A8537fE39CAD81748726584C05b68b3c11",
"beefyOracleAddress": "0x3923704D9684ABb234743d65D96c43Bf26414481"
}
4 changes: 3 additions & 1 deletion config/moonbeam.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0xAcc15dC74880C9944775448304B263D191c6077F",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x4497B606be93e773bbA5eaCFCb2ac5E2214220Eb",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0x8F40C4Be6732241222293953475a9e69BFc607AA",
"beefyOracleAddress": "0x4d417C189AE9D1B128397026A124b531A535D741"
}
4 changes: 3 additions & 1 deletion config/optimism-tmp.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0x4200000000000000000000000000000000000006",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x13e3Ee699D1909E989722E753853AE30b17e08c5",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0xe115b50c52cB5624fD76232cDF498ADA6ECD1e69",
"beefyOracleAddress": "0x7066606233Cc8b5ede0925003F8910FF7B15219C"
}
4 changes: 3 additions & 1 deletion config/optimism.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0x4200000000000000000000000000000000000006",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0x13e3Ee699D1909E989722E753853AE30b17e08c5",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0xe115b50c52cB5624fD76232cDF498ADA6ECD1e69",
"beefyOracleAddress": "0x7066606233Cc8b5ede0925003F8910FF7B15219C"
}
4 changes: 3 additions & 1 deletion config/polygon.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
"wrappedNativeAddress": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"wrappedNativeDecimals": 18,
"chainlinkNativePriceFeedAddress": "0xAB594600376Ec9fD91F8e885dADF0CE036862dE0",
"chainlinkNativePriceFeedDecimals": 8
"chainlinkNativePriceFeedDecimals": 8,
"beefySwapperAddress": "0xDd27227Dba7Ea8F5869466A10A8E36Bb2D709b35",
"beefyOracleAddress": "0xfcE4448C50A96c279afdB8CE7735295660653e19"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"typescript": "^5.3.3"
},
"lint-staged": {
"*.--check": "prettier --write"
"*.*": "prettier --write"
}
}
56 changes: 29 additions & 27 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ type CLM @entity {
underlyingToken0: Token!
"The underlying tokens contained in the CLM. This is the second token."
underlyingToken1: Token!
"The reward token of the CLM. This is the token that is minted when the CLM earns non-compounding yield."
rewardToken: Token!
"The reward tokens of the CLM's rewardpool. These will be rewarded to positions when the CLM earns non-compounding yield."
rewardTokens: [Token!]!

# ----- PRICES & STATS -----

Expand All @@ -388,13 +388,13 @@ type CLM @entity {
"Total supply of the reward pool token. Express with `rewardPoolToken.decimals` decimals."
rewardPoolTotalSupply: BigInt!

"Token 0 price in native at the time of the interaction. Expressed with 18 decimals."
"Latest token 0 price in native we have seen. Expressed with 18 decimals."
token0ToNativePrice: BigInt!
"Token 1 price in native at the time of the interaction. Expressed with 18 decimals."
"Latest token 1 price in native we have seen. Expressed with 18 decimals."
token1ToNativePrice: BigInt!
"Reward token 0 price in native at the time of the interaction. Expressed with 18 decimals."
rewardToNativePrice: BigInt!
"Native token price at the time of the interaction. Expressed with 18 decimals."
"Latest reward token prices in native we have seen. Ordered by clm.rewardTokens. Expressed with 18 decimals."
rewardToNativePrices: [BigInt!]!
"Latest native token price we have seen. Expressed with 18 decimals."
nativeToUSDPrice: BigInt!

"""
Expand Down Expand Up @@ -464,13 +464,13 @@ type ClmSnapshot @entity {
"Total supply of the reward pool token. Express with `rewardPoolToken.decimals` decimals."
rewardPoolTotalSupply: BigInt!

"Token 0 price in native at the time of the interaction. Expressed with 18 decimals."
"Latest token 0 price in native of this snapshot. Expressed with 18 decimals."
token0ToNativePrice: BigInt!
"Token 1 price in native at the time of the interaction. Expressed with 18 decimals."
"Latest token 1 price in native of this snapshot. Expressed with 18 decimals."
token1ToNativePrice: BigInt!
"Reward token price in native at the time of the interaction. Expressed with 18 decimals."
rewardToNativePrice: BigInt!
"Native token price at the time of the interaction. Expressed with 18 decimals."
"Latest reward token prices in native of this snapshot. Ordered by clm.rewardTokens. Expressed with 18 decimals."
rewardToNativePrices: [BigInt!]!
"Latest native token price of this snapshot. Expressed with 18 decimals."
nativeToUSDPrice: BigInt!

"""
Expand Down Expand Up @@ -572,21 +572,21 @@ type ClmHarvestEvent @entity(immutable: true) {
compoundedAmount0: BigInt!
"The amount of second underlying tokens compounded"
compoundedAmount1: BigInt!
"The amount of reward tokens collected"
collectedRewards: BigInt!
"The amount of reward tokens collected. Ordered by clm.rewardTokens."
collectedRewards: [BigInt!]!

"Total amount of liquidity in the manager at time of harvest"
managerTotalSupply: BigInt!
"Total amount of reward pool shares at time of harvest"
rewardPoolTotalSupply: BigInt!

"Token 0 price in native at the time of the interaction. Expressed with 18 decimals."
"Token 0 price in native at the time of harvest. Expressed with 18 decimals."
token0ToNativePrice: BigInt!
"Token 1 price in native at the time of the interaction. Expressed with 18 decimals."
"Token 1 price in native at the time of harvest. Expressed with 18 decimals."
token1ToNativePrice: BigInt!
"Reward token price in native at the time of the interaction. Expressed with 18 decimals."
rewardToNativePrice: BigInt!
"Native token price at the time of the interaction. Expressed with 18 decimals."
"Reward token prices in native at the time of harvest. Expressed with 18 decimals. Ordered by clm.rewardTokens."
rewardToNativePrices: [BigInt!]!
"Native token price at the time of harvest. Expressed with 18 decimals."
nativeToUSDPrice: BigInt!
}

Expand Down Expand Up @@ -624,15 +624,15 @@ type ClmManagerCollectionEvent @entity(immutable: true) {
collectedAmount0: BigInt!
"Amount of collected fees in the second token"
collectedAmount1: BigInt!
"Amount of collected fees in the reward token"
collectedRewardAmount: BigInt!
"Amount of collected fees in the reward tokens. Ordered by clm.rewardTokens."
collectedRewardAmounts: [BigInt!]!

"Token 0 price in native at the time of the interaction. Expressed with 18 decimals."
"Token 0 price in native at the time of the collection. Expressed with 18 decimals."
token0ToNativePrice: BigInt!
"Token 1 price in native at the time of the interaction. Expressed with 18 decimals."
"Token 1 price in native at the time of the collection. Expressed with 18 decimals."
token1ToNativePrice: BigInt!
"Reward token price in native at the time of the interaction. Expressed with 18 decimals."
rewardToNativePrice: BigInt!
"Reward token prices in native at the time of the collection. Expressed with 18 decimals. Ordered by clm.rewardTokens."
rewardToNativePrices: [BigInt!]!
"Native token price at the time of the interaction. Expressed with 18 decimals."
nativeToUSDPrice: BigInt!
}
Expand Down Expand Up @@ -712,6 +712,8 @@ type ClmPositionInteraction @entity(immutable: true) {
managerBalanceDelta: BigInt!
"Amount of reward pool shares change in the interaction"
rewardPoolBalanceDelta: BigInt!
"Amount of reward tokens change in the interaction. Ordered by clm.rewardTokens."
rewardBalancesDelta: [BigInt!]!
"Amount of underlying token 0 change in the interaction"
underlyingBalance0Delta: BigInt!
"Amount of underlying token 0 change in the interaction"
Expand All @@ -721,8 +723,8 @@ type ClmPositionInteraction @entity(immutable: true) {
token0ToNativePrice: BigInt!
"Token 1 price in native at the time of the interaction. Expressed with 18 decimals."
token1ToNativePrice: BigInt!
"Reward token price in native at the time of the interaction. Expressed with 18 decimals."
rewardToNativePrice: BigInt!
"Reward token prices in native at the time of the interaction. Expressed with 18 decimals. Ordered by clm.rewardTokens."
rewardToNativePrices: [BigInt!]!
"Native token price at the time of the interaction. Expressed with 18 decimals."
nativeToUSDPrice: BigInt!
}
20 changes: 11 additions & 9 deletions src/clm/compound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import { getEventIdentifier } from "../common/utils/event"
import { updateCLMDataAndSnapshots, fetchCLMData } from "./utils/clm-data"

export function handleClmStrategyHarvestAmounts(event: CLMHarvestEvent): void {
handleClmStrategyHarvest(event, event.params.fee0, event.params.fee1, ZERO_BI)
handleClmStrategyHarvest(event, event.params.fee0, event.params.fee1, [])
}

export function handleClmStrategyHarvestRewards(event: CLMHarvestRewardsEvent): void {
handleClmStrategyHarvest(event, ZERO_BI, ZERO_BI, event.params.fees)
// TODO: handle output tokens and event.params.fees or remove this handler
handleClmStrategyHarvest(event, ZERO_BI, ZERO_BI, [])
}

function handleClmStrategyHarvest(
event: ethereum.Event,
compoundedAmount0: BigInt,
compoundedAmount1: BigInt,
collectedRewards: BigInt,
collectedRewards: Array<BigInt>,
): void {
let strategy = getClmStrategy(event.address)
let clm = getCLM(strategy.clm)
Expand Down Expand Up @@ -56,7 +57,7 @@ function handleClmStrategyHarvest(
harvest.rewardPoolTotalSupply = clmData.rewardPoolTotalSupply
harvest.token0ToNativePrice = clmData.token0ToNativePrice
harvest.token1ToNativePrice = clmData.token1ToNativePrice
harvest.rewardToNativePrice = clmData.rewardToNativePrice
harvest.rewardToNativePrices = clmData.rewardToNativePrices
harvest.nativeToUSDPrice = clmData.nativeToUSDPrice
harvest.save()
}
Expand All @@ -66,18 +67,19 @@ export function handleClmStrategyClaimedFees(event: CLMClaimedFeesEvent): void {
event,
event.params.feeAlt0.plus(event.params.feeMain0),
event.params.feeAlt1.plus(event.params.feeMain1),
ZERO_BI,
[],
)
}
export function handleClmStrategyClaimedRewards(event: CLMClaimedRewardsEvent): void {
handleClmStrategyFees(event, ZERO_BI, ZERO_BI, event.params.fees)
// TODO: handle output tokens and event.params.fees or remove this handler
handleClmStrategyFees(event, ZERO_BI, ZERO_BI, [])
}

function handleClmStrategyFees(
event: ethereum.Event,
collectedAmount0: BigInt,
collectedAmount1: BigInt,
collectedRewardAmount: BigInt,
collectedRewardAmounts: Array<BigInt>,
): void {
let strategy = getClmStrategy(event.address)
let clm = getCLM(strategy.clm)
Expand Down Expand Up @@ -106,10 +108,10 @@ function handleClmStrategyFees(
collect.underlyingAltAmount1 = clmData.token1PositionAltBalance
collect.collectedAmount0 = collectedAmount0
collect.collectedAmount1 = collectedAmount1
collect.collectedRewardAmount = collectedRewardAmount
collect.collectedRewardAmounts = collectedRewardAmounts
collect.token0ToNativePrice = clmData.token0ToNativePrice
collect.token1ToNativePrice = clmData.token1ToNativePrice
collect.rewardToNativePrice = clmData.rewardToNativePrice
collect.rewardToNativePrices = clmData.rewardToNativePrices
collect.nativeToUSDPrice = clmData.nativeToUSDPrice
collect.save()

Expand Down
8 changes: 4 additions & 4 deletions src/clm/entity/clm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export function getCLM(managerAddress: Bytes): CLM {

clm.underlyingToken0 = ADDRESS_ZERO
clm.underlyingToken1 = ADDRESS_ZERO
clm.rewardToken = getNullToken().id
clm.rewardTokens = []

clm.managerTotalSupply = ZERO_BI
clm.rewardPoolTotalSupply = ZERO_BI

clm.token0ToNativePrice = ZERO_BI
clm.token1ToNativePrice = ZERO_BI
clm.rewardToNativePrice = ZERO_BI
clm.rewardToNativePrices = []
clm.nativeToUSDPrice = ZERO_BI

clm.priceOfToken0InToken1 = ZERO_BI
Expand Down Expand Up @@ -102,7 +102,7 @@ export function getClmSnapshot(clm: CLM, timestamp: BigInt, period: BigInt): Clm

snapshot.token0ToNativePrice = ZERO_BI
snapshot.token1ToNativePrice = ZERO_BI
snapshot.rewardToNativePrice = ZERO_BI
snapshot.rewardToNativePrices = []
snapshot.nativeToUSDPrice = ZERO_BI

snapshot.priceOfToken0InToken1 = ZERO_BI
Expand All @@ -122,7 +122,7 @@ export function getClmSnapshot(clm: CLM, timestamp: BigInt, period: BigInt): Clm
snapshot.rewardPoolTotalSupply = previousSnapshot.rewardPoolTotalSupply
snapshot.token0ToNativePrice = previousSnapshot.token0ToNativePrice
snapshot.token1ToNativePrice = previousSnapshot.token1ToNativePrice
snapshot.rewardToNativePrice = previousSnapshot.rewardToNativePrice
snapshot.rewardToNativePrices = previousSnapshot.rewardToNativePrices
snapshot.nativeToUSDPrice = previousSnapshot.nativeToUSDPrice
snapshot.priceOfToken0InToken1 = previousSnapshot.priceOfToken0InToken1
snapshot.priceRangeMin1 = previousSnapshot.priceRangeMin1
Expand Down
Loading

0 comments on commit f836d04

Please sign in to comment.