Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove sync #182

Draft
wants to merge 1 commit into
base: 12-04-minimal_mainnet_subgraph
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions src/mappings/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigDecimal } from '@graphprotocol/graph-ts'
import { log } from '@graphprotocol/graph-ts'

import { Burn as BurnEntity, Mint as MintEntity, Pair, Swap as SwapEntity, Token } from '../types/schema'
import { Burn, Mint, Swap, Sync } from '../types/templates/Pair/Pair'
import { Burn, Mint, Swap } from '../types/templates/Pair/Pair'
import { convertTokenToDecimal } from './helpers'

export function handleMint(event: Mint): void {
Expand Down Expand Up @@ -35,6 +35,11 @@ export function handleMint(event: Mint): void {
mint.amount0 = token0Amount as BigDecimal
mint.amount1 = token1Amount as BigDecimal
mint.save()

token0.totalLiquidity = token0.totalLiquidity.plus(token0Amount)
token1.totalLiquidity = token1.totalLiquidity.plus(token1Amount)
token0.save()
token1.save()
}

export function handleBurn(event: Burn): void {
Expand All @@ -60,6 +65,11 @@ export function handleBurn(event: Burn): void {
burn.amount1 = token1Amount as BigDecimal
burn.to = event.params.to
burn.save()

token0.totalLiquidity = token0.totalLiquidity.minus(token0Amount)
token1.totalLiquidity = token1.totalLiquidity.minus(token1Amount)
token0.save()
token1.save()
}

export function handleSwap(event: Swap): void {
Expand Down Expand Up @@ -89,25 +99,9 @@ export function handleSwap(event: Swap): void {
swap.amount1Out = token1AmountOut
swap.to = event.params.to
swap.save()
}

export function handleSync(event: Sync): void {
const pair = Pair.load(event.address.toHex())!
const token0 = Token.load(pair.token0)!
const token1 = Token.load(pair.token1)!

const reserve0 = convertTokenToDecimal(event.params.reserve0, token0.decimals)
const reserve1 = convertTokenToDecimal(event.params.reserve1, token1.decimals)

const oldReserve0 = pair.reserve0
const oldReserve1 = pair.reserve1

pair.reserve0 = reserve0
pair.reserve1 = reserve1
pair.save()

token0.totalLiquidity = token0.totalLiquidity.plus(reserve0.minus(oldReserve0))
token1.totalLiquidity = token1.totalLiquidity.plus(reserve1.minus(oldReserve1))
token0.totalLiquidity = token0.totalLiquidity.minus(token0AmountOut).plus(token0AmountIn)
token1.totalLiquidity = token1.totalLiquidity.minus(token1AmountOut).plus(token1AmountIn)
token0.save()
token1.save()
}
}
4 changes: 1 addition & 3 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@ templates:
- event: Burn(indexed address,uint256,uint256,indexed address)
handler: handleBurn
- event: Swap(indexed address,uint256,uint256,uint256,uint256,indexed address)
handler: handleSwap
- event: Sync(uint112,uint112)
handler: handleSync
handler: handleSwap