-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* split core handlers * remove yarn codegen from CI * update export * fix(lint): auto-fix [ci] * add collect event handler * remove double count * remove burn * remove burn * add comment * add linear ticket * remove unused comment * lint * update transaction ids to use log index * fix(lint): auto-fix [ci] --------- Co-authored-by: mzywang <[email protected]>
- Loading branch information
Showing
8 changed files
with
117 additions
and
27 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { BigInt } from '@graphprotocol/graph-ts' | ||
|
||
import { Bundle, Collect, Factory, Pool, Token } from '../../types/schema' | ||
import { Collect as CollectEvent } from '../../types/templates/Pool/Pool' | ||
import { convertTokenToDecimal, loadTransaction } from '../../utils' | ||
import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' | ||
import { | ||
updatePoolDayData, | ||
updatePoolHourData, | ||
updateTokenDayData, | ||
updateTokenHourData, | ||
updateUniswapDayData, | ||
} from '../../utils/intervalUpdates' | ||
import { getTrackedAmountUSD } from '../../utils/pricing' | ||
|
||
export function handleCollect(event: CollectEvent): void { | ||
const bundle = Bundle.load('1')! | ||
const pool = Pool.load(event.address.toHexString()) | ||
if (pool == null) { | ||
return | ||
} | ||
const transaction = loadTransaction(event) | ||
const factory = Factory.load(FACTORY_ADDRESS)! | ||
|
||
const token0 = Token.load(pool.token0) | ||
const token1 = Token.load(pool.token1) | ||
if (token0 == null || token1 == null) { | ||
return | ||
} | ||
|
||
// Get formatted amounts collected. | ||
const collectedAmountToken0 = convertTokenToDecimal(event.params.amount0, token0.decimals) | ||
const collectedAmountToken1 = convertTokenToDecimal(event.params.amount1, token1.decimals) | ||
const trackedCollectedAmountUSD = getTrackedAmountUSD( | ||
collectedAmountToken0, | ||
token0 as Token, | ||
collectedAmountToken1, | ||
token1 as Token | ||
) | ||
|
||
// Reset tvl aggregates until new amounts calculated | ||
factory.totalValueLockedETH = factory.totalValueLockedETH.minus(pool.totalValueLockedETH) | ||
|
||
// Update globals | ||
factory.txCount = factory.txCount.plus(ONE_BI) | ||
|
||
// update token data | ||
token0.txCount = token0.txCount.plus(ONE_BI) | ||
token0.totalValueLocked = token0.totalValueLocked.minus(collectedAmountToken0) | ||
token0.totalValueLockedUSD = token0.totalValueLocked.times(token0.derivedETH.times(bundle.ethPriceUSD)) | ||
|
||
token1.txCount = token1.txCount.plus(ONE_BI) | ||
token1.totalValueLocked = token1.totalValueLocked.minus(collectedAmountToken1) | ||
token1.totalValueLockedUSD = token1.totalValueLocked.times(token1.derivedETH.times(bundle.ethPriceUSD)) | ||
|
||
// Adjust pool TVL based on amount collected. | ||
pool.txCount = pool.txCount.plus(ONE_BI) | ||
pool.totalValueLockedToken0 = pool.totalValueLockedToken0.minus(collectedAmountToken0) | ||
pool.totalValueLockedToken1 = pool.totalValueLockedToken1.minus(collectedAmountToken1) | ||
pool.totalValueLockedETH = pool.totalValueLockedToken0 | ||
.times(token0.derivedETH) | ||
.plus(pool.totalValueLockedToken1.times(token1.derivedETH)) | ||
pool.totalValueLockedUSD = pool.totalValueLockedETH.times(bundle.ethPriceUSD) | ||
|
||
// Update aggregate fee collection values. | ||
pool.collectedFeesToken0 = pool.collectedFeesToken0.plus(collectedAmountToken0) | ||
pool.collectedFeesToken1 = pool.collectedFeesToken1.plus(collectedAmountToken1) | ||
pool.collectedFeesUSD = pool.collectedFeesUSD.plus(trackedCollectedAmountUSD) | ||
|
||
// reset aggregates with new amounts | ||
factory.totalValueLockedETH = factory.totalValueLockedETH.plus(pool.totalValueLockedETH) | ||
factory.totalValueLockedUSD = factory.totalValueLockedETH.times(bundle.ethPriceUSD) | ||
|
||
const collect = new Collect(transaction.id + '-' + event.logIndex.toString()) | ||
collect.transaction = transaction.id | ||
collect.timestamp = event.block.timestamp | ||
collect.pool = pool.id | ||
collect.owner = event.params.owner | ||
collect.amount0 = collectedAmountToken0 | ||
collect.amount1 = collectedAmountToken1 | ||
collect.amountUSD = trackedCollectedAmountUSD | ||
collect.tickLower = BigInt.fromI32(event.params.tickLower) | ||
collect.tickUpper = BigInt.fromI32(event.params.tickUpper) | ||
collect.logIndex = event.logIndex | ||
|
||
updateUniswapDayData(event) | ||
updatePoolDayData(event) | ||
updatePoolHourData(event) | ||
updateTokenDayData(token0 as Token, event) | ||
updateTokenDayData(token1 as Token, event) | ||
updateTokenHourData(token0 as Token, event) | ||
updateTokenHourData(token1 as Token, event) | ||
|
||
token0.save() | ||
token1.save() | ||
factory.save() | ||
pool.save() | ||
collect.save() | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { handleBurn } from './burn' | ||
import { handleCollect } from './collect' | ||
import { handleInitialize } from './initialize' | ||
import { handleMint } from './mint' | ||
import { handleSwap } from './swap' | ||
|
||
export { handleBurn, handleInitialize, handleMint, handleSwap } | ||
export { handleBurn, handleCollect, handleInitialize, handleMint, handleSwap } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters