Skip to content

Commit

Permalink
add typechain gen scripts (#36)
Browse files Browse the repository at this point in the history
add typechain generation for core/periphery contracts
  • Loading branch information
JFrankfurt committed Mar 30, 2021
1 parent 878fc9c commit c0ce6a5
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,5 +1,8 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# generated contract types
/src/types/v3

# dependencies
/node_modules

Expand Down
31 changes: 17 additions & 14 deletions package.json
Expand Up @@ -20,6 +20,7 @@
"@storybook/react": "^6.1.17",
"@storybook/theming": "^6.1.17",
"@styled-system/css": "^5.1.5",
"@typechain/ethers-v5": "^6.0.5",
"@types/jest": "^25.2.1",
"@types/lodash.flatmap": "^4.5.6",
"@types/luxon": "^1.24.4",
Expand All @@ -36,15 +37,19 @@
"@types/styled-components": "^5.1.0",
"@types/testing-library__cypress": "^5.0.5",
"@types/wcag-contrast": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"@uniswap/default-token-list": "^2.0.0",
"@uniswap/governance": "^1.0.2",
"@uniswap/liquidity-staker": "^1.0.2",
"@uniswap/merkle-distributor": "1.0.1",
"@uniswap/sdk-core": "^1.0.8",
"@uniswap/token-lists": "^1.0.0-beta.19",
"@uniswap/v2-core": "1.0.0",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"@uniswap/v3-periphery": "^1.0.0-beta.7",
"@uniswap/v2-sdk": "^1.0.6",
"@uniswap/v3-core": "^1.0.0-rc.0",
"@uniswap/v3-periphery": "^1.0.0-beta.11",
"@web3-react/core": "^6.0.9",
"@web3-react/fortmatic-connector": "^6.0.9",
"@web3-react/injected-connector": "^6.0.7",
Expand All @@ -67,6 +72,7 @@
"i18next-xhr-backend": "^2.0.1",
"inter-ui": "^3.13.1",
"jazzicon": "^1.5.0",
"lightweight-charts": "^3.3.0",
"lodash.flatmap": "^4.5.0",
"luxon": "^1.25.0",
"multicodec": "^2.0.0",
Expand Down Expand Up @@ -97,7 +103,8 @@
"start-server-and-test": "^1.11.0",
"styled-components": "^4.2.0",
"styled-system": "^5.1.5",
"typescript": "^3.8.3",
"typechain": "^4.0.3",
"typescript": "^4.2.3",
"use-count-up": "^2.2.5",
"wcag-contrast": "^3.0.0",
"workbox-core": "^6.1.0",
Expand All @@ -110,11 +117,13 @@
"@walletconnect/web3-provider": "1.1.1-alpha.0"
},
"scripts": {
"start": "react-scripts start",
"start:service-worker": "yarn build && yarn serve -s build",
"build": "react-scripts build",
"compile-contract-types": "npx typechain --target ethers-v5 --outDir src/types/v3 './node_modules/@uniswap/?(v3-core|v3-periphery)/artifacts/contracts/**/*.json'",
"build": "yarn compile-contract-types && react-scripts build",
"eject": "react-scripts eject",
"integration-test": "start-server-and-test 'serve build -l 3000' http://localhost:3000 'cypress run'",
"postinstall": "yarn compile-contract-types",
"start": "yarn compile-contract-types && react-scripts start",
"start:service-worker": "yarn build && yarn serve -s build",
"storybook": "start-storybook -p 6006",
"test": "react-scripts test --env=jsdom"
},
Expand All @@ -136,11 +145,5 @@
"last 1 safari version"
]
},
"license": "GPL-3.0-or-later",
"dependencies": {
"@uniswap/default-token-list": "^2.0.0",
"@uniswap/sdk-core": "^1.0.8",
"@uniswap/v2-sdk": "^1.0.6",
"lightweight-charts": "^3.3.0"
}
"license": "GPL-3.0-or-later"
}
2 changes: 1 addition & 1 deletion src/components/Modal/index.tsx
Expand Up @@ -128,7 +128,7 @@ export default function Modal({
{...(isMobile
? {
...bind(),
style: { transform: y.interpolate((y) => `translateY(${y > 0 ? y : 0}px)`) },
style: { transform: y.interpolate((y) => `translateY(${(y as number) > 0 ? y : 0}px)`) },
}
: {})}
aria-label="dialog content"
Expand Down
2 changes: 1 addition & 1 deletion src/components/PositionList/index.tsx
Expand Up @@ -7,7 +7,7 @@ import { unwrappedToken } from 'utils/wrappedCurrency'
import styled, { keyframes } from 'styled-components'
import { Link } from 'react-router-dom'
import { MEDIA_WIDTHS } from 'theme'
import { Position } from 'types/v3'
import { Position } from 'types/position'

const ActiveDot = styled.span`
background-color: ${({ theme }) => theme.success};
Expand Down
2 changes: 1 addition & 1 deletion src/connectors/Fortmatic.ts
Expand Up @@ -27,7 +27,7 @@ export class FortmaticConnector extends FortmaticConnectorCore {

const provider = this.fortmatic.getProvider()

const pollForOverlayReady = new Promise((resolve) => {
const pollForOverlayReady = new Promise<void>((resolve) => {
const interval = setInterval(() => {
if (provider.overlayReady) {
clearInterval(interval)
Expand Down
14 changes: 6 additions & 8 deletions src/connectors/NetworkConnector.ts
Expand Up @@ -89,14 +89,12 @@ class MiniRpcProvider implements AsyncSendable {
reject,
request: { method },
} = byKey[result.id]
if (resolve && reject) {
if ('error' in result) {
reject(new RequestError(result?.error?.message, result?.error?.code, result?.error?.data))
} else if ('result' in result) {
resolve(result.result)
} else {
reject(new RequestError(`Received unexpected JSON-RPC response to ${method} request.`, -32000, result))
}
if ('error' in result) {
reject(new RequestError(result?.error?.message, result?.error?.code, result?.error?.data))
} else if ('result' in result && resolve) {
resolve(result.result)
} else {
reject(new RequestError(`Received unexpected JSON-RPC response to ${method} request.`, -32000, result))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useContract.ts
Expand Up @@ -8,7 +8,7 @@ import { abi as IUniswapV2PairABI } from '@uniswap/v2-core/build/IUniswapV2Pair.
import { abi as NFTPositionManagerABI } from '@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json'
import { NONFUNGIBLE_POSITION_MANAGER_ADDRESSES } from 'constants/v3'
import { useMemo } from 'react'
import { NonfungiblePositionManager } from 'types/v3/contracts/NonfungiblePositionManager'
import { NonfungiblePositionManager } from 'types/v3/NonfungiblePositionManager'
import { GOVERNANCE_ADDRESS, MERKLE_DISTRIBUTOR_ADDRESS, UNI } from '../constants'
import {
ARGENT_WALLET_DETECTOR_ABI,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useV3PositionManager.ts
@@ -1,5 +1,5 @@
import { OptionalMethodInputs, useSingleCallResult, useSingleContractMultipleData } from 'state/multicall/hooks'
import { Position } from 'types/v3'
import { Position } from 'types/position'
import { useV3NFTPositionManagerContract } from './useContract'

interface UseV3PositionsResults {
Expand Down
22 changes: 14 additions & 8 deletions src/state/mint/reducer.test.ts
@@ -1,28 +1,34 @@
import { createStore, Store } from 'redux'

import { Field, typeInput } from './actions'
import reducer, { MintState } from './reducer'
import reducer, { initialState, MintState } from './reducer'

describe('mint reducer', () => {
let store: Store<MintState>

beforeEach(() => {
store = createStore(reducer, {
independentField: Field.CURRENCY_A,
typedValue: '',
otherTypedValue: '',
})
store = createStore(reducer, initialState)
})

describe('typeInput', () => {
it('sets typed value', () => {
store.dispatch(typeInput({ field: Field.CURRENCY_A, typedValue: '1.0', noLiquidity: false }))
expect(store.getState()).toEqual({ independentField: Field.CURRENCY_A, typedValue: '1.0', otherTypedValue: '' })
expect(store.getState()).toEqual({
...initialState,
independentField: Field.CURRENCY_A,
typedValue: '1.0',
otherTypedValue: '',
})
})
it('clears other value', () => {
store.dispatch(typeInput({ field: Field.CURRENCY_A, typedValue: '1.0', noLiquidity: false }))
store.dispatch(typeInput({ field: Field.CURRENCY_B, typedValue: '1.0', noLiquidity: false }))
expect(store.getState()).toEqual({ independentField: Field.CURRENCY_B, typedValue: '1.0', otherTypedValue: '' })
expect(store.getState()).toEqual({
...initialState,
independentField: Field.CURRENCY_B,
typedValue: '1.0',
otherTypedValue: '',
})
})
})
})
2 changes: 1 addition & 1 deletion src/state/mint/reducer.ts
Expand Up @@ -18,7 +18,7 @@ export interface MintState {
readonly rangeType: RangeType
}

const initialState: MintState = {
export const initialState: MintState = {
independentField: Field.CURRENCY_A,
typedValue: '',
otherTypedValue: '',
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions src/types/v3/contracts/NonfungiblePositionManager.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -19,7 +19,7 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react",
"jsx": "react-jsx",
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"types": ["react-spring", "jest"],
Expand Down

0 comments on commit c0ce6a5

Please sign in to comment.