Skip to content

Commit

Permalink
Fix fetch error and refactor files (#40)
Browse files Browse the repository at this point in the history
* build: upgrade version to 0.1.6-alpha

* Refactor/refactor (#39)

* Add a new test: PerpetualProtocol.test.ts

* feat: replace fetch with cross-fetch

* feat: remove graphReader

* test: make test environment support json

* build: remove @apollo/client

* docs: license

* refactor: sync with latest code

* build: remove ^ in version

Co-authored-by: Yenwen Feng <tempofeng@gmail.com>
Co-authored-by: justin <>

* build: upgrade verion to 0.1.6

* feat: remove try catch in  in in perpeturalprotocol class

Co-authored-by: justin <>
Co-authored-by: Yenwen Feng <tempofeng@gmail.com>
  • Loading branch information
JustinlinPerp and tempofeng authored Mar 16, 2022
1 parent f45a11e commit ebc866b
Show file tree
Hide file tree
Showing 17 changed files with 562 additions and 676 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.DS_Store
node_modules
dist
.idea
coverage
42 changes: 25 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
LICENSEMIT License
BSD 3-Clause License

Copyright (c) 2022 justin
Copyright (c) 2022, Perpetual Protocol
All rights reserved.

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:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

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.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ module.exports = {
transform: { '^.+\\.ts?$': 'ts-jest' },
testPathIgnorePatterns: ['dist/'],
globals: { 'ts-jest': { diagnostics: false }},
moduleDirectories: [
"node_modules",
"src"
],
transform: {
"^.+\\.ts$": "ts-jest"
},
};
80 changes: 37 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@perp/v2-sdk",
"version": "0.1.6-alpha",
"license": "BSD 3-Clause",
"version": "0.1.6",
"license": "BSD-3-Clause",
"main": "dist/index.js",
"module": "dist/v2-sdk.esm.js",
"typings": "dist/src/index.d.ts",
Expand Down Expand Up @@ -48,60 +48,54 @@
"sdk"
],
"dependencies": {
"@apollo/client": "3.4.7",
"@babel/preset-modules": "^0.1.5",
"@babel/preset-modules": "0.1.5",
"@perp/curie-deployments": "2022.3.3-1646291577863",
"@perp/curie-periphery": "1.3.1",
"@uniswap/v3-core": "1.0.0",
"big.js": "6.1.1",
"cross-fetch": "3.1.5",
"dotenv-flow": "3.2.0",
"ethers": "5.5.0"
},
"devDependencies": {
"@babel/preset-env": "^7.16.0",
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@babel/preset-env": "7.16.0",
"@commitlint/cli": "13.1.0",
"@commitlint/config-conventional": "13.1.0",
"@rollup/plugin-commonjs": "21.0.1",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "13.1.3",
"@typechain/ethers-v5": "7.0.0",
"@types/big.js": "6.1.2",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"commitizen": "^4.2.4",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.9.0",
"eslint-config-airbnb": "^19.0.0",
"eslint-config-airbnb-typescript": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^4.3.1",
"husky": "^7.0.2",
"jest": "^27.1.0",
"lint-staged": "^11.1.2",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2",
"rollup": "^2.56.3",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-typescript2": "^0.30.0",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.5",
"ts-lib": "^0.0.5",
"ts-node": "^10.5.0",
"@types/jest": "27.0.1",
"@typescript-eslint/eslint-plugin": "5.12.0",
"@typescript-eslint/parser": "5.12.0",
"commitizen": "4.2.4",
"cross-env": "7.0.3",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.9.0",
"eslint-config-airbnb": "19.0.0",
"eslint-config-airbnb-typescript": "15.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-promise": "4.3.1",
"husky": "7.0.2",
"jest": "27.1.0",
"lint-staged": "11.1.2",
"mkdirp": "1.0.4",
"rimraf": "3.0.2",
"rollup": "2.56.3",
"rollup-plugin-sourcemaps": "0.6.3",
"rollup-plugin-typescript2": "0.30.0",
"standard-version": "9.3.1",
"ts-jest": "27.0.5",
"ts-lib": "0.0.5",
"ts-node": "10.5.0",
"typechain": "5.0.0",
"typedoc": "^0.21.9",
"typedoc": "0.21.9",
"typescript": "4.4.2"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
"react": "^16.8.0 || ^17.0.0",
"subscriptions-transport-ws": "^0.9.0 || ^0.11.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
Expand Down
1 change: 0 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps';
import { babel } from '@rollup/plugin-babel';
import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import pkg from './package.json';
Expand Down
28 changes: 14 additions & 14 deletions src/core/PerpetualProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ class PerpetualProtocol {
}

async init() {
try {
this._metadata = await Metadata.create(this._chainId)
this._contracts = new Contracts({ metadata: this.metadata, provider: this.provider })
this._contractReader = new ContractReader({
metadata: this.metadata,
provider: this.provider,
contracts: this.contracts,
})
this._markets = new Markets(this)
this._clearingHouseConfig = await ClearingHouseConfig.create(this.contractReader)
this._clearingHouse = new ClearingHouse(this)
} catch (e) {
throw new InitSDKError()
}
// try {
this._metadata = await Metadata.create(this._chainId)
this._contracts = new Contracts({ metadata: this.metadata, provider: this.provider })
this._contractReader = new ContractReader({
metadata: this.metadata,
provider: this.provider,
contracts: this.contracts,
})
this._markets = new Markets(this)
this._clearingHouseConfig = await ClearingHouseConfig.create(this.contractReader)
this._clearingHouse = new ClearingHouse(this)
// } catch (e) {
// throw new InitSDKError()
// }
}

async connect({ signer }: { signer: Signer }) {
Expand Down
83 changes: 0 additions & 83 deletions src/core/contractReader/GraphqlReader.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/core/contractReader/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./ContractReader"
export * from "./GraphqlReader"
export * from "./MulticallReader"
1 change: 0 additions & 1 deletion src/core/liquidity/LiquidityDraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface EventPayloadLiquidityAmountUpdated {
baseAmount?: Big
isLastEditBase: boolean
isUpdatedFromTickPrice: boolean
test?: string
}

export interface LiquidityDraftLiquidityAmountUpdatable {
Expand Down
2 changes: 1 addition & 1 deletion src/core/wallet/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Wallet extends Channel<WalletEventName> {
private _cache: Map<CacheKey, Big> = new Map()
private readonly _contractReader: ContractReader
private _collateralToken: CollateralToken
private _contractVault: ContractVault
private _contractVault: ContractVault // TODO: move to vault

constructor(private readonly _perp: PerpetualProtocol, readonly account: string) {
super(_perp.channelRegistry)
Expand Down
1 change: 1 addition & 0 deletions src/metadata/Metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PeripheryMetadataOptimism from "@perp/curie-periphery/metadata/optimism.json"
import PeripheryMetadataOptimismKovan from "@perp/curie-periphery/metadata/optimismKovan.json"
import { ChainId, ChainName } from "../network"
import fetch from "cross-fetch"

export type Pool = {
address: string
Expand Down
1 change: 1 addition & 0 deletions src/network/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum SupportedChainId {
OPTIMISTIC_ETHEREUM = MainMetadataOptimism.chainId,
}

// TODO ChainId and ChainName might be deprecated later
export const ChainId = {
OPTIMISTIC_ETHEREUM: 10,
OPTIMISTIC_ETHEREUM_TESTNET_KOVAN: 69,
Expand Down
7 changes: 0 additions & 7 deletions test/blah.test.ts

This file was deleted.

20 changes: 20 additions & 0 deletions test/core/PerpetualProtocol.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PerpetualProtocol, SupportedChainId } from "../../src"

describe("PerpetualProtocol test", () => {
it("getMarket", async () => {
const pp = new PerpetualProtocol({
chainId: SupportedChainId.OPTIMISTIC_ETHEREUM,
providerConfigs: [
{
rpcUrl: "https://mainnet.optimism.io",
},
],
})
await pp.init()

const market = pp.markets.getMarket({
tickerSymbol: "ETHUSD",
})
expect(market.baseSymbol).toEqual("ETH")
})
})
19 changes: 0 additions & 19 deletions test/index.test.ts

This file was deleted.

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"node_modules/@types"
],
"jsx": "react-jsx",
"resolveJsonModule": true
"resolveJsonModule": true,
"esModuleInterop": true
},
"include": [
"src",
Expand Down
Loading

0 comments on commit ebc866b

Please sign in to comment.