Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/implement swap routes #25

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5218830
chore: add wagmi/core, remove unused deps
toniocodo Aug 31, 2023
ac2de3d
fix: flatten abis structures
toniocodo Aug 31, 2023
661f9d9
feat: add Button action variant
toniocodo Aug 31, 2023
bebf5a7
feat: create oeth shared components, move ApyHeader
toniocodo Aug 31, 2023
9cc9d16
feat: routing WIP 🚧
toniocodo Sep 1, 2023
7ae33b2
feat: extract SwapApi type, add default implementation WIP🚧
toniocodo Sep 1, 2023
8c6d4a4
feat: replace infura with alchemy
toniocodo Sep 1, 2023
e830256
fix: proper api files
toniocodo Sep 1, 2023
6f6b437
feat: add curve sdk, add ethers adapters
toniocodo Sep 1, 2023
179d88e
fix: curve setup with alchemy, update env access
toniocodo Sep 1, 2023
94bf478
feat: add chain id to curve sdk
toniocodo Sep 1, 2023
b00840f
refactor: change redeem-mix for redeem-vault
toniocodo Sep 1, 2023
d83d00f
Add generated statics and abi generation
smitch88 Sep 1, 2023
437e007
Add in generation
smitch88 Sep 1, 2023
005f374
feat: add swap curve action, test sdk WIP🚧
toniocodo Sep 1, 2023
77e7063
Merge branch 'feat/implement-swap-routes' of github.com:OriginProtoco…
toniocodo Sep 1, 2023
dff57d6
feat: upgrade generate abis scripts
toniocodo Sep 2, 2023
b56c6bb
feat: refresh ABIs, add contracts script
toniocodo Sep 4, 2023
2b8c35f
feat: add swap curve action, add loading states
toniocodo Sep 4, 2023
5deb60c
feat: add wrap/unwrap estimates, zapper routes WIP 🚧
toniocodo Sep 4, 2023
c1e79e1
style: various changes based on Matt's feedback
dcodes05 Sep 5, 2023
e2a2efa
style: minor changes around input, output, top nav and apy cards
dcodes05 Sep 4, 2023
535b5c4
refactor: move oeth clients to libs
toniocodo Sep 5, 2023
d2664fc
fix: compute WOETH price
toniocodo Sep 5, 2023
e6d4ca4
feat: add utils addresses
toniocodo Sep 5, 2023
72592c5
feat: swap routes WIP 🚧
toniocodo Sep 5, 2023
bc03ae8
fix: use redeem for WOETH price
toniocodo Sep 5, 2023
972d400
feat: add console stats for curve calls
toniocodo Sep 5, 2023
9a3cdd0
Merge branch 'main' into feat/implement-swap-routes
toniocodo Sep 5, 2023
3f3544a
chore: move data-access to oeth/shared, update clients
toniocodo Sep 5, 2023
1a4d86a
feat: update README
toniocodo Sep 5, 2023
f434f67
Merge branch 'main' into feat/implement-swap-routes
toniocodo Sep 6, 2023
f240a9e
feat: add fork support, update deps
toniocodo Sep 6, 2023
4bf8ae7
feat: default to tenderly fork
toniocodo Sep 6, 2023
47bb19a
fix: topnav styles
dcodes05 Sep 6, 2023
163abec
fix: styles based on matt's feedback and style the tokeninput component
dcodes05 Sep 6, 2023
9849669
feat: support local and tenderly testing, add utilities
toniocodo Sep 7, 2023
d205d31
feat: update ABIs
toniocodo Sep 7, 2023
185daf4
feat: add protocol logos
toniocodo Sep 7, 2023
747b7a5
feat: update deps, adapt scripts
toniocodo Sep 7, 2023
51672e4
feat: swap routing WIP🚧
toniocodo Sep 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VITE_SUBSQUID_URL="https://squid.subsquid.io/origin-squid/v/v4/graphql"
# VITE_CUSTOM_RPC="https://rpc.tenderly.co/fork/751e79c6-6420-4ea9-ac13-1f6b20f318bc"
# VITE_CUSTOM_RPC="http://127.0.0.1:8545"
VITE_WALLET_CONNECT_PROJECT_ID=
VITE_INFURA_ID=
VITE_ALCHEMY_ID=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ yarn-error.log
testem.log
/typings

# generated
*-generated.ts

# System Files
.DS_Store
Thumbs.db
Expand Down
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Origin Defi

## Start any the app
## Setup environment

To start the development server run `nx serve ousd` or `nx serve oeth`. Open your browser and navigate to http://localhost:4200/. Happy coding!
Duplicate `.env` file to `.env.local` and fill the variables with your secrets, they will take precedence over the defaults.

## Start the app

To start the development server run `pnpm nx serve oeth` or `pnpm nx serve ousd`. Open your browser and navigate to http://localhost:4200/. Happy coding!

## Apps

| Status | Name | Nx project | Port | Public hosts |
|:------:|:-----|:-----------|:-----|:-------------|
| 🚧 | OETH | `oeth` | 4200 | [fleek]() |
| 🚧 | OUSD | `ousd` | 4201 | [fleek]() |

## Storybook

There is a shared storybook aggregator that can run all the stories across all the libraries, run
`pnpm storybook`. If you want to run storybook for one individual library (eg: ousd) simply run `pnpm nx storybook defi-ousd` (basically the command is `pnpm nx storybook name-of-the-lib`).
There is a shared storybook aggregator that can run all the stories across all the libraries, run `pnpm storybook`. If you want to run storybook for one individual library (eg: ousd) simply run `pnpm nx storybook defi-ousd` (basically the command is `pnpm nx storybook name-of-the-lib`).

## Translations

Expand All @@ -17,20 +27,20 @@ Basic translation setup was added to the repo. It might require some changes dep

To execute tasks with Nx use the following syntax:

```
nx <target> <project> <...options>
```bash
pnpm nx <target> <project> <...options>
```

You can also run multiple targets:

```
nx run-many -t <target1> <target2>
```bash
pnpm nx run-many -t <target1> <target2>
```

..or add `-p` to filter specific projects

```
nx run-many -t <target1> <target2> -p <proj1> <proj2>
```bash
pnpm nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/core-features/run-tasks).
2 changes: 1 addition & 1 deletion apps/oeth/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Container, Stack } from '@mui/material';
import { HistoryView } from '@origin/oeth/history';
import { ApyHeader } from '@origin/oeth/shared';
import { SwapView } from '@origin/oeth/swap';
import { WrapView } from '@origin/oeth/wrap';
import { Route, Routes } from 'react-router-dom';

import { ApyHeader } from './components/ApyHeader';
import { Topnav } from './components/Topnav';

export function App() {
Expand Down
63 changes: 0 additions & 63 deletions apps/oeth/src/clients/wagmi.ts

This file was deleted.

35 changes: 21 additions & 14 deletions apps/oeth/src/components/Topnav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Link as MuiLink,
Tab,
Tabs,
useMediaQuery,
useTheme,
} from '@mui/material';
import { OpenAccountModalButton } from '@origin/shared/providers';
Expand All @@ -17,6 +18,7 @@ import type { BoxProps } from '@mui/material';

export function Topnav(props: BoxProps) {
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down('md'));
const intl = useIntl();
const [value, setValue] = useState(0);

Expand All @@ -25,8 +27,10 @@ export function Topnav(props: BoxProps) {
component="nav"
sx={{
display: 'grid',
borderBlockEnd: { xs: 'none', md: '1px solid' },
borderColor: 'background.paper',
borderBlockEnd: {
xs: 'none',
md: '1px solid var(--mui-palette-background-paper)',
},
gap: { xs: 1, md: 10 },
alignItems: 'center',
backgroundColor: 'divider',
Expand All @@ -42,10 +46,6 @@ export function Topnav(props: BoxProps) {
xs: '1fr 1fr',
md: 'auto 1fr auto',
},
rowGap: {
xs: 1.5,
md: 0,
},
...props?.sx,
}}
>
Expand Down Expand Up @@ -83,6 +83,10 @@ export function Topnav(props: BoxProps) {
xs: 'span 2',
md: 'span 1',
},
marginBlockStart: {
xs: 4,
md: 0,
},
backgroundColor: 'transparent',
minHeight: 0,
overflow: 'visible',
Expand Down Expand Up @@ -146,8 +150,9 @@ export function Topnav(props: BoxProps) {
sx={{
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'stretch',
gap: { xs: 1, md: 2 },
'& > a': {
'& > a, & > *': {
fontSize: {
xs: '0.75rem',
md: '1rem',
Expand All @@ -161,11 +166,8 @@ export function Topnav(props: BoxProps) {
href="https://oeth.on.fleek.co/"
target="_blank"
sx={{
backgroundColor: 'background.paper',
borderRadius: 25,
paddingBlock: 1,
color: 'primary.contrastText',
boxShadow: (theme) => theme.shadows['24'],
paddingBlock: 0.75,
display: 'grid',
placeContent: 'center',
paddingInline: {
Expand All @@ -185,9 +187,12 @@ export function Topnav(props: BoxProps) {
background: (theme) => theme.palette.background.paper,
backgroundImage: 'none',
},
color: 'primary.contrastText',
boxSizing: 'border-box',
lineHeight: '1rem',
}}
>
{theme.breakpoints.down('md')
{isSmall
? intl.formatMessage({ defaultMessage: 'IPFS' })
: intl.formatMessage({ defaultMessage: 'View on IPFS' })}
</MuiLink>
Expand All @@ -198,9 +203,11 @@ export function Topnav(props: BoxProps) {
display: { xs: 'block', md: 'none' },
gridColumn: 'span 2',
gridRowStart: 1,
borderColor: 'background.paper',
borderColor: (theme) => theme.palette.background.paper,
position: 'relative',
bottom: '-4rem',
width: 'calc(100% + 1.5rem)',
bottom: '-3.75rem',
left: '-0.75rem',
}}
/>
</Box>
Expand Down
4 changes: 3 additions & 1 deletion apps/oeth/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

interface ImportMetaEnv {
readonly VITE_WALLET_CONNECT_PROJECT_ID: string;
readonly VITE_INFURA_ID: string;
readonly VITE_ALCHEMY_ID: string;
readonly VITE_SUBSQUID_URL: string;
readonly VITE_CUSTOM_RPC?: string;
}

interface ImportMeta {
Expand Down
14 changes: 13 additions & 1 deletion apps/oeth/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import {
CssBaseline,
Experimental_CssVarsProvider as CssVarsProvider,
} from '@mui/material';
import { chains, queryClient, wagmiConfig } from '@origin/oeth/shared';
import { CurveProvider } from '@origin/shared/providers';
import { theme } from '@origin/shared/theme';
import { composeContexts } from '@origin/shared/utils';
import { darkTheme, RainbowKitProvider } from '@rainbow-me/rainbowkit';
import { QueryClientProvider } from '@tanstack/react-query';
import { setAutoFreeze } from 'immer';
import { IntlProvider } from 'react-intl';
import { BrowserRouter } from 'react-router-dom';
import { WagmiConfig } from 'wagmi';

import { App } from './App';
import { chains, queryClient, wagmiConfig } from './clients';
import { en } from './lang';

// https://github.com/dai-shi/proxy-compare/pull/8
setAutoFreeze(false);

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement,
);
Expand All @@ -33,6 +38,13 @@ root.render(
[CssVarsProvider, { theme: theme, defaultMode: 'dark' }],
[WagmiConfig, { config: wagmiConfig }],
[RainbowKitProvider, { chains: chains, theme: darkTheme() }],
[
CurveProvider,
{
alchemyApiKey: import.meta.env.VITE_ALCHEMY_ID,
customRpcUrl: import.meta.env.VITE_CUSTOM_RPC,
},
],
],
<>
<CssBaseline />
Expand Down
12 changes: 4 additions & 8 deletions apps/ousd/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
CssBaseline,
Experimental_CssVarsProvider as CssVarsProvider,
} from '@mui/material';
import { queryClient } from '@origin/shared/data-access';
import { theme } from '@origin/shared/theme';
import { QueryClientProvider } from '@tanstack/react-query';
import { IntlProvider } from 'react-intl';

import { OUSDRoot } from './components';
Expand All @@ -19,12 +17,10 @@ const root = ReactDOM.createRoot(
root.render(
<StrictMode>
<IntlProvider messages={en} locale="en" defaultLocale="en">
<QueryClientProvider client={queryClient}>
<CssVarsProvider theme={theme} defaultMode="dark">
<CssBaseline />
<OUSDRoot />
</CssVarsProvider>
</QueryClientProvider>
<CssVarsProvider theme={theme} defaultMode="dark">
<CssBaseline />
<OUSDRoot />
</CssVarsProvider>
</IntlProvider>
</StrictMode>,
);
6 changes: 3 additions & 3 deletions apps/ousd/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import viteTsConfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
cacheDir: '../../node_modules/.vite/ousd',

server: {
port: 4200,
port: 4201,
host: 'localhost',
},

preview: {
port: 4300,
port: 4301,
host: 'localhost',
},

Expand Down
8 changes: 5 additions & 3 deletions libs/defi/oeth/src/components/Swap/GasPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {
} from '@mui/material';
import { useIntl } from 'react-intl';

import type { Theme } from '@mui/material';
import type { SxProps } from '@mui/material';

const defaultPriceTolerance = 0.01;

const gridStyles = {
display: 'grid',
gridTemplateColumns: (theme: Theme) => `1.5fr 1fr`,
gridTemplateColumns: `1.5fr 1fr`,
gap: 1,
justifyContent: 'space-between',
alignItems: 'center',
Expand All @@ -32,9 +32,10 @@ const gridStyles = {
interface Props {
gasPrice: number;
onPriceToleranceChange: (value: number) => void;
sx?: SxProps;
}

export function GasPopover({ gasPrice, onPriceToleranceChange }: Props) {
export function GasPopover({ gasPrice, onPriceToleranceChange, sx }: Props) {
const theme = useTheme();
const intl = useIntl();
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
Expand All @@ -48,6 +49,7 @@ export function GasPopover({ gasPrice, onPriceToleranceChange }: Props) {
<IconButton
onClick={(e) => setAnchorEl(e.currentTarget)}
data-testid="gas-popover-button"
sx={{ ...sx }}
>
<img src="/images/settings-icon.svg" />
</IconButton>
Expand Down
Loading