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

fix: update linter and github CI #212

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
}
}
]
}
}
47 changes: 38 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,44 @@ on:
branches:
- main
pull_request:
branches:
- main

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

runs-on: ubuntu-latest

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

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

runs-on: ${{ matrix.os }}
- name: Install dependencies
run: npm ci

- name: Lint
run: npm 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
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
Expand All @@ -22,7 +51,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
node-version: '18.x'

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -32,9 +61,9 @@ jobs:
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: ${{ matrix.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
key: yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ matrix.os }}-yarn-
yarn-

- name: Install dependencies
run: yarn install
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"repository": "https://github.com/graphprotocol/uniswap-v3-subgraph",
"license": "GPL-3.0-or-later",
"scripts": {
"lint": "eslint . --ext .ts --fix",
"codegen": "graph codegen --output-dir src/types/",
"build": "graph build",
"create-local": "graph create ianlapham/uniswap-v3 --node http://127.0.0.1:8020",
Expand All @@ -18,7 +19,8 @@
"@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",
"prettier": "^1.18.2",
"typescript": "^3.5.2"
Expand Down
20 changes: 6 additions & 14 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/* eslint-disable prefer-const */
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'

import { Bundle, Burn, Factory, Mint, Pool, Swap, Tick, Token } from '../types/schema'
import { Pool as PoolABI } from '../types/Factory/Pool'
import { BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'
import {
Burn as BurnEvent,
Flash as FlashEvent,
Initialize,
Mint as MintEvent,
Swap as SwapEvent
} from '../types/templates/Pool/Pool'
import { Burn as BurnEvent, Initialize, Mint as MintEvent, Swap as SwapEvent } from '../types/templates/Pool/Pool'
import { convertTokenToDecimal, loadTransaction, safeDiv } from '../utils'
import { FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from '../utils/constants'
import { findEthPerToken, getEthPriceInUSD, getTrackedAmountUSD, sqrtPriceX96ToTokenPrices } from '../utils/pricing'
import { FACTORY_ADDRESS, ONE_BI, ZERO_BD } from '../utils/constants'
import {
updatePoolDayData,
updatePoolHourData,
updateTokenDayData,
updateTokenHourData,
updateUniswapDayData
} from '../utils/intervalUpdates'
import { createTick, feeTierToTickSpacing } from '../utils/tick'
import { findEthPerToken, getEthPriceInUSD, getTrackedAmountUSD, sqrtPriceX96ToTokenPrices } from '../utils/pricing'
import { createTick } from '../utils/tick'

export function handleInitialize(event: Initialize): void {
// update pool sqrt price and tick
Expand Down Expand Up @@ -289,8 +283,6 @@ export function handleSwap(event: SwapEvent): void {
let token1 = Token.load(pool.token1)

if (token0 && token1) {
let oldTick = pool.tick

// amounts - 0/1 are token deltas: can be positive or negative
let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals)
let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals)
Expand Down
15 changes: 8 additions & 7 deletions src/mappings/factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { WHITELIST_TOKENS } from './../utils/pricing'
/* eslint-disable prefer-const */
import { FACTORY_ADDRESS, ZERO_BI, ONE_BI, ZERO_BD, ADDRESS_ZERO } from './../utils/constants'
import { Factory } from '../types/schema'
import { Address, BigInt, log } from '@graphprotocol/graph-ts'

import { PoolCreated } from '../types/Factory/Factory'
import { Pool, Token, Bundle } from '../types/schema'
import { Factory } from '../types/schema'
import { Bundle, Pool, Token } from '../types/schema'
import { Pool as PoolTemplate } from '../types/templates'
import { fetchTokenSymbol, fetchTokenName, fetchTokenTotalSupply, fetchTokenDecimals } from '../utils/token'
import { log, BigInt, Address } from '@graphprotocol/graph-ts'
import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../utils/token'
/* eslint-disable prefer-const */
import { ADDRESS_ZERO, FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from './../utils/constants'
import { WHITELIST_TOKENS } from './../utils/pricing'

export function handlePoolCreated(event: PoolCreated): void {
// temp fix
Expand Down
3 changes: 2 additions & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable prefer-const */
import { BigInt, BigDecimal, Address } from '@graphprotocol/graph-ts'
import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts'

import { Factory as FactoryContract } from '../types/templates/Pool/Factory'

export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'
Expand Down
5 changes: 3 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable prefer-const */
import { BigInt, BigDecimal, ethereum } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts'

import { Transaction } from '../types/schema'
import { ONE_BI, ZERO_BI, ZERO_BD, ONE_BD } from '../utils/constants'
import { ONE_BD, ONE_BI, ZERO_BD, ZERO_BI } from '../utils/constants'

export function exponentToBigDecimal(decimals: BigInt): BigDecimal {
let bd = BigDecimal.fromString('1')
Expand Down
32 changes: 10 additions & 22 deletions src/utils/intervalUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { ZERO_BD, ZERO_BI, ONE_BI } from './constants'
import { ethereum } from '@graphprotocol/graph-ts'

/* eslint-disable prefer-const */
import {
UniswapDayData,
Bundle,
Factory,
Pool,
PoolDayData,
PoolHourData,
Token,
TokenDayData,
TokenHourData,
Bundle,
PoolHourData,
Tick
UniswapDayData,
} from './../types/schema'
import { ONE_BI, ZERO_BD, ZERO_BI } from './constants'
import { FACTORY_ADDRESS } from './constants'
import { ethereum } from '@graphprotocol/graph-ts'

/**
* Tracks global aggregate data over daily windows
Expand Down Expand Up @@ -43,10 +43,7 @@ export function updatePoolDayData(event: ethereum.Event): PoolDayData {
let timestamp = event.block.timestamp.toI32()
let dayID = timestamp / 86400
let dayStartTimestamp = dayID * 86400
let dayPoolID = event.address
.toHexString()
.concat('-')
.concat(dayID.toString())
let dayPoolID = event.address.toHexString().concat('-').concat(dayID.toString())
let pool = Pool.load(event.address.toHexString())!
let poolDayData = PoolDayData.load(dayPoolID)
if (poolDayData === null) {
Expand Down Expand Up @@ -88,10 +85,7 @@ export function updatePoolHourData(event: ethereum.Event): PoolHourData {
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 hourPoolID = event.address
.toHexString()
.concat('-')
.concat(hourIndex.toString())
let hourPoolID = event.address.toHexString().concat('-').concat(hourIndex.toString())
let pool = Pool.load(event.address.toHexString())!
let poolHourData = PoolHourData.load(hourPoolID)
if (poolHourData === null) {
Expand Down Expand Up @@ -136,10 +130,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(dayID.toString())
let tokenDayID = token.id.toString().concat('-').concat(dayID.toString())
let tokenPrice = token.derivedETH.times(bundle.ethPriceUSD)

let tokenDayData = TokenDayData.load(tokenDayID)
Expand Down Expand Up @@ -179,10 +170,7 @@ export function updateTokenHourData(token: Token, event: ethereum.Event): TokenH
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 tokenHourID = token.id
.toString()
.concat('-')
.concat(hourIndex.toString())
let tokenHourID = token.id.toString().concat('-').concat(hourIndex.toString())
let tokenHourData = TokenHourData.load(tokenHourID)
let tokenPrice = token.derivedETH.times(bundle.ethPriceUSD)

Expand Down
5 changes: 3 additions & 2 deletions src/utils/pricing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable prefer-const */
import { ONE_BD, ZERO_BD, ZERO_BI } from './constants'
import { Bundle, Pool, Token } from './../types/schema'
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'

import { exponentToBigDecimal, safeDiv } from '../utils/index'
import { Bundle, Pool, Token } from './../types/schema'
import { ONE_BD, ZERO_BD, ZERO_BI } from './constants'

const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8'
Expand Down
6 changes: 3 additions & 3 deletions src/utils/staticTokenDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ export class StaticTokenDefinition {

// Helper for hardcoded tokens
static fromAddress(tokenAddress: Address): StaticTokenDefinition | null {
let staticDefinitions = this.getStaticDefinitions()
let tokenAddressHex = tokenAddress.toHexString()
const staticDefinitions = this.getStaticDefinitions()
const tokenAddressHex = tokenAddress.toHexString()

// Search the definition using the address
for (let i = 0; i < staticDefinitions.length; i++) {
let staticDefinition = staticDefinitions[i]
const staticDefinition = staticDefinitions[i]
if (staticDefinition.address.toHexString() == tokenAddressHex) {
return staticDefinition
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/tick.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable prefer-const */
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { bigDecimalExponated, safeDiv } from '.'

import { Tick } from '../types/schema'
import { Mint as MintEvent } from '../types/templates/Pool/Pool'
import { ONE_BD, ZERO_BD, ZERO_BI } from './constants'
import { bigDecimalExponated, safeDiv } from '.'
import { ONE_BD, ZERO_BI } from './constants'

export function createTick(tickId: string, tickIdx: i32, poolId: string, event: MintEvent): Tick {
let tick = new Tick(tickId)
Expand Down
7 changes: 4 additions & 3 deletions src/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable prefer-const */
import { Address, BigInt } from '@graphprotocol/graph-ts'

import { ERC20 } from '../types/Factory/ERC20'
import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes'
import { ERC20NameBytes } from '../types/Factory/ERC20NameBytes'
import { StaticTokenDefinition } from './staticTokenDefinition'
import { BigInt, Address } from '@graphprotocol/graph-ts'
import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes'
import { isNullEthValue } from '.'
import { StaticTokenDefinition } from './staticTokenDefinition'

export function fetchTokenSymbol(tokenAddress: Address): string {
let contract = ERC20.bind(tokenAddress)
Expand Down
7 changes: 1 addition & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
{
"extends": "@graphprotocol/graph-ts/tsconfig",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was giving my IDE an error and didn't seem like it was doing anything, so I made this empty

"compilerOptions": {
"types": ["@graphprotocol/graph-ts"]
}
}
{}
Loading
Loading