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

feat(v2-sdk): separate esm / cjs builds #222

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 deletions sdks/router-sdk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"extends": [
"prettier",
"prettier/@typescript-eslint"
],
"ignorePatterns": ["dist/**"]
}
12 changes: 12 additions & 0 deletions sdks/router-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: 'src',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.base.json'
}
}
};

41 changes: 27 additions & 14 deletions sdks/router-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
"ethereum"
],
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/src/index.js",
"types": "./dist/types/src/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsdx build",
"lint": "tsdx lint src",
"release": "semantic-release",
"start": "tsdx watch",
"test": "tsdx test"
"clean": "rm -rf dist",
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:types": "tsc -p tsconfig.types.json",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"test": "jest"
},
"dependencies": {
"@ethersproject/abi": "^5.5.0",
Expand All @@ -29,18 +33,27 @@
},
"devDependencies": {
"@types/jest": "^24.0.25",
"prettier": "^2.4.1",
"tsdx": "^0.14.1"
},
"prettier": {
"printWidth": 120,
"semi": false,
"singleQuote": true
"@typescript-eslint/eslint-plugin": "^5.62",
"@typescript-eslint/parser": "^5.62",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"jest": "25.5.0",
"prettier": "^2.4.1"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"exports": {
".": {
"types": "./dist/types/src/index.d.ts",
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
}
},
"release": {
"extends": "semantic-release-monorepo",
"branches": [
Expand Down
18 changes: 18 additions & 0 deletions sdks/router-sdk/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"include": ["src"],
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"target": "es6",
"module": "esnext",
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"skipLibCheck": true,
"isolatedModules": true
}
}
7 changes: 7 additions & 0 deletions sdks/router-sdk/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs"
}
}
7 changes: 7 additions & 0 deletions sdks/router-sdk/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/esm"
}
}
24 changes: 0 additions & 24 deletions sdks/router-sdk/tsconfig.json

This file was deleted.

8 changes: 8 additions & 0 deletions sdks/router-sdk/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist/types"
}
}
14 changes: 14 additions & 0 deletions sdks/v2-sdk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
}
}
60 changes: 50 additions & 10 deletions sdks/v2-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,48 @@
"ethereum"
],
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"module": "dist/v2-sdk.esm.js",
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/src/index.js",
"types": "./dist/types/src/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=10"
},
"scripts": {
"build": "tsdx build",
"lint": "tsdx lint src",
"release": "semantic-release",
"start": "tsdx watch",
"test": "tsdx test"
"clean": "rm -rf dist",
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:types": "tsc -p tsconfig.types.json",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"test": "jest"
},
"dependencies": {
"@ethersproject/address": "^5.0.2",
"@ethersproject/solidity": "^5.0.9",
"@typescript-eslint/eslint-plugin": "8.18.1",
"@uniswap/sdk-core": "^6.0.0",
"eslint-config-prettier": "9.1.0",
"prettier": "3.4.2",
"tiny-invariant": "^1.1.0",
"tiny-warning": "^1.0.3"
},
"devDependencies": {
"@types/big.js": "^4.0.5",
"@types/jest": "^24.0.25",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@uniswap/v2-core": "^1.0.1",
"eslint-config-react-app": "7.0.1",
"tsdx": "^0.14.1"
"eslint": "^8.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.0.0",
"prettier": "^3.0.0",
"ts-jest": "^29.0.0",
"typescript": "^4.3.3"
},
"prettier": {
"printWidth": 120,
Expand Down Expand Up @@ -74,5 +87,32 @@
}
]
]
},
"exports": {
".": {
"types": "./dist/types/src/index.d.ts",
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
}
},
"sideEffects": false,
"jest": {
"transform": {
"^.+\\.(t|j)sx?$": [
"ts-jest",
{
"tsconfig": "tsconfig.test.json"
}
]
},
"testEnvironment": "node",
"extensionsToTreatAsEsm": [
".ts"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"testRegex": ".*\\.test\\.ts$",
"rootDir": "src"
}
}
6 changes: 3 additions & 3 deletions sdks/v2-sdk/src/constants.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { INIT_CODE_HASH } from './constants'

import { bytecode } from '@uniswap/v2-core/build/UniswapV2Pair.json'
import { keccak256 } from '@ethersproject/solidity'
import { bytecode } from '@uniswap/v2-core/build/UniswapV2Pair.json'

import { INIT_CODE_HASH } from './constants'

// this _could_ go in constants, except that it would cost every consumer of the sdk the CPU to compute the hash
// and load the JSON.
Expand Down
29 changes: 16 additions & 13 deletions sdks/v2-sdk/src/entities/entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WETH9 as _WETH9, CurrencyAmount, Token, TradeType } from '@uniswap/sdk-core'
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { WETH9 as _WETH9, TradeType, Token, CurrencyAmount } from '@uniswap/sdk-core'

import { Pair, Route, Trade } from '../index'

const ADDRESSES = [
Expand Down Expand Up @@ -33,15 +34,15 @@ describe('entities', () => {
pairs = [
new Pair(
CurrencyAmount.fromRawAmount(tokens[0], decimalize(1, tokens[0].decimals)),
CurrencyAmount.fromRawAmount(tokens[1], decimalize(1, tokens[1].decimals))
CurrencyAmount.fromRawAmount(tokens[1], decimalize(1, tokens[1].decimals)),
),
new Pair(
CurrencyAmount.fromRawAmount(tokens[1], decimalize(1, tokens[1].decimals)),
CurrencyAmount.fromRawAmount(tokens[2], decimalize(1, tokens[2].decimals))
CurrencyAmount.fromRawAmount(tokens[2], decimalize(1, tokens[2].decimals)),
),
new Pair(
CurrencyAmount.fromRawAmount(tokens[2], decimalize(1, tokens[2].decimals)),
CurrencyAmount.fromRawAmount(WETH9, decimalize(1234, WETH9.decimals))
CurrencyAmount.fromRawAmount(WETH9, decimalize(1234, WETH9.decimals)),
),
]
})
Expand All @@ -59,13 +60,15 @@ describe('entities', () => {
invariant(route.input.isToken)
invariant(route.output.isToken)
expect(
route.midPrice.quote(CurrencyAmount.fromRawAmount(route.input, decimalize(1, route.input.decimals))).toExact()
route.midPrice
.quote(CurrencyAmount.fromRawAmount(route.input, decimalize(1, route.input.decimals)))
.toExact(),
).toEqual(CurrencyAmount.fromRawAmount(route.output, decimalize(1234, route.output.decimals)).toExact())
expect(
route.midPrice
.invert()
.quote(CurrencyAmount.fromRawAmount(route.output, decimalize(1234, route.output.decimals)))
.toExact()
.toExact(),
).toEqual(CurrencyAmount.fromRawAmount(route.input, decimalize(1, route.input.decimals)).toExact())

expect(route.midPrice.invert().toSignificant(5)).toEqual('0.00081037')
Expand All @@ -80,11 +83,11 @@ describe('entities', () => {
[
new Pair(
CurrencyAmount.fromRawAmount(tokens[1], decimalize(5, tokens[1].decimals)),
CurrencyAmount.fromRawAmount(WETH9, decimalize(10, WETH9.decimals))
CurrencyAmount.fromRawAmount(WETH9, decimalize(10, WETH9.decimals)),
),
],
tokens[1],
WETH9
WETH9,
)
const inputAmount = CurrencyAmount.fromRawAmount(tokens[1], decimalize(1, tokens[1].decimals))
const expectedOutputAmount = CurrencyAmount.fromRawAmount(WETH9, '1662497915624478906')
Expand Down Expand Up @@ -129,19 +132,19 @@ describe('entities', () => {
WETH9,
JSBI.add(
decimalize(10, WETH9.decimals),
tokens[1].decimals === 9 ? JSBI.BigInt('30090280812437312') : JSBI.BigInt('30090270812437322')
)
)
tokens[1].decimals === 9 ? JSBI.BigInt('30090280812437312') : JSBI.BigInt('30090270812437322'),
),
),
),
],
tokens[1],
WETH9
WETH9,
)
const outputAmount = CurrencyAmount.fromRawAmount(tokens[1], '1')
const trade = new Trade(route, outputAmount, TradeType.EXACT_INPUT)

expect(trade.priceImpact.toSignificant(18)).toEqual(
tokens[1].decimals === 9 ? '0.300000099400899902' : '0.3000000000000001'
tokens[1].decimals === 9 ? '0.300000099400899902' : '0.3000000000000001',
)
}
})
Expand Down
Loading
Loading