Skip to content

Commit

Permalink
Refactor core (Uniswap#58)
Browse files Browse the repository at this point in the history
* fix module reference

* modernize v2-sdk
  • Loading branch information
moodysalem authored Mar 5, 2021
1 parent 473ffb0 commit 221db31
Show file tree
Hide file tree
Showing 31 changed files with 2,474 additions and 2,693 deletions.
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"uniswap",
"ethereum"
],
"module": "dist/sdk.esm.js",
"module": "dist/v2-sdk.esm.js",
"scripts": {
"lint": "tsdx lint src test",
"build": "tsdx build",
Expand All @@ -22,20 +22,18 @@
"prepublishOnly": "tsdx build"
},
"dependencies": {
"@uniswap/v2-core": "^1.0.0",
"big.js": "^5.2.2",
"decimal.js-light": "^2.5.0",
"jsbi": "^3.1.1",
"@uniswap/sdk-core": "^1.0.6",
"tiny-invariant": "^1.1.0",
"tiny-warning": "^1.0.3",
"toformat": "^2.0.0"
"tiny-warning": "^1.0.3"
},
"peerDependencies": {
"@ethersproject/address": "^5.0.0-beta",
"@ethersproject/contracts": "^5.0.0-beta",
"@ethersproject/networks": "^5.0.0-beta",
"@ethersproject/providers": "^5.0.0-beta",
"@ethersproject/solidity": "^5.0.0-beta"
"@ethersproject/address": "^5.0.0",
"@ethersproject/contracts": "^5.0.0"
},
"optionalDependencies": {
"@uniswap/v2-core": "^1.0.1",
"@ethersproject/networks": "^5.0.2",
"@ethersproject/providers": "^5.0.5"
},
"devDependencies": {
"@ethersproject/address": "^5.0.2",
Expand All @@ -45,8 +43,8 @@
"@ethersproject/solidity": "^5.0.2",
"@types/big.js": "^4.0.5",
"@types/jest": "^24.0.25",
"babel-plugin-transform-jsbi-to-bigint": "^1.3.1",
"tsdx": "^0.12.3"
"@uniswap/v2-core": "^1.0.1",
"tsdx": "^0.14.1"
},
"engines": {
"node": ">=10"
Expand Down
2 changes: 1 addition & 1 deletion test/constants.test.ts → src/constants.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INIT_CODE_HASH } from '../src/constants'
import { INIT_CODE_HASH } from './constants'

import { bytecode } from '@uniswap/v2-core/build/UniswapV2Pair.json'
import { keccak256 } from '@ethersproject/solidity'
Expand Down
37 changes: 0 additions & 37 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,13 @@
import JSBI from 'jsbi'

// exports for external consumption
export type BigintIsh = JSBI | bigint | string

export enum ChainId {
MAINNET = 1,
ROPSTEN = 3,
RINKEBY = 4,
GÖRLI = 5,
KOVAN = 42
}

export enum TradeType {
EXACT_INPUT,
EXACT_OUTPUT
}

export enum Rounding {
ROUND_DOWN,
ROUND_HALF_UP,
ROUND_UP
}

export const FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'

export const INIT_CODE_HASH = '0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'

export const MINIMUM_LIQUIDITY = JSBI.BigInt(1000)

// exports for internal consumption
export const ZERO = JSBI.BigInt(0)
export const ONE = JSBI.BigInt(1)
export const TWO = JSBI.BigInt(2)
export const THREE = JSBI.BigInt(3)
export const FIVE = JSBI.BigInt(5)
export const TEN = JSBI.BigInt(10)
export const _100 = JSBI.BigInt(100)
export const _997 = JSBI.BigInt(997)
export const _1000 = JSBI.BigInt(1000)

export enum SolidityType {
uint8 = 'uint8',
uint256 = 'uint256'
}

export const SOLIDITY_TYPE_MAXIMA = {
[SolidityType.uint8]: JSBI.BigInt('0xff'),
[SolidityType.uint256]: JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
}
3 changes: 2 additions & 1 deletion test/data.test.ts → src/data.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChainId, WETH, Token, Fetcher } from '../src'
import { ChainId, WETH, Token } from '@uniswap/sdk-core'
import { Fetcher } from './fetcher'

// TODO: replace the provider in these tests
describe.skip('data', () => {
Expand Down
1 change: 0 additions & 1 deletion src/declarations.d.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/entities/currency.ts

This file was deleted.

14 changes: 9 additions & 5 deletions test/entities.test.ts → src/entities/entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import JSBI from 'jsbi'
import invariant from 'tiny-invariant'
import { ChainId, WETH as _WETH, TradeType, Rounding, Token, TokenAmount, Pair, Route, Trade } from '../src'
import { ChainId, WETH as _WETH, TradeType, Rounding, Token, TokenAmount } from '@uniswap/sdk-core'
import { Pair, Route, Trade } from '../index'

const ADDRESSES = [
'0x0000000000000000000000000000000000000001',
Expand All @@ -14,8 +16,8 @@ const DECIMAL_PERMUTATIONS: [number, number, number][] = [
[18, 18, 18]
]

function decimalize(amount: number, decimals: number): bigint {
return BigInt(amount) * BigInt(10) ** BigInt(decimals)
function decimalize(amount: number, decimals: number): JSBI {
return JSBI.multiply(JSBI.BigInt(amount), JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(decimals)))
}

describe('entities', () => {
Expand Down Expand Up @@ -156,8 +158,10 @@ describe('entities', () => {
new TokenAmount(tokens[1], decimalize(1, tokens[1].decimals)),
new TokenAmount(
WETH,
decimalize(10, WETH.decimals) +
(tokens[1].decimals === 9 ? BigInt('30090280812437312') : BigInt('30090270812437322'))
JSBI.add(
decimalize(10, WETH.decimals),
tokens[1].decimals === 9 ? JSBI.BigInt('30090280812437312') : JSBI.BigInt('30090270812437322')
)
)
)
],
Expand Down
69 changes: 0 additions & 69 deletions src/entities/fractions/currencyAmount.ts

This file was deleted.

Loading

0 comments on commit 221db31

Please sign in to comment.