Skip to content

Commit

Permalink
Merge branch 'main' into fix-rpc-amount
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanYang0523 committed Oct 14, 2022
2 parents b236234 + 25107c6 commit bbbf463
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 249 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/publish-dev1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish NPM (Dev1)
on:
workflow_dispatch:
branches:
- '*'
- "*"
jobs:
publish-npm-package:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -46,9 +46,9 @@ jobs:
- name: Build package
run: yarn build
env:
TRACK: ${{ steps.set-variables.outputs.release_track }}
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN: ${{ secrets.METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN_DEV1 }}
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN: ${{ secrets.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN_DEV1 }}
TRACK: ${{ steps.set-variables.outputs.release_track }}
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI: ${{ secrets.METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI_DEV1 }}
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI: ${{ secrets.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI_DEV1 }}

- name: Publish package
id: publish-package
Expand All @@ -61,9 +61,9 @@ jobs:

- name: Git push version tag
run: |
PKG_VERSION=${{ steps.set-variables.outputs.pkg_version }}
git tag $PKG_VERSION
git push origin $PKG_VERSION
PKG_VERSION=${{ steps.set-variables.outputs.pkg_version }}
git tag $PKG_VERSION
git push origin $PKG_VERSION
discord-notification-npm-package:
name: Discord Notification for publishing npm package
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/publish-dev2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish NPM (Dev2)
on:
workflow_dispatch:
branches:
- '*'
- "*"
jobs:
publish-npm-package:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -46,9 +46,9 @@ jobs:
- name: Build package
run: yarn build
env:
TRACK: ${{ steps.set-variables.outputs.release_track }}
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN: ${{ secrets.METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN_DEV1 }}
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN: ${{ secrets.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN_DEV1 }}
TRACK: ${{ steps.set-variables.outputs.release_track }}
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI: ${{ secrets.METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI_DEV1 }}
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI: ${{ secrets.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI_DEV1 }}

- name: Publish package
id: publish-package
Expand All @@ -61,9 +61,9 @@ jobs:

- name: Git push version tag
run: |
PKG_VERSION=${{ steps.set-variables.outputs.pkg_version }}
git tag $PKG_VERSION
git push origin $PKG_VERSION
PKG_VERSION=${{ steps.set-variables.outputs.pkg_version }}
git tag $PKG_VERSION
git push origin $PKG_VERSION
discord-notification-npm-package:
name: Discord Notification for publishing npm package
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
branches:
- main
- release/*
- op-kovan-dev1
- op-kovan-dev2
jobs:
test:
runs-on: ubuntu-latest
Expand Down
194 changes: 183 additions & 11 deletions CHANGELOG.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ See `./test/` for common use cases.

```javascript
TRACK
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI
METADATA_URL_CORE_OVERRIDE_OPTIMISM
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM

enum TRACK {
Expand Down Expand Up @@ -58,8 +58,8 @@ yarn start:[TRACK]
### To supply custom envs, run:

```bash
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN="your_url" \
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN="your_url" \
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI="your_url" \
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI="your_url" \
yarn start:[TRACK]
```

Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@perp/sdk-curie",
"version": "1.13.0-canary.1",
"version": "1.14.0",
"license": "BSD-3-Clause",
"main": "dist/lib/index.js",
"module": "dist/es/index.js",
Expand Down Expand Up @@ -58,7 +58,7 @@
"sdk"
],
"dependencies": {
"@perp/curie-deployments": "2022.8.25-1661400314113",
"@perp/curie-deployments": "2022.10.5-1664940982527",
"cross-fetch": "3.1.5"
},
"peerDependencies": {
Expand All @@ -67,10 +67,6 @@
},
"devDependencies": {
"@chainlink/contracts": "0.4.1",
"@uniswap/v3-core": "1.0.0",
"big.js": "6.1.1",
"cross-fetch": "3.1.5",
"ethers": "5.5.0",
"@commitlint/cli": "17.0.0",
"@commitlint/config-conventional": "17.0.0",
"@commitlint/cz-commitlint": "17.0.0",
Expand All @@ -83,20 +79,22 @@
"@types/jest": "27.0.1",
"@typescript-eslint/eslint-plugin": "5.12.0",
"@typescript-eslint/parser": "5.12.0",
"@uniswap/v3-core": "1.0.0",
"big.js": "6.1.1",
"commitizen": "4.2.4",
"copyfiles": "2.4.1",
"cross-env": "7.0.3",
"esbuild": "^0.14.53",
"cross-fetch": "3.1.5",
"eslint": "8.9.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.0.0",
"ethers": "5.5.0",
"husky": "8.0.1",
"jest": "27.1.0",
"lint-staged": "11.1.2",
"mkdirp": "1.0.4",
"rimraf": "3.0.2",
"rollup": "2.77.2",
"rollup-plugin-esbuild": "^4.9.1",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.32.1",
"rollup-plugin-visualizer": "5.7.1",
Expand Down
12 changes: 4 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import resolve from "@rollup/plugin-node-resolve"
import pkg from "./package.json"
import replace from "@rollup/plugin-replace"
import { visualizer } from "rollup-plugin-visualizer"
// import esbuild from "rollup-plugin-esbuild"
import typescript from "rollup-plugin-typescript2"
import { terser } from "rollup-plugin-terser"

Expand Down Expand Up @@ -50,14 +49,14 @@ export default {
values: {
"process.env.LOGGER_ON": JSON.stringify(process.env.LOGGER_ON),
"process.env.TRACK": JSON.stringify(process.env.TRACK),
"process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN": JSON.stringify(
process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN,
"process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI": JSON.stringify(
process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI,
),
"process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM": JSON.stringify(
process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM,
),
"process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN": JSON.stringify(
process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN,
"process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI": JSON.stringify(
process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI,
),
"process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM": JSON.stringify(
process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM,
Expand All @@ -69,9 +68,6 @@ export default {
json(),
typescript(),
terser(),
// esbuild({
// minify: true,
// }),
visualizer(),
],
}
21 changes: 14 additions & 7 deletions script/generate-type.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import fs from "fs"
import { basename } from "path"

import { glob, runTypeChain } from "typechain"

const getABIRefByTrack = (track?: string) => {
switch (track) {
case "dev1":
return "optimism-kovan-dev1"
return "optimism-goerli-dev1"
case "dev2":
return "optimism-kovan-dev2"
return "optimism-goerli-dev2"
case "canary":
// Canary supports both Kovan and Mainnet but we gen-type with Kovan's ABI.
// When the Kovan ABI contains new features that has not yet been deployed to Mainnet,
// Canary supports both Goerli and Mainnet but we gen-type with Goerli's ABI.
// When the Goerli ABI contains new features that has not yet been deployed to Mainnet,
// it is expected to fail when using Mainnet.
return "optimism-kovan"
return "optimism-goerli"
case "rc": // release candidate
return "optimism-kovan"
return "optimism-goerli"
case "production":
return "optimism"
default:
Expand All @@ -27,14 +28,20 @@ async function main() {

const abiRef = getABIRefByTrack(process.env.TRACK)
// find all files matching the glob
const allFiles = glob(cwd, [
let allFiles = glob(cwd, [
`${__dirname}/../node_modules/@perp/curie-deployments/${abiRef}/core/artifacts/contracts/**/+([a-zA-Z0-9_]).json`,
`${__dirname}/../node_modules/@perp/curie-deployments/${abiRef}/core/artifacts/oracle-contracts/**/+([a-zA-Z0-9_]).json`,
`${__dirname}/../node_modules/@perp/curie-deployments/${abiRef}/periphery/artifacts/contracts/**/+([a-zA-Z0-9_]).json`,
`${__dirname}/../node_modules/@uniswap/v3-core/artifacts/contracts/UniswapV3Pool.sol/UniswapV3Pool.json`,
`${__dirname}/../node_modules/@chainlink/contracts/abi/v0.7/**/+([a-zA-Z0-9_]).json`,
])

allFiles = allFiles.filter(file => {
const fileName = basename(file)
// eliminate unused artifacts like TestClearingHouse.json ....
return !fileName.match(/Test.*\.json/)
})

const outDir = "src/contracts/type"

const result = await runTypeChain({
Expand Down
10 changes: 5 additions & 5 deletions src/constants/envVariables.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* TRACK: Development tracks, each correspond to a set of deployed smart contracts.
* METADATA_URL_OVERRIDE_OPTIMISM_KOVAN: metadata url override for Optimism Kovan.
* METADATA_URL_OVERRIDE_OPTIMISM_GOERLI: metadata url override for Optimism Goerli.
* METADATA_URL_OVERRIDE_OPTIMISM: metadata url override for Optimism Mainnet.
*/
const LOGGER_ON = process.env.LOGGER_ON
const TRACK = process.env.TRACK
const METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN = process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN
const METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI = process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI
const METADATA_URL_CORE_OVERRIDE_OPTIMISM = process.env.METADATA_URL_CORE_OVERRIDE_OPTIMISM
const METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN = process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN
const METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI = process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI
const METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM = process.env.METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM

export enum Track {
Expand All @@ -27,9 +27,9 @@ const TYPED_TRACK = isTrack(TRACK) ? TRACK : Track.PRODUCTION

export {
TYPED_TRACK as TRACK,
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN,
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI,
METADATA_URL_CORE_OVERRIDE_OPTIMISM,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM,
LOGGER_ON,
}
2 changes: 1 addition & 1 deletion src/metadata/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface ChainMetadata {
USDC: string
UniswapV3Factory: string
}
network: "optimism" | "optimismKovan"
network: "optimism" | "optimism-goerli"
pools: Pool[]
collaterals: Collateral[]
}
Expand Down
34 changes: 17 additions & 17 deletions src/network/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import MainMetadataOptimismGoerli from "@perp/curie-deployments/optimism-goerli/core/metadata.json"
import MainMetadataOptimism from "@perp/curie-deployments/optimism/core/metadata.json"

import {
METADATA_URL_CORE_OVERRIDE_OPTIMISM,
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN,
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN,
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI,
TRACK,
Track,
} from "../constants"

import MainMetadataOptimism from "@perp/curie-deployments/optimism/core/metadata.json"
import MainMetadataOptimismKovan from "@perp/curie-deployments/optimism-kovan/core/metadata.json"
import MainMetadataOptimismKovanDev1 from "@perp/curie-deployments/optimism-kovan-dev1/core/metadata.json"
import MainMetadataOptimismKovanDev2 from "@perp/curie-deployments/optimism-kovan-dev2/core/metadata.json"

/* ========== CHAIN ========== */
export enum ChainId {
OPTIMISM_KOVAN = MainMetadataOptimismKovan.chainId,
OPTIMISM_GOERLI = MainMetadataOptimismGoerli.chainId,
OPTIMISM = MainMetadataOptimism.chainId,
}

Expand All @@ -25,32 +23,34 @@ const SupportedChainIdByTrack: {
OPTIMISM: MainMetadataOptimism.chainId,
},
[Track.RC]: {
OPTIMISM_KOVAN: MainMetadataOptimismKovan.chainId,
OPTIMISM_GOERLI: MainMetadataOptimismGoerli.chainId,
},
[Track.CANARY]: {
OPTIMISM_KOVAN: MainMetadataOptimismKovan.chainId,
OPTIMISM_GOERLI: MainMetadataOptimismGoerli.chainId,
OPTIMISM: MainMetadataOptimism.chainId,
},
[Track.DEV1]: {
OPTIMISM_KOVAN: MainMetadataOptimismKovanDev1.chainId,
// TODO: import from MainMetadataOptimismGoerliDev1 when @perp/curie-deployments support it
OPTIMISM_GOERLI: MainMetadataOptimismGoerli.chainId,
},
[Track.DEV2]: {
OPTIMISM_KOVAN: MainMetadataOptimismKovanDev2.chainId,
// TODO: import from MainMetadataOptimismGoerliDev2 when @perp/curie-deployments support it
OPTIMISM_GOERLI: MainMetadataOptimismGoerli.chainId,
},
}
export const SupportedChainIds = SupportedChainIdByTrack[TRACK]

/* ========== METADATA ========== */
export const MetadataUrlCoreByChainId = {
[ChainId.OPTIMISM_KOVAN]:
METADATA_URL_CORE_OVERRIDE_OPTIMISM_KOVAN || "https://metadata.perp.exchange/v2/optimism-kovan.json",
[ChainId.OPTIMISM_GOERLI]:
METADATA_URL_CORE_OVERRIDE_OPTIMISM_GOERLI || "https://metadata.perp.exchange/v2/optimism-goerli.json",
[ChainId.OPTIMISM]: METADATA_URL_CORE_OVERRIDE_OPTIMISM || "https://metadata.perp.exchange/v2/optimism.json",
}

export const MetadataUrlPeripheryByChainId = {
[ChainId.OPTIMISM_KOVAN]:
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_KOVAN ||
"https://metadata.perp.exchange/v2/periphery/optimism-kovan.json",
[ChainId.OPTIMISM_GOERLI]:
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM_GOERLI ||
"https://metadata.perp.exchange/v2/periphery/optimism-goerli.json",
[ChainId.OPTIMISM]:
METADATA_URL_PERIPHERY_OVERRIDE_OPTIMISM || "https://metadata.perp.exchange/v2/periphery/optimism.json",
}
4 changes: 2 additions & 2 deletions test/core/PerpetualProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ describe("PerpetualProtocol", () => {

beforeAll(async () => {
perp = new PerpetualProtocol({
chainId: SupportedChainIds.OPTIMISM_KOVAN,
chainId: SupportedChainIds.OPTIMISM_GOERLI,
providerConfigs: [
{
rpcUrl: "https://kovan.optimism.io",
rpcUrl: "https://goerli.optimism.io/",
},
],
})
Expand Down
6 changes: 3 additions & 3 deletions test/core/clearingHouse/ClearingHouse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe("ClearingHouse", () => {

beforeAll(async () => {
perp = new PerpetualProtocol({
chainId: SupportedChainIds.OPTIMISM_KOVAN,
chainId: SupportedChainIds.OPTIMISM_GOERLI,
providerConfigs: [
{
rpcUrl: "https://kovan.optimism.io",
rpcUrl: "https://goerli.optimism.io/",
},
],
})
Expand Down Expand Up @@ -59,7 +59,7 @@ describe("ClearingHouse", () => {
contractFunctionName: "openPosition",
args: [
{
baseToken: "0x5802918dc503c465f969da0847b71e3fbe9b141c",
baseToken: "0x60a233b9b94c67e94e0a269429fb40004d4ba494",
isBaseToQuote: false,
isExactInput: true,
amount: big2BigNumberAndScaleUp(amountInput),
Expand Down
4 changes: 2 additions & 2 deletions test/core/position/PositionDraft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ describe("PositionDraft", () => {

beforeAll(async () => {
perp = new PerpetualProtocol({
chainId: SupportedChainIds.OPTIMISM_KOVAN,
chainId: SupportedChainIds.OPTIMISM_GOERLI,
providerConfigs: [
{
rpcUrl: "https://kovan.optimism.io",
rpcUrl: "https://goerli.optimism.io/",
},
],
})
Expand Down
Loading

0 comments on commit bbbf463

Please sign in to comment.