Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sushiswap/sushiswap into …
Browse files Browse the repository at this point in the history
…feature/farms-api
  • Loading branch information
LufyCZ committed Sep 2, 2022
2 parents eb4a352 + ed94707 commit 1e2af0f
Show file tree
Hide file tree
Showing 116 changed files with 4,653 additions and 1,391 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ https://pnpm.io/installation
## Disclaimer

_These smart contracts and code are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts and code. There can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions or loss of transmitted information. In addition, using these smart contracts and code should be conducted in accordance with applicable law. Nothing in this repo should be construed as investment advice or legal advice for any particular facts or circumstances and is not meant to replace competent counsel. It is strongly advised for you to contact a reputable attorney in your jurisdiction for any questions or concerns with respect thereto. SushiSwap is not liable for any use of the foregoing and users should proceed with caution and use at their own risk._

_Any stated APY (the 'Rate') is purely informational based on publicly available blockchain data, and is a forward-looking projection based on our good faith belief of how to reasonably project results over the relevant period, but such belief is subject to numerous assumptions, risks and uncertainties (including smart contract security risks and third-party actions) which could result in a materially different (lower or higher) token-denominated Rates. The Rate is not a promise, guarantee or undertaking on the part of any person or group of persons, but depends entirely on the results of operation of smart contracts and other autonomous systems (including third-party systems) and how third parties interact with those systems after the time of your deposit or other interactions. Even if the Rate is achieved as projected, you may still suffer a financial loss in fiat-denominated terms if the fiat-denominated value of the relevant tokens (your deposit and any tokens allocated or distributed to you pursuant to the Rate) declines during the deposit period._
1 change: 1 addition & 0 deletions apis/farm/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REDIS_URL=
1 change: 1 addition & 0 deletions apis/farm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
1 change: 1 addition & 0 deletions apis/farm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Farm
29 changes: 29 additions & 0 deletions apis/farm/api/v0/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { VercelRequest, VercelResponse } from '@vercel/node'
import { getUnixTime } from 'date-fns'

import redis from '../../lib/redis'

export default async (request: VercelRequest, response: VercelResponse) => {
const data = await redis.hgetall('farms')

if (!data) {
return response.status(204)
}

const now = getUnixTime(Date.now())

return response.status(200).json(
Object.fromEntries(
Object.entries(data).map(([chainId, data]) => {
const json = JSON.parse(data)
return [
chainId,
{
...json,
updatedSecondsAgo: now - json.updatedAtTimestamp,
},
]
})
)
)
}
7 changes: 7 additions & 0 deletions apis/farm/lib/redis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Redis from 'ioredis'

if (!process.env.REDIS_URL) throw new Error('REDIS_URL is required')

const redis = new Redis(process.env.REDIS_URL)

export default redis
19 changes: 19 additions & 0 deletions apis/farm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "farm",
"version": "0.0.0",
"private": true,
"scripts": {
"lint": "eslint --fix ."
},
"dependencies": {
"@vercel/node": "^2.2.0",
"date-fns": "2.x",
"ioredis": "5.x"
},
"devDependencies": {
"@sushiswap/eslint-config": "workspace:*",
"@sushiswap/jest-config": "workspace:*",
"@sushiswap/prettier-config": "workspace:*",
"@sushiswap/typescript-config": "workspace:*"
}
}
5 changes: 5 additions & 0 deletions apis/farm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"exclude": ["node_modules"],
"extends": "@sushiswap/typescript-config/node16.json",
"include": ["."]
}
12 changes: 12 additions & 0 deletions apis/farm/vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"headers":[
{
"source": "/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Origin", "value": "*" },
{ "key": "Access-Control-Allow-Methods", "value": "GET" }
]
}
],
"rewrites": [{ "source": "/v0", "destination": "/api/v0" }]
}
2 changes: 1 addition & 1 deletion apis/token-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"dependencies": {
"@sushiswap/chainlink-token-list": "^0.1.0",
"@sushiswap/default-token-list": "^31.1.0",
"@sushiswap/default-token-list": "^32.0.0",
"@vercel/node": "^2.2.0"
},
"devDependencies": {
Expand Down
14 changes: 10 additions & 4 deletions apps/analytics/config.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
import { ChainId } from '@sushiswap/chain'

export const ENABLED_NETWORKS = [
// ChainId.ETHEREUM,
ChainId.AVALANCHE,
ChainId.ARBITRUM,
ChainId.BSC,
// ChainId.CELO,
ChainId.CELO,
ChainId.FANTOM,
ChainId.FUSE,
ChainId.GNOSIS,
ChainId.MOONBEAM,
ChainId.MOONRIVER,
// ChainId.HARMONY,
// ChainId.FANTOM,
// ChainId.POLYGON,
]

const GRAPH_HOST_ENDPOINT = 'api.thegraph.com/subgraphs/name'

export const EXCHANGE_SUBGRAPH_NAME: Record<number | string, string> = {
[ChainId.ETHEREUM]: 'sushiswap/sushiswap-ethereum',
[ChainId.AVALANCHE]: 'sushiswap/sushiswap-avalanche',
[ChainId.ARBITRUM]: 'sushiswap/sushiswap-arbitrum',
[ChainId.BSC]: 'sushiswap/sushiswap-bsc',
[ChainId.CELO]: 'sushiswap/sushiswap-celo',
[ChainId.FANTOM]: 'sushiswap/sushiswap-fantom',
[ChainId.FUSE]: 'sushiswap/sushiswap-fuse',
[ChainId.GNOSIS]: 'sushiswap/sushiswap-gnosis',
[ChainId.MOONBEAM]: 'sushiswap/sushiswap-moonbeam',
[ChainId.MOONRIVER]: 'sushiswap/sushiswap-moonriver',
[ChainId.HARMONY]: 'sushiswap/sushiswap-harmony',
[ChainId.FANTOM]: 'sushiswap/sushiswap-fantom',
[ChainId.POLYGON]: 'sushiswap/sushiswap-polygon',
}

export const GRAPH_HOST = {
[ChainId.ETHEREUM]: GRAPH_HOST_ENDPOINT,
[ChainId.AVALANCHE]: GRAPH_HOST_ENDPOINT,
[ChainId.ARBITRUM]: GRAPH_HOST_ENDPOINT,
[ChainId.BSC]: GRAPH_HOST_ENDPOINT,
[ChainId.CELO]: GRAPH_HOST_ENDPOINT,
[ChainId.FANTOM]: GRAPH_HOST_ENDPOINT,
[ChainId.FUSE]: GRAPH_HOST_ENDPOINT,
[ChainId.GNOSIS]: GRAPH_HOST_ENDPOINT,
[ChainId.MOONBEAM]: GRAPH_HOST_ENDPOINT,
[ChainId.MOONRIVER]: GRAPH_HOST_ENDPOINT,
[ChainId.HARMONY]: GRAPH_HOST_ENDPOINT,
[ChainId.FANTOM]: GRAPH_HOST_ENDPOINT,
[ChainId.POLYGON]: GRAPH_HOST_ENDPOINT,
}
2 changes: 1 addition & 1 deletion apps/analytics/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const getCharts = async () => {
const sdk = getBuiltGraphSDK()
const { crossChainFactoryDaySnapshots } = await sdk.CrossChainFactoryDaySnapshots({
chainIds: ENABLED_NETWORKS,
first: 365,
first: 1000,
})

const dateSnapshotMap = new Map()
Expand Down
1 change: 1 addition & 0 deletions apps/analytics/pages/api/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import { getCharts } from '../../lib/api'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
res.setHeader('Cache-Control', 'public, s-maxage=900, stale-while-revalidate=3600')
const data = await getCharts()
res.status(200).send(data)
}
9 changes: 4 additions & 5 deletions apps/analytics/pages/api/pairs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { NextApiRequest, NextApiResponse } from 'next'

import { getPairs } from '../../lib/api'
import { QuerypairsArgs } from '.graphclient'
import { getPairs, GetPairsQuery } from '../../lib/api'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
res.setHeader('Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59')
const { query } = req
const pairs = await getPairs(query as unknown as QuerypairsArgs & { networks: string })
res.setHeader('Cache-Control', 'public, s-maxage=900, stale-while-revalidate=3600')
const query = req.query as unknown
const pairs = await getPairs(query as GetPairsQuery)
res.status(200).send(JSON.stringify(pairs))
}
1 change: 1 addition & 0 deletions apps/analytics/pages/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'
import { getStats } from '../../lib/api'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
res.setHeader('Cache-Control', 'public, s-maxage=900, stale-while-revalidate=3600')
const pairs = await getStats()
res.status(200).send(pairs)
}
2 changes: 1 addition & 1 deletion apps/analytics/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ChartSection } from '../components/ChartSection'
import { getCharts, getPairs, GetPairsQuery } from '../lib/api'

export const getServerSideProps: GetServerSideProps = async ({ req, query, res }) => {
res.setHeader('Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59')
res.setHeader('Cache-Control', 'public, s-maxage=900, stale-while-revalidate=3600')
// console.log('SSR query', query)
const [pairs, charts] = await Promise.all([getPairs(query as unknown as GetPairsQuery), getCharts()])
return {
Expand Down
21 changes: 12 additions & 9 deletions apps/analytics/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ export const resolvers: Resolvers = {
})
)
).then((pools) =>
pools.flat().sort((a, b) => {
if (args.orderDirection === 'asc') {
return a[args.orderBy || 'liquidityUSD'] - b[args.orderBy || 'liquidityUSD']
} else if (args.orderDirection === 'desc') {
return b[args.orderBy || 'liquidityUSD'] - a[args.orderBy || 'liquidityUSD']
}

return 0
})
pools
.flat()
.sort((a, b) => {
if (args.orderDirection === 'asc') {
return a[args.orderBy || 'liquidityUSD'] - b[args.orderBy || 'liquidityUSD']
} else if (args.orderDirection === 'desc') {
return b[args.orderBy || 'liquidityUSD'] - a[args.orderBy || 'liquidityUSD']
}
return 0
})
.slice(args.skip, args.skip + args.first)
),

crossChainStats: async (root, args, context, info) =>
Promise.all(
args.chainIds.map((chainId) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,19 @@ export const CreateMultipleForm: FC = () => {
{el}
</Typography>
))}
{formStateErrors.streams?.map((errors, idx) =>
Object.entries(errors).map(([k, v]) => (
<Typography variant="sm" className="flex items-center gap-2 text-red" key={`${idx}-${k}`}>
<ExclamationCircleIcon width={20} height={20} />
Stream {idx + 1}: {(v as any).message}
</Typography>
))
)}
{formStateErrors.streams?.map((errors, idx) => {
if (errors) {
return Object.entries(errors).map(([k, v]) => (
<Typography variant="sm" className="flex items-center gap-2 text-red" key={`${idx}-${k}`}>
<ExclamationCircleIcon width={20} height={20} />
Stream {idx + 1}: {(v as any).message}
</Typography>
))
}
})}
</div>
<TableSection />
<Form.Buttons className="flex flex-col items-end gap-3 mt-[-68px]">
<Form.Buttons className="flex flex-col items-end gap-3">
<Button
type="button"
onClick={() => setReview(true)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,20 @@ export const CreateMultipleForm = () => {
</Typography>
))}
<>
{formStateErrors.vestings?.map((errors, idx) =>
Object.entries(errors).map(([k, v]) => (
<Typography variant="sm" className="flex items-center gap-2 text-red" key={`${idx}-${k}`}>
<ExclamationCircleIcon width={20} height={20} />
Vesting {idx + 1}: {(v as any).message}
</Typography>
))
)}
{formStateErrors.vestings?.map((errors, idx) => {
if (errors) {
return Object.entries(errors).map(([k, v]) => (
<Typography variant="sm" className="flex items-center gap-2 text-red" key={`${idx}-${k}`}>
<ExclamationCircleIcon width={20} height={20} />
Vesting {idx + 1}: {(v as any).message}
</Typography>
))
}
})}
</>
</div>
<TableSection />
<Form.Buttons className="flex flex-col items-end gap-3 mt-[-68px]">
<Form.Buttons className="flex flex-col items-end gap-3">
<Button
type="button"
onClick={() => setReview(true)}
Expand Down
28 changes: 28 additions & 0 deletions apps/furo/next-seo.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check
/** @type {import('next-seo').DefaultSeoProps} */
export default {
titleTemplate: '%s | Furo',
defaultTitle: 'Furo',
description: 'Earn, stream and automate your DAO salaries and token vesting with Furo.',
// canonical: 'https://sushi.com/furo',
// mobileAlternate: {
// media: '',
// href: '',
// },
// languageAlternates: [{ hrefLang: "en", href: "https://sushi.com/furo" }],
twitter: {
handle: '@sushiswap',
site: '@sushiswap',
cardType: 'summary_large_image',
},
openGraph: {
// url: 'https://sushi.com/furo',
type: 'website',
title: 'Furo',
description: 'and token vesting with Furo. and token vesting with Furo.',
// images: [],
// videos: [],
// locale: 'en_IE',
site_name: 'Sushi',
},
}
1 change: 1 addition & 0 deletions apps/furo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"ethers": "^5.0.0",
"graphql": "16.6.0",
"next": "^12.2.0",
"next-seo": "^5.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.31.1",
Expand Down
3 changes: 3 additions & 0 deletions apps/furo/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import { SUPPORTED_CHAINS } from 'config'
import type { AppProps } from 'next/app'
import { useRouter } from 'next/router'
import Script from 'next/script'
import { DefaultSeo } from 'next-seo'
import { FC, useEffect } from 'react'
import { Provider as ReduxProvider } from 'react-redux'
import { WagmiConfig } from 'wagmi'

import { Updaters as MulticallUpdaters } from '../lib/state/MulticallUpdaters'
import { Updaters as TokenListUpdaters } from '../lib/state/TokenListsUpdaters'
import SEO from '../next-seo.config.mjs'
import store from '../store'

const MyApp: FC<AppProps> = ({ Component, pageProps }) => {
Expand Down Expand Up @@ -51,6 +53,7 @@ const MyApp: FC<AppProps> = ({ Component, pageProps }) => {
<ReduxProvider store={store}>
<ThemeProvider>
<App.Shell>
<DefaultSeo {...SEO} />
<Header />
<MulticallUpdaters chainIds={SUPPORTED_CHAINS} />
<TokenListUpdaters chainIds={SUPPORTED_CHAINS} />
Expand Down
Loading

0 comments on commit 1e2af0f

Please sign in to comment.