Skip to content

Commit

Permalink
[CoW AMM Deployer] Integrate advanced mode for price oracles (#671)
Browse files Browse the repository at this point in the history
* add custom oracle feature

* chore: add bleu ui

* remove unused context

* chore: use bleu ui toaster

* refactor: separete price oracle inputs into new files

* chore: add npm token on github pnpm setup action

* wip: move .npmrc to repo root

* chore: remove rainbowkit colors from milkman project

* chore: add missing dependencies on balancer tools

* add npm_token input on all workflows

* add input into setup-pnpm workflow

* chore: run formatter

* chore: rename @bleu-fi/ui to @bleu/ui due to org name change

* remove bleu-ui from tsconfig

* chore: use try and catch patern and change tooltip texts

* [CoW AMM Deployer] Integrate sushi into application (#672)

* add sushi gql

* add sushiswap pricechecker component

* run lint

* refactor apr paths

* apr: update viem

* apr: fix ts errors

* add chainlink-datafeeds-api app

* chore(deps-dev): bump @graphql-codegen/client-preset from 4.2.5 to 4.2.6 (#675)

Bumps [@graphql-codegen/client-preset](https://github.com/dotansimha/graphql-code-generator/tree/HEAD/packages/presets/client) from 4.2.5 to 4.2.6.
- [Release notes](https://github.com/dotansimha/graphql-code-generator/releases)
- [Changelog](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/presets/client/CHANGELOG.md)
- [Commits](https://github.com/dotansimha/graphql-code-generator/commits/@graphql-codegen/[email protected]/packages/presets/client)

---
updated-dependencies:
- dependency-name: "@graphql-codegen/client-preset"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* remove unneeded files in chainlink api

* add chainlink-datafeeds-api url

* add price information of new oracles

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: José Ribeiro <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* merge into main

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: José Ribeiro <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 17, 2024
1 parent a9e737b commit 49d65d9
Show file tree
Hide file tree
Showing 130 changed files with 29,041 additions and 6,928 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- uses: actions/checkout@v3

- uses: ./.github/workflows/setup-pnpm
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Check formatting and linting
run: pnpm run ci
Expand All @@ -35,6 +37,8 @@ jobs:
- uses: actions/checkout@v3

- uses: ./.github/workflows/setup-pnpm
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Run tests
run: pnpm test:jest
2 changes: 2 additions & 0 deletions .github/workflows/contracts-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
submodules: recursive

- uses: ./.github/workflows/setup-pnpm
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/daily-apr-seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:

- name: Set up pnpm
uses: ./.github/workflows/setup-pnpm
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Install Dependencies
run: pnpm install
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- uses: actions/checkout@v3

- uses: ./.github/workflows/setup-pnpm
with:
npm_token: ${{ secrets.NPM_TOKEN }}

- name: Install node
uses: actions/setup-node@v1
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/setup-pnpm/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: setup JS dependencies
inputs:
npm_token:
description: "NPM token for authentication"
required: true
runs:
using: composite
steps:
Expand All @@ -9,5 +13,8 @@ runs:
with:
node-version-file: ".tool-versions"
cache: "pnpm"
- run: pnpm install --frozen-lockfile
- name: Install dependencies
run: pnpm install --frozen-lockfile
shell: bash
env:
NPM_TOKEN: ${{ inputs.npm_token }}
7 changes: 7 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
auto-install-peers=true
strict-peer-dependencies=false

; Yarn Node Linker
node-linker=node-modules

; Scoped Registry Configuration for bleu-fi
@bleu:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
5 changes: 3 additions & 2 deletions apps/balancer-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,23 @@
"@rainbow-me/rainbowkit": "1.3.1",
"@sentry/nextjs": "^7.91.0",
"@sentry/profiling-node": "^1.3.2",
"@sentry/utils": "^8.0.0",
"@wagmi/cli": "1.5.2",
"@wagmi/core": "^1.4.12",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"copy-to-clipboard": "^3.3.3",
"date-fns": "^2.30.0",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.29.3",
"downshift": "^8.2.3",
"drizzle-orm": "^0.29.3",
"fathom-client": "^3.6.0",
"graphql-request": "6.1.0",
"lodash": "^4.17.21",
"lodash.merge": "^4.6.2",
"next": "^14.0.4",
"postgres": "^3.4.3",
"plotly.js": "^2.27.1",
"postgres": "^3.4.3",
"react": "^18.3.1",
"react-day-picker": "^8.9.1",
"react-dom": "^18.3.1",
Expand Down
1 change: 1 addition & 0 deletions apps/cow-amm-deployer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"dependencies": {
"@bleu-fi/gql": "workspace:*",
"@bleu-fi/tsconfig": "workspace:*",
"@bleu/ui": "^0.1.93",
"@cowprotocol/app-data": "^2.0.2",
"@gnosis.pm/safe-apps-react-sdk": "^4.6.2",
"@gnosis.pm/safe-apps-sdk": "^7.8.0",
Expand Down
16 changes: 1 addition & 15 deletions apps/cow-amm-deployer/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import "#/global.css";
import "@rainbow-me/rainbowkit/styles.css";

import { Metadata } from "next";
import localFont from "next/font/local";
import * as React from "react";

import { Footer } from "#/components/Footer";
import { Header } from "#/components/Header";
import { RootLayout } from "#/components/RootLayout";
import { NetworksContextProvider } from "#/contexts/networks";
import { cn } from "#/lib/utils";

const APP_DISPLAY_NAME = "CoW AMM Manager";
Expand Down Expand Up @@ -66,17 +62,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
"bg-background flex h-full flex-col font-sans font-normal text-foreground",
)}
>
<RootLayout>
<NetworksContextProvider>
<div className="flex flex-col h-screen">
<Header linkUrl={"/"} imageSrc={"/assets/cow-amm-deployer.svg"} />
<div className="flex flex-1 overflow-auto p-4 sm:flex-row sm:gap-x-8 text-foreground">
{children}
</div>
<Footer twitterLink="https://twitter.com/cowswap" />
</div>
</NetworksContextProvider>
</RootLayout>
<RootLayout>{children}</RootLayout>
</body>
</html>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { NetworkFromNetworkChainId } from "@bleu-fi/utils";
import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk";
import { ArrowTopRightIcon } from "@radix-ui/react-icons";
import Link from "next/link";

import { ICowAmm } from "#/lib/types";
import { ChainId } from "#/utils/chainsPublicClients";

export function BalancerPriceInformation({ cowAmm }: { cowAmm: ICowAmm }) {
const { safe } = useSafeAppsSDK();

const priceOracleLink = getBalancerPoolUrl(
safe.chainId as ChainId,
cowAmm.priceOracleData?.balancerPoolId,
);

return (
<div className="flex flex-row gap-x-1 items-center hover:text-foreground/90">
<span>Using price information from Balancer V2</span>
{priceOracleLink && (
<Link href={priceOracleLink} target="_blank">
<ArrowTopRightIcon />
</Link>
)}
</div>
);
}

export function getBalancerPoolUrl(chainId: ChainId, poolId?: string) {
return `https://app.balancer.fi/#/${NetworkFromNetworkChainId[chainId]}-chain/pool/${poolId}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { buildBlockExplorerAddressURL } from "@bleu-fi/utils";
import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk";
import { ArrowTopRightIcon } from "@radix-ui/react-icons";
import Link from "next/link";

import { ICowAmm } from "#/lib/types";
import { ChainId } from "#/utils/chainsPublicClients";

export function CustomPriceInformation({ cowAmm }: { cowAmm: ICowAmm }) {
const { safe } = useSafeAppsSDK();

const priceOracleLink = buildBlockExplorerAddressURL({
chainId: safe.chainId as ChainId,
address: cowAmm.priceOracleAddress,
});

return (
<div className="flex flex-row gap-x-1 items-center hover:text-foreground/90">
<span>Using price information from custom contract</span>
{priceOracleLink && (
<Link href={priceOracleLink.url} target="_blank">
<ArrowTopRightIcon />
</Link>
)}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ICowAmm, PRICE_ORACLES } from "#/lib/types";

import { BalancerPriceInformation } from "./BalancerPriceInformation";
import { CustomPriceInformation } from "./CustomPriceInformation";
import { SushiV2PriceInformation } from "./SushiV2PriceInformation";
import { UniswapV2PriceInformation } from "./UniswapV2PriceInformation";

export function PriceInformation({ cowAmm }: { cowAmm: ICowAmm }) {
switch (cowAmm.priceOracle) {
case PRICE_ORACLES.UNI:
return <UniswapV2PriceInformation cowAmm={cowAmm} />;
case PRICE_ORACLES.BALANCER:
return <BalancerPriceInformation cowAmm={cowAmm} />;
case PRICE_ORACLES.SUSHI:
return <SushiV2PriceInformation cowAmm={cowAmm} />;
default:
return <CustomPriceInformation cowAmm={cowAmm} />;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk";
import { ArrowTopRightIcon } from "@radix-ui/react-icons";
import Link from "next/link";

import { ICowAmm } from "#/lib/types";
import { ChainId } from "#/utils/chainsPublicClients";

export function SushiV2PriceInformation({ cowAmm }: { cowAmm: ICowAmm }) {
const { safe } = useSafeAppsSDK();

const priceOracleLink = getSushiV2Pair(
safe.chainId as ChainId,
cowAmm.priceOracleData?.sushiSwapPairAddress,
);

return (
<div className="flex flex-row gap-x-1 items-center hover:text-foreground/90">
<span>Using price information from Sushi V2</span>
{priceOracleLink && (
<Link href={priceOracleLink} target="_blank">
<ArrowTopRightIcon />
</Link>
)}
</div>
);
}

export function getSushiV2Pair(chainId: ChainId, referencePair?: string) {
return `https://www.sushi.com/pool/${[chainId]}%3A${referencePair}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NetworkFromNetworkChainId } from "@bleu-fi/utils";
import { useSafeAppsSDK } from "@gnosis.pm/safe-apps-react-sdk";
import { ArrowTopRightIcon } from "@radix-ui/react-icons";
import Link from "next/link";
import { gnosis } from "viem/chains";

import { ICowAmm } from "#/lib/types";
import { ChainId } from "#/utils/chainsPublicClients";

export function UniswapV2PriceInformation({ cowAmm }: { cowAmm: ICowAmm }) {
const { safe } = useSafeAppsSDK();

const priceOracleLink = getUniV2PairUrl(
safe.chainId as ChainId,
cowAmm.priceOracleData?.uniswapV2PairAddress,
);

return (
<div className="flex flex-row gap-x-1 items-center hover:text-foreground/90">
<span>Using price information from Uniswap V2</span>
{priceOracleLink && (
<Link href={priceOracleLink} target="_blank">
<ArrowTopRightIcon />
</Link>
)}
</div>
);
}

export function getUniV2PairUrl(chainId: ChainId, referencePair?: string) {
if (chainId === gnosis.id) {
return;
}
return `https://info.uniswap.org/#/${NetworkFromNetworkChainId[chainId]}/pools/${referencePair}`;
}
24 changes: 2 additions & 22 deletions apps/cow-amm-deployer/src/app/manager/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import { useRawTxData } from "#/hooks/useRawTxData";
import { useRunningAMM } from "#/hooks/useRunningAmmInfo";
import { buildAccountCowExplorerUrl } from "#/lib/cowExplorer";
import { TRANSACTION_TYPES } from "#/lib/transactionFactory";
import { PRICE_ORACLES } from "#/lib/types";
import { getBalancerPoolUrl } from "#/utils/balancerPoolUrl";
import { ChainId, supportedChainIds } from "#/utils/chainsPublicClients";
import { getUniV2PairUrl } from "#/utils/univ2pairUrl";

import { UnsuportedChain } from "../../components/UnsuportedChain";
import { PoolCompositionTable } from "./(components)/PoolCompositionTable";
import { PriceInformation } from "./(components)/PriceInformation";

export default function Page() {
const router = useRouter();
Expand All @@ -54,17 +52,6 @@ export default function Page() {
redirect("/new");
}

const priceOracleLink =
cowAmm.priceOracle === PRICE_ORACLES.BALANCER
? getBalancerPoolUrl(
safe.chainId as ChainId,
cowAmm.priceOracleData?.balancerPoolId,
)
: getUniV2PairUrl(
safe.chainId as ChainId,
cowAmm.priceOracleData?.uniswapV2PairAddress,
);

return (
<div className="flex w-full justify-center">
<Dialog
Expand Down Expand Up @@ -105,14 +92,7 @@ export default function Page() {
The first <i className="text-purple">MEV-Capturing AMM</i>,
brought to you by <i className="text-yellow">CoW DAO</i>{" "}
</h2>
<div className="flex flex-row gap-x-1 items-center hover:text-foreground/90">
<span>Using price information from {cowAmm.priceOracle}</span>
{priceOracleLink && (
<Link href={priceOracleLink} target="_blank">
<ArrowTopRightIcon />
</Link>
)}
</div>
<PriceInformation cowAmm={cowAmm} />
</div>
<div className="flex flex-col bg-yellow/40 text-foreground py-2 px-8">
<span className="text-sm">Total Value</span>
Expand Down
Loading

0 comments on commit 49d65d9

Please sign in to comment.