Skip to content

Commit

Permalink
feat(exchange): Support testnet switch (#4295)
Browse files Browse the repository at this point in the history
* feat(exchange): Support testnet switch

* fix token test

* hide menu when chain not support

* rename mainnet to bsc

* WETH -> WNATIVE

* typo

* fix warning token

* snapshot update

* chart support

* add swap sdk

* add sdk in next config

* fix test

* add default provider back

* signMessage hook

* fix build
  • Loading branch information
0xjojoex authored Jul 26, 2022
1 parent 5a52154 commit e159183
Show file tree
Hide file tree
Showing 156 changed files with 6,620 additions and 2,296 deletions.
11 changes: 0 additions & 11 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
NEXT_PUBLIC_CHAIN_ID = "56"
NEXT_PUBLIC_GTAG = "GTM-PXLD3XW"

# 10+ nodes balanced, US/EU
NEXT_PUBLIC_NODE_1 = "https://bsc-dataseed1.ninicoin.io"

# 10+ nodes balanced, US/EU
NEXT_PUBLIC_NODE_2 = "https://bsc-dataseed1.defibit.io"

# 10+ nodes balanced in each region, global
NEXT_PUBLIC_NODE_3 = "https://bsc-dataseed.binance.org"

NEXT_PUBLIC_NODE_PRODUCTION = "https://nodes.pancakeswap.com"

NEXT_PUBLIC_GRAPH_API_PROFILE = "https://api.thegraph.com/subgraphs/name/pancakeswap/profile"
NEXT_PUBLIC_GRAPH_API_PREDICTION_BNB = "https://api.thegraph.com/subgraphs/name/pancakeswap/prediction-v2"
Expand Down
13 changes: 0 additions & 13 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
NEXT_PUBLIC_CHAIN_ID = "56"
NEXT_PUBLIC_GTAG = "GTM-TLF66T4"

# 10+ nodes balanced, US/EU
NEXT_PUBLIC_NODE_1 = "https://bsc-dataseed1.ninicoin.io"

# 10+ nodes balanced, US/EU
NEXT_PUBLIC_NODE_2 = "https://bsc-dataseed1.defibit.io"

# 10+ nodes balanced in each region, global
NEXT_PUBLIC_NODE_3 = "https://bsc-dataseed.binance.org"

# Google Cloud Infrastructure Endpoint - Global
NEXT_PUBLIC_NODE_PRODUCTION = "https://nodes.pancakeswap.com"

NEXT_PUBLIC_GRAPH_API_PROFILE = "https://api.thegraph.com/subgraphs/name/pancakeswap/profile"
NEXT_PUBLIC_GRAPH_API_PREDICTION_BNB = "https://api.thegraph.com/subgraphs/name/pancakeswap/prediction-v2"
NEXT_PUBLIC_GRAPH_API_PREDICTION_CAKE = "https://api.thegraph.com/subgraphs/name/pancakeswap/prediction-cake"
Expand Down
7 changes: 0 additions & 7 deletions .env.test

This file was deleted.

5 changes: 0 additions & 5 deletions .env.testnet

This file was deleted.

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/swap-sdk/**/*.ts
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const customJestConfig = {
testPathIgnorePatterns: ['<rootDir>/cypress/', '<rootDir>/src/config/__tests__/', '<rootDir>/packages'],
moduleNameMapper: {
'^@pancakeswap/uikit': '<rootDir>/packages/uikit/src',
'^@pancakeswap/sdk': '<rootDir>/packages/swap-sdk/src',
},
moduleDirectories: ['node_modules', 'src'],
testTimeout: 20000,
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { withSentryConfig } = require('@sentry/nextjs')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
const withTM = require('next-transpile-modules')(['@pancakeswap/uikit'])
const withTM = require('next-transpile-modules')(['@pancakeswap/uikit', '@pancakeswap/sdk'])

const sentryWebpackPluginOptions =
process.env.VERCEL_ENV === 'production'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@ethersproject/units": "^5.5.0",
"@gelatonetwork/limit-orders-lib": "^4.1.0",
"@next/bundle-analyzer": "^12.0.7",
"@pancakeswap/sdk": "^2.4.5",
"@pancakeswap/sdk": "3.0.0-2",
"@reduxjs/toolkit": "^1.8.2",
"@sentry/nextjs": "6.19.6",
"@uniswap/token-lists": "^1.0.0-beta.19",
Expand Down
3 changes: 3 additions & 0 deletions packages/swap-sdk/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": [] // "transform-jsbi-to-bigint"
}
21 changes: 21 additions & 0 deletions packages/swap-sdk/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Noah Zinsmeister

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
53 changes: 53 additions & 0 deletions packages/swap-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Pancakeswap SDK

Forked from the [Uniswap SDK](https://github.com/Uniswap/uniswap-v2-sdk/commit/a88048e9c4198a5bdaea00883ca00c8c8e582605).

You can refer to the Uniswap SDK documentation [uniswap.org](https://docs.uniswap.org/sdk/2.0.0/).

## Running tests

To run the tests, follow these steps. You must have at least node v10 and [yarn](https://yarnpkg.com/) installed.

First clone the repository:

```sh
git clone https://github.com/pancakeswap/pancake-swap-sdk.git
```

Move into the pancakeswap-sdk working directory

```sh
cd pancakeswap-sdk/
```

Install dependencies

```sh
yarn install
```

Run tests

```sh
yarn test
```

You should see output like the following:

```sh
yarn run v1.22.4
$ tsdx test
PASS test/constants.test.ts
PASS test/pair.test.ts
PASS test/fraction.test.ts
PASS test/miscellaneous.test.ts
PASS test/entities.test.ts
PASS test/trade.test.ts

Test Suites: 1 skipped, 6 passed, 6 of 7 total
Tests: 3 skipped, 82 passed, 85 total
Snapshots: 0 total
Time: 5.091s
Ran all test suites.
✨ Done in 6.61s.
```
18 changes: 18 additions & 0 deletions packages/swap-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
transform: {
'^.+\\.(t|j)sx?$': [
'@swc/jest',
{
jsc: {
transform: {
react: {
runtime: 'automatic',
},
},
},
},
],
},
testEnvironment: 'jsdom',
}
60 changes: 60 additions & 0 deletions packages/swap-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "@pancakeswap/sdk",
"license": "MIT",
"version": "3.0.0-2",
"description": "🛠 An SDK for building applications on top of Pancakeswap.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist"
],
"repository": "https://github.com/pancakeswap/pancake-swap-sdk.git",
"keywords": [
"pancakeswap",
"bsc"
],
"module": "dist/sdk.esm.js",
"scripts": {
"lint": "tsdx lint src test",
"build": "tsup src/index.ts --format esm,cjs --dts",
"start": "tsup src/index.tsx --format esm,cjs --watch --dts",
"test": "jest",
"prepublishOnly": "yarn run build"
},
"dependencies": {
"big.js": "^5.2.2",
"decimal.js-light": "^2.5.0",
"jsbi": "^3.1.4",
"tiny-invariant": "^1.1.0",
"tiny-warning": "^1.0.3",
"toformat": "^2.0.0"
},
"peerDependencies": {
"@ethersproject/address": "^5.0.0",
"@ethersproject/contracts": "^5.0.0",
"@ethersproject/networks": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@ethersproject/solidity": "^5.0.0"
},
"devDependencies": {
"@ethersproject/address": "^5.0.2",
"@ethersproject/contracts": "^5.0.2",
"@ethersproject/networks": "^5.0.2",
"@ethersproject/providers": "^5.0.5",
"@ethersproject/solidity": "^5.0.2",
"@swc/core": "^1.2.215",
"@swc/jest": "^0.2.21",
"@types/big.js": "^4.0.5",
"@types/jest": "^24.0.25",
"babel-plugin-transform-jsbi-to-bigint": "^1.3.1",
"tsup": "^5.10.1"
},
"engines": {
"node": ">=10"
},
"prettier": {
"printWidth": 120,
"semi": false,
"singleQuote": true
}
}
20 changes: 20 additions & 0 deletions packages/swap-sdk/src/abis/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "name": "", "type": "uint8" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [{ "name": "", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
Loading

0 comments on commit e159183

Please sign in to comment.