Skip to content

Commit 4ccc8b2

Browse files
committed
update
0 parents  commit 4ccc8b2

File tree

654 files changed

+371641
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

654 files changed

+371641
-0
lines changed

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/node_modules/*
2+
**/out/*
3+
**/.next/*
4+
**/public/charting_library/*
5+
**/public/datafeeds/*
6+
**/components/charting_library/*

.eslintrc.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": ["@typescript-eslint", "react-hooks"],
4+
"extends": [
5+
"eslint:recommended",
6+
"plugin:react/recommended",
7+
"plugin:@typescript-eslint/recommended",
8+
"prettier"
9+
],
10+
"env": {
11+
"es6": true,
12+
"browser": true,
13+
"jest": true,
14+
"node": true
15+
},
16+
"settings": {
17+
"react": {
18+
"version": "detect"
19+
}
20+
},
21+
"rules": {
22+
"react/react-in-jsx-scope": 0,
23+
"react/display-name": 0,
24+
"react/prop-types": 0,
25+
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
26+
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies
27+
"@typescript-eslint/explicit-module-boundary-types": 0,
28+
"@typescript-eslint/ban-ts-comment": 0,
29+
"@typescript-eslint/explicit-function-return-type": 0,
30+
"@typescript-eslint/explicit-member-accessibility": 0,
31+
"@typescript-eslint/indent": 0,
32+
"@typescript-eslint/member-delimiter-style": 0,
33+
"@typescript-eslint/no-empty-function": 0,
34+
"@typescript-eslint/no-explicit-any": 0,
35+
"@typescript-eslint/no-var-requires": 0,
36+
"@typescript-eslint/no-use-before-define": 0,
37+
"@typescript-eslint/no-unused-vars": [
38+
2,
39+
{
40+
"argsIgnorePattern": "^_"
41+
}
42+
],
43+
"no-console": [
44+
0,
45+
{
46+
"allow": ["warn", "error"]
47+
}
48+
]
49+
}
50+
}

.github/workflows/codeql-scan.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# GitHub SAST (static application security testing) tool that scans code for security bugs and unsafe coding practices
2+
3+
name: 'CodeQL Scan'
4+
5+
# Events that triggers CodeQL to run
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
# Option to configure as a scheduled action to monitor for drift in code
13+
# schedule:
14+
# - cron: '0 6 * * 1'
15+
16+
jobs:
17+
analyze:
18+
name: CodeQL Analysis
19+
runs-on: ubuntu-latest
20+
# Skip any PR created by dependabot to avoid permission issues (if used)
21+
if: (github.actor != 'dependabot[bot]')
22+
permissions:
23+
actions: read
24+
contents: read
25+
security-events: write
26+
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
# Add more languages if relevnt to the project
31+
language: ['javascript']
32+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
33+
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v2
37+
38+
# Initialises the CodeQL tools for scanning (sorry Americans)
39+
- name: Initialise CodeQL
40+
uses: github/codeql-action/init@v1
41+
with:
42+
languages: ${{ matrix.language }}
43+
# If you wish to specify custom queries, you can do so here or in a config file.
44+
# By default, queries listed here will override any specified in a config file.
45+
# Prefix the list here with "+" to use these queries and those in the config file.
46+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
47+
48+
# Run the analysis and upload results to the security tab
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@v1

.github/workflows/trivy-scan.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Trivy configured to scan for vulnerable dependencies in the project software composition
2+
3+
name: Trivy Scan
4+
5+
# Events that triggers Trivy to run
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
jobs:
13+
build:
14+
name: Trivy Vulnerability Scanner
15+
runs-on: ubuntu-latest
16+
# Skip any PR created by dependabot to avoid permission issues (if used)
17+
if: (github.actor != 'dependabot[bot]')
18+
steps:
19+
# Checking out the repo to scan
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
23+
# Run Trivy with the following args
24+
- name: Run Trivy
25+
uses: aquasecurity/trivy-action@master
26+
with:
27+
scan-type: 'fs' # Filesystem mode
28+
ignore-unfixed: true # Ignore vulnerabilities with no available fix
29+
format: 'template' # Template output mode
30+
template: '@/contrib/sarif.tpl' # SARIF template to be compatible with GitHub security tab
31+
output: 'trivy-results.sarif' # Output file name
32+
severity: 'CRITICAL' # Report error only on critical vulnerabilities. Warn on lower severities
33+
exit-code: '1' # Fail the job if a critical vulnerability with fix available is found
34+
35+
# Generate the output as SARIF and upload to the security tab
36+
- name: Upload Trivy results
37+
uses: github/codeql-action/upload-sarif@v1
38+
if: always() # Upload even if the job has failed due to a vulnerability
39+
with:
40+
sarif_file: 'trivy-results.sarif'

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# vercel
34+
.vercel
35+
36+
# Sentry
37+
.sentryclirc
38+
39+
.idea

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint-staged

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v14.15.3

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.next
3+
yarn.lock
4+
package-lock.json
5+
public
6+
components/charting_library

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true
4+
}

@types/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.svg' {
2+
const content: any
3+
export default content
4+
}

@types/types.tsx

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { AccountInfo, PublicKey, Transaction } from '@solana/web3.js'
2+
import { Market, OpenOrders } from '@project-serum/serum'
3+
import { Event } from '@project-serum/serum/lib/queue'
4+
import { I80F48 } from '@blockworks-foundation/mango-client'
5+
6+
export interface Token {
7+
chainId: number // 101,
8+
address: string // 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
9+
symbol: string // 'USDC',
10+
name: string // 'Wrapped USDC',
11+
decimals: number // 6,
12+
logoURI: string // 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/BXXkv6z8ykpG1yuvUDPgh732wzVHB69RnB9YgSYh3itW/logo.png',
13+
tags: string[] // [ 'stablecoin' ]
14+
}
15+
export interface MarketInfo {
16+
address: PublicKey
17+
name: string
18+
programId: PublicKey
19+
deprecated: boolean
20+
quoteLabel?: string
21+
baseLabel?: string
22+
}
23+
24+
export interface CustomMarketInfo {
25+
address: string
26+
name: string
27+
programId: string
28+
quoteLabel?: string
29+
baseLabel?: string
30+
}
31+
32+
export interface TokenAccount {
33+
pubkey: PublicKey
34+
account: AccountInfo<Buffer> | null
35+
effectiveMint: PublicKey
36+
}
37+
38+
export interface Trade extends Event {
39+
side: string
40+
price: number
41+
feeCost: number
42+
size: number
43+
}
44+
45+
interface BalancesBase {
46+
key: string
47+
symbol: string
48+
wallet?: number | null | undefined
49+
orders?: number | null | undefined
50+
openOrders?: OpenOrders | null | undefined
51+
unsettled?: number | null | undefined
52+
}
53+
54+
export interface Balances extends BalancesBase {
55+
market?: Market | null | undefined
56+
deposits?: I80F48 | null | undefined
57+
borrows?: I80F48 | null | undefined
58+
net?: I80F48 | null | undefined
59+
value?: I80F48 | null | undefined
60+
depositRate?: I80F48 | null | undefined
61+
borrowRate?: I80F48 | null | undefined
62+
decimals?: number | null | undefined
63+
}
64+
65+
export interface OpenOrdersBalances extends BalancesBase {
66+
market?: string | null | undefined
67+
baseCurrencyAccount:
68+
| { pubkey: PublicKey; account: AccountInfo<Buffer> }
69+
| null
70+
| undefined
71+
quoteCurrencyAccount:
72+
| { pubkey: PublicKey; account: AccountInfo<Buffer> }
73+
| null
74+
| undefined
75+
}
76+
77+
export interface EndpointInfo {
78+
name: string
79+
url: string
80+
websocket: string
81+
custom: boolean
82+
}
83+
84+
/**
85+
* {tokenMint: preferred token account's base58 encoded public key}
86+
*/
87+
export interface SelectedTokenAccounts {
88+
[tokenMint: string]: string
89+
}
90+
91+
export interface ChartTradeType {
92+
market: string
93+
size: number
94+
price: number
95+
orderId: string
96+
time: number
97+
side: string
98+
feeCost: number
99+
marketAddress: string
100+
}
101+
102+
export interface FeeRates {
103+
taker: number
104+
maker: number
105+
}
106+
107+
// Type declaration for the margin accounts for the mango group
108+
export type mangoTokenAccounts = {
109+
mango_group: string
110+
accounts: TokenAccount[]
111+
}
112+
113+
// Token infos
114+
export interface KnownToken {
115+
tokenSymbol: string
116+
tokenName: string
117+
icon?: string
118+
mintAddress: string
119+
}
120+
121+
export const DEFAULT_PUBLIC_KEY = new PublicKey(
122+
'11111111111111111111111111111111'
123+
)
124+
125+
export interface WalletAdapter {
126+
publicKey: PublicKey
127+
autoApprove: boolean
128+
connected: boolean
129+
signTransaction: (transaction: Transaction) => Promise<Transaction>
130+
signAllTransactions: (transaction: Transaction[]) => Promise<Transaction[]>
131+
connect: () => any
132+
disconnect: () => any
133+
on(event: string, fn: () => void): this
134+
}
135+
136+
export interface PerpTriggerOrder {
137+
orderId: number
138+
marketIndex: number
139+
orderType: 'limit' | 'ioc' | 'postOnly' | 'market'
140+
side: 'buy' | 'sell'
141+
price: number
142+
size: number
143+
triggerCondition: 'above' | 'below'
144+
triggerPrice: number
145+
}

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Mango UI V3
2+
3+
Uses:
4+
5+
- [Typescript](https://www.typescriptlang.org/)
6+
- Linting with [ESLint](https://eslint.org/)
7+
- Formatting with [Prettier](https://prettier.io/)
8+
- Linting, typechecking and formatting on by default using [`husky`](https://github.com/typicode/husky) for commit hooks
9+
- Testing with [Jest](https://jestjs.io/) and [`react-testing-library`](https://testing-library.com/docs/react-testing-library/intro)
10+
11+
## Running the UI locally
12+
13+
1. Install Node.js and npm (https://nodejs.org/en/download/), and Git (https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
2. Open a new terminal window (if running Windows use Git Bash) and run `npm install -g yarn`
15+
3. Run `git clone https://github.com/blockworks-foundation/mango-ui-v3.git && cd mango-ui-v3` to get the UI source code
16+
4. Run `yarn install` to install dependencies
17+
5. Run `yarn dev` to start the webserver
18+
6. Navigate to `http://localhost:3000` in your browser

0 commit comments

Comments
 (0)