-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename to core add templtae
- Loading branch information
Showing
7 changed files
with
143 additions
and
64 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
type UniswapFactory @entity { | ||
# factory address | ||
id: ID! | ||
id: ID! # factory address, checksummed | ||
pairCount: Int! | ||
txCount: BigInt! | ||
} | ||
|
||
type Token @entity { | ||
# token address | ||
id: ID! | ||
|
||
id: ID! # token address, lowercased | ||
decimals: BigInt! | ||
txCount: BigInt! | ||
|
||
pairsAsToken0: [Pair!]! @derivedFrom(field: "token0") | ||
pairsAsToken1: [Pair!]! @derivedFrom(field: "token1") | ||
mintsAsToken0: [Mint!]! @derivedFrom(field: "token0") | ||
mintsAsToken1: [Mint!]! @derivedFrom(field: "token1") | ||
} | ||
|
||
type Pair @entity { | ||
# pair address | ||
id: ID! | ||
|
||
# mirrored from the smart contract | ||
id: ID! # pair address, lowercased | ||
token0: Token! | ||
token1: Token! | ||
|
||
# creation stats | ||
createdAtTimestamp: BigInt! | ||
createdAtBlockNumber: BigInt! | ||
txCount: BigInt! | ||
|
||
mints: [Mint!]! @derivedFrom(field: "pair") | ||
} | ||
|
||
# stores for USD calculations | ||
type Bundle @entity { | ||
# always 1 | ||
id: ID! | ||
ethPrice: BigDecimal! # price of ETH usd | ||
type Mint @entity { | ||
id: ID! # transactionhash#logIndex | ||
timestamp: BigInt! | ||
blockNumber: BigInt! | ||
to: Bytes! | ||
pair: Pair! | ||
token0: Token! | ||
token1: Token! | ||
sender: Bytes! | ||
amount0: BigDecimal! | ||
amount1: BigDecimal! | ||
} | ||
|
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,61 @@ | ||
import { BigDecimal } from '@graphprotocol/graph-ts' | ||
import { log } from '@graphprotocol/graph-ts' | ||
|
||
import { Mint as MintEntity, Pair, Token, UniswapFactory } from '../types/schema' | ||
import { Burn, Mint, Swap, Sync } from '../types/templates/Pair/Pair' | ||
import { convertTokenToDecimal, FACTORY_ADDRESS, ONE_BI } from './helpers' | ||
|
||
export function handleMint(event: Mint): void { | ||
const block = event.block | ||
const transaction = event.transaction | ||
const mintId = transaction.hash.toHex() + '#' + event.logIndex.toString() | ||
|
||
const transactionTo = transaction.to | ||
|
||
if (transactionTo === null) { | ||
log.warning('Could not fetch transaction to address, skipping mint {}.', [mintId]) | ||
return | ||
} | ||
|
||
const uniswap = UniswapFactory.load(FACTORY_ADDRESS)! | ||
const pair = Pair.load(event.address.toHex())! | ||
const token0 = Token.load(pair.token0)! | ||
const token1 = Token.load(pair.token1)! | ||
|
||
const token0Amount = convertTokenToDecimal(event.params.amount0, token0.decimals) | ||
const token1Amount = convertTokenToDecimal(event.params.amount1, token1.decimals) | ||
|
||
token0.txCount = token0.txCount.plus(ONE_BI) | ||
token1.txCount = token1.txCount.plus(ONE_BI) | ||
pair.txCount = pair.txCount.plus(ONE_BI) | ||
uniswap.txCount = uniswap.txCount.plus(ONE_BI) | ||
|
||
token0.save() | ||
token1.save() | ||
pair.save() | ||
uniswap.save() | ||
|
||
const mint = new MintEntity(mintId) | ||
mint.timestamp = block.timestamp | ||
mint.blockNumber = block.number | ||
mint.to = transactionTo | ||
mint.pair = pair.id | ||
mint.token0 = token0.id | ||
mint.token1 = token1.id | ||
mint.sender = event.params.sender | ||
mint.amount0 = token0Amount as BigDecimal | ||
mint.amount1 = token1Amount as BigDecimal | ||
mint.save() | ||
} | ||
|
||
export function handleBurn(event: Burn): void { | ||
log.info('Burn event received for pair {}.', [event.address.toHex()]) | ||
} | ||
|
||
export function handleSwap(event: Swap): void { | ||
log.info('Swap event received for pair {}.', [event.address.toHex()]) | ||
} | ||
|
||
export function handleSync(event: Sync): void { | ||
log.info('Sync event received for pair {}.', [event.address.toHex()]) | ||
} |
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