Skip to content

Commit

Permalink
Merge pull request #153 from Uniswap/04-12-lint
Browse files Browse the repository at this point in the history
add linter
  • Loading branch information
mzywang authored Apr 23, 2024
2 parents 5245085 + 54bd428 commit 9d8a918
Show file tree
Hide file tree
Showing 12 changed files with 1,692 additions and 411 deletions.
5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

34 changes: 34 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('@uniswap/eslint-config/load')

module.exports = {
extends: ['@uniswap/eslint-config/node'],
rules: {
'import/no-unused-modules': 'off',
'@typescript-eslint/no-restricted-imports': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' },
],
'@typescript-eslint/no-this-alias': [
'error',
{
allowDestructuring: true, // Allow `const { props, state } = this`; false by default
allowedNames: [
'self', // Allow `const self= this`; `[]` by default
],
},
],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-types': [
'error',
{
types: {
// Allow BigInt (uppercase)
BigInt: false,
},
},
],
},
ignorePatterns: ['src/types/templates/*'],
}
88 changes: 68 additions & 20 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,84 @@ name: CI
on:
push:
branches:
- master
- main
pull_request:
branches:
- main

jobs:
test:
strategy:
matrix:
node: ['10.x', '12.x']
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
lint:
name: lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- name: Check out Git repository
uses: actions/checkout@v2
with:
node-version: ${{ matrix.node }}
ref: ${{ github.event.pull_request.head.ref || '' }}
token: ${{ secrets.github_token }}

- run: npm install -g yarn
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: https://registry.npmjs.org

- id: yarn-cache
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
yarn-
- name: Install dependencies
run: yarn install

- name: Lint
run: yarn run lint

- name: Commit lint fixes
if: github.event_name == 'pull_request'
run: |
git config --global user.name "${{ github.event.pull_request.user.login }}"
git config --global user.email "${{ github.event.pull_request.user.login }}@users.noreply.github.com"
if [ -z "$(git diff)" ]; then exit; fi
git commit -a -m "fix(lint): auto-fix [ci]"
git push
build:
needs: lint
name: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18.x'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
yarn-
- run: yarn
- name: Install dependencies
run: yarn install

- run: yarn codegen
- run: yarn build
- name: Build project
run: yarn build
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 120
"printWidth": 120,
"trailingComma": "all"
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"repository": "https://github.com/graphprotocol/uniswap-v2-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"lint": "eslint . --ext .ts --fix",
"build": "run-s codegen && graph build",
"buildonly": "graph build",
"deploy:alchemy": "graph deploy --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz",
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
"deploy-local": "graph deploy davekaj/uniswap --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy ianlapham/uniswap-v2-dev --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
Expand All @@ -17,8 +20,10 @@
"@graphprotocol/graph-ts": "^0.32.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"eslint": "^6.2.2",
"@uniswap/eslint-config": "^1.2.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^6.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
}
Expand Down
47 changes: 16 additions & 31 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* eslint-disable prefer-const */
import { BigInt, BigDecimal, store, Address } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt, store } from '@graphprotocol/graph-ts'

import {
Bundle,
Burn as BurnEvent,
Mint as MintEvent,
Pair,
Swap as SwapEvent,
Token,
UniswapFactory,
Transaction,
Mint as MintEvent,
Burn as BurnEvent,
Swap as SwapEvent,
Bundle,
UniswapFactory,
} from '../types/schema'
import { Pair as PairContract, Mint, Burn, Swap, Transfer, Sync } from '../types/templates/Pair/Pair'
import { updatePairDayData, updateTokenDayData, updateUniswapDayData, updatePairHourData } from './dayUpdates'
import { getEthPriceInUSD, findEthPerToken, getTrackedVolumeUSD, getTrackedLiquidityUSD } from './pricing'
import { convertTokenToDecimal, ADDRESS_ZERO, FACTORY_ADDRESS, ONE_BI, createUser, ZERO_BD, BI_18 } from './helpers'
import { Burn, Mint, Swap, Sync, Transfer } from '../types/templates/Pair/Pair'
import { updatePairDayData, updatePairHourData, updateTokenDayData, updateUniswapDayData } from './dayUpdates'
import { ADDRESS_ZERO, BI_18, convertTokenToDecimal, createUser, FACTORY_ADDRESS, ONE_BI, ZERO_BD } from './helpers'
import { findEthPerToken, getEthPriceInUSD, getTrackedLiquidityUSD, getTrackedVolumeUSD } from './pricing'

function isCompleteMint(mintId: string): boolean {
return MintEvent.load(mintId)!.sender !== null // sufficient checks
Expand All @@ -36,7 +37,6 @@ export function handleTransfer(event: Transfer): void {

// get pair and load contract
let pair = Pair.load(event.address.toHexString())!
let pairContract = PairContract.bind(event.address)

// liquidity token amount being transfered
let value = convertTokenToDecimal(event.params.value, BI_18)
Expand Down Expand Up @@ -66,10 +66,7 @@ export function handleTransfer(event: Transfer): void {
// this is to make sure all the mints are under the same transaction
if (mints.length === 0 || isCompleteMint(mints[mints.length - 1])) {
let mint = new MintEvent(
event.transaction.hash
.toHexString()
.concat('-')
.concat(BigInt.fromI32(mints.length).toString()),
event.transaction.hash.toHexString().concat('-').concat(BigInt.fromI32(mints.length).toString()),
)
mint.transaction = transaction.id
mint.pair = pair.id
Expand All @@ -95,10 +92,7 @@ export function handleTransfer(event: Transfer): void {
if (event.params.to.toHexString() == pair.id) {
let burns = transaction.burns
let burn = new BurnEvent(
event.transaction.hash
.toHexString()
.concat('-')
.concat(BigInt.fromI32(burns.length).toString()),
event.transaction.hash.toHexString().concat('-').concat(BigInt.fromI32(burns.length).toString()),
)
burn.transaction = transaction.id
burn.pair = pair.id
Expand Down Expand Up @@ -134,10 +128,7 @@ export function handleTransfer(event: Transfer): void {
burn = currentBurn as BurnEvent
} else {
burn = new BurnEvent(
event.transaction.hash
.toHexString()
.concat('-')
.concat(BigInt.fromI32(burns.length).toString()),
event.transaction.hash.toHexString().concat('-').concat(BigInt.fromI32(burns.length).toString()),
)
burn.transaction = transaction.id
burn.needsComplete = false
Expand All @@ -148,10 +139,7 @@ export function handleTransfer(event: Transfer): void {
}
} else {
burn = new BurnEvent(
event.transaction.hash
.toHexString()
.concat('-')
.concat(BigInt.fromI32(burns.length).toString()),
event.transaction.hash.toHexString().concat('-').concat(BigInt.fromI32(burns.length).toString()),
)
burn.transaction = transaction.id
burn.needsComplete = false
Expand Down Expand Up @@ -482,10 +470,7 @@ export function handleSwap(event: Swap): void {
}
let swaps = transaction.swaps
let swap = new SwapEvent(
event.transaction.hash
.toHexString()
.concat('-')
.concat(BigInt.fromI32(swaps.length).toString()),
event.transaction.hash.toHexString().concat('-').concat(BigInt.fromI32(swaps.length).toString()),
)

// update swap event
Expand Down
16 changes: 4 additions & 12 deletions src/mappings/dayUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable prefer-const */
import { BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'

import { Bundle, Pair, PairDayData, Token, TokenDayData, UniswapDayData, UniswapFactory } from '../types/schema'
import { PairHourData } from './../types/schema'
import { FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from './helpers'
Expand Down Expand Up @@ -32,10 +33,7 @@ export function updatePairDayData(event: ethereum.Event): PairDayData {
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
let dayStartTimestamp = dayID * 86400
let dayPairID = event.address
.toHexString()
.concat('-')
.concat(BigInt.fromI32(dayID).toString())
let dayPairID = event.address.toHexString().concat('-').concat(BigInt.fromI32(dayID).toString())
let pair = Pair.load(event.address.toHexString())!
let pairDayData = PairDayData.load(dayPairID)
if (pairDayData === null) {
Expand Down Expand Up @@ -64,10 +62,7 @@ export function updatePairHourData(event: ethereum.Event): PairHourData {
let timestamp = event.block.timestamp.toI32()
let hourIndex = timestamp / 3600 // get unique hour within unix history
let hourStartUnix = hourIndex * 3600 // want the rounded effect
let hourPairID = event.address
.toHexString()
.concat('-')
.concat(BigInt.fromI32(hourIndex).toString())
let hourPairID = event.address.toHexString().concat('-').concat(BigInt.fromI32(hourIndex).toString())
let pair = Pair.load(event.address.toHexString())!
let pairHourData = PairHourData.load(hourPairID)
if (pairHourData === null) {
Expand Down Expand Up @@ -95,10 +90,7 @@ export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDa
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
let dayStartTimestamp = dayID * 86400
let tokenDayID = token.id
.toString()
.concat('-')
.concat(BigInt.fromI32(dayID).toString())
let tokenDayID = token.id.toString().concat('-').concat(BigInt.fromI32(dayID).toString())

let tokenDayData = TokenDayData.load(tokenDayID)
if (tokenDayData === null) {
Expand Down
3 changes: 2 additions & 1 deletion src/mappings/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable prefer-const */
import { log } from '@graphprotocol/graph-ts'

import { PairCreated } from '../types/Factory/Factory'
import { Bundle, Pair, Token, UniswapFactory } from '../types/schema'
import { Pair as PairTemplate } from '../types/templates'
Expand All @@ -10,7 +11,7 @@ import {
fetchTokenSymbol,
fetchTokenTotalSupply,
ZERO_BD,
ZERO_BI
ZERO_BI,
} from './helpers'

export function handleNewPair(event: PairCreated): void {
Expand Down
7 changes: 4 additions & 3 deletions src/mappings/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable prefer-const */
import { log, BigInt, BigDecimal, Address, ethereum } from '@graphprotocol/graph-ts'
import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts'

import { ERC20 } from '../types/Factory/ERC20'
import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes'
import { ERC20NameBytes } from '../types/Factory/ERC20NameBytes'
import { User, Bundle, Token, Pair } from '../types/schema'
import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes'
import { User } from '../types/schema'
import { Factory as FactoryContract } from '../types/templates/Pair/Factory'
import { TokenDefinition } from './tokenDefinition'

Expand Down
Loading

0 comments on commit 9d8a918

Please sign in to comment.