Skip to content

Commit

Permalink
Merge pull request #75 from compolabs/uni-market
Browse files Browse the repository at this point in the history
Uni market
  • Loading branch information
PaulZhemanov authored Feb 26, 2024
2 parents 6dcd30c + 4c48531 commit 9e1ae41
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 56 deletions.
1 change: 1 addition & 0 deletions services/spark-matcher-evm/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export const PORT = loadVar("PORT", true);
export const PRIVATE_KEY = loadVar("PRIVATE_KEY");
export const CONTRACT_ADDRESS = loadVar("CONTRACT_ADDRESS");
export const NODE_URL = loadVar("NODE_URL");
export const MARKET = loadVar("MARKET");
6 changes: 6 additions & 0 deletions services/spark-matcher-evm/src/constants/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
"symbol": "USDC",
"decimals": 6,
"assetId": "0x6943ee384c0f1ea9c58c2ded573a8146e3e0f66e"
},
{
"name": "Uniswap",
"symbol": "UNI",
"decimals": 9,
"assetId": "0xb86d06a89abd27d2daf7967d88a12f343673d2c0"
}
]
6 changes: 3 additions & 3 deletions services/spark-matcher-evm/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PORT } from "./config";
import { MARKET, PORT } from "./config";
import { app } from "./app";
import { schedule } from "node-cron";
import { TOKENS_BY_SYMBOL } from "./constants";
Expand All @@ -22,7 +22,7 @@ class SparkMatcher {
}

public doMatch = async () => {
const market = TOKENS_BY_SYMBOL.BTC.assetId;
const market = TOKENS_BY_SYMBOL[MARKET].assetId;

let [buyOrders, sellOrders]: [SpotMarketOrder[], SpotMarketOrder[]] = await Promise.all([
this.spotMarket.getOrders({ market, limit: 100, type: "BUY" }),
Expand Down Expand Up @@ -63,6 +63,6 @@ class SparkMatcher {
}

const matcher = new SparkMatcher();
matcher.run("*/20 * * * * *");
matcher.run("*/30 * * * * *");

app.listen(PORT ?? 5000, () => console.log(print));
6 changes: 3 additions & 3 deletions services/spark-matcher-evm/src/utils/fetchIndexer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import axios from "axios";

export const INDEXER_URLS = [
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-3/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-2/version/latest",
"https://api.studio.thegraph.com/query/63182/spark-arbitrum-spor-market/version/latest",
"https://api.studio.thegraph.com/query/63182/arbitrum-sepolia-spot-market/version/latest",
"https://api.studio.thegraph.com/query/63182/spark-arbitrum-spor-market/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-2/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-3/version/latest",
];

export const fetchIndexer = async (query: string) => {
Expand Down
5 changes: 3 additions & 2 deletions services/spark-matcher-evm/src/utils/print.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PORT } from "../config";
import { MARKET, PORT } from "../config";

export const print = `
Expand All @@ -16,4 +16,5 @@ export const print = `
███████╗██║ ██║██████╔╝███████║
╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝
${"🚀 Server ready at: http://localhost:" + (PORT ?? 5000)} \n`;
${"🚀 Server ready at: http://localhost:" + (PORT ?? 5000)}
${"🛒 Market: " + MARKET}-USDC\n`;
8 changes: 4 additions & 4 deletions spark-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion spark-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@emotion/styled": "^11.11.0",
"@ethersproject/bignumber": "^5.7.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
"@pythnetwork/pyth-evm-js": "^1.32.0",
"@pythnetwork/pyth-evm-js": "^1.33.0",
"@svgr/webpack": "^5.5.0",
"@szhsin/react-accordion": "^1.2.3",
"@testing-library/jest-dom": "^5.17.0",
Expand Down
5 changes: 5 additions & 0 deletions spark-frontend/src/assets/icons/sparkLogoIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion spark-frontend/src/assets/tokens/uni.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions spark-frontend/src/components/TokenInput/TokenInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface IProps {
readOnly?: boolean;
}

const TokenInput: React.FC<IProps> = (props) => {
const TokenInput: React.FC<IProps> = observer((props) => {
const [focused, setFocused] = useState(false);
const [amount, setAmount] = useState<BN>(props.amount);
useEffect(() => {
Expand Down Expand Up @@ -92,9 +92,9 @@ const TokenInput: React.FC<IProps> = (props) => {
)}
</Root>
);
};
});

export default observer(TokenInput);
export default TokenInput;

const Root = styled.div`
display: flex;
Expand Down
6 changes: 3 additions & 3 deletions spark-frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export const TV_DATAFEED = "https://spark-tv-datafeed.spark-defi.com/api/v1";
export const CHARTS_STORAGE = "https://tv-backend-v4.herokuapp.com/";

export const INDEXER_URLS = [
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-3/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-2/version/latest",
"https://api.studio.thegraph.com/query/63182/spark-arbitrum-spor-market/version/latest",
"https://api.studio.thegraph.com/query/63182/arbitrum-sepolia-spot-market/version/latest",
"https://api.studio.thegraph.com/query/63182/spark-arbitrum-spor-market/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-2/version/latest",
"https://api.studio.thegraph.com/query/65658/spark-arbitrum-spor-market-3/version/latest",
];
export const INDEXER_URL = INDEXER_URLS[0];

Expand Down
7 changes: 7 additions & 0 deletions spark-frontend/src/constants/tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
"decimals": 6,
"assetId": "0x6943ee384c0f1ea9c58c2ded573a8146e3e0f66e",
"priceFeed": "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a"
},
{
"name": "Uniswap",
"symbol": "UNI",
"decimals": 9,
"assetId": "0xb86d06a89abd27d2daf7967d88a12f343673d2c0",
"priceFeed": "0x78d185a741d07edb3412b09008b7c5cfb9bbbd7d568bf00ba737b456ba171501"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { useTheme } from "@emotion/react";
import styled from "@emotion/styled";
import { observer } from "mobx-react";

import { useStores } from "@stores";

let tvScriptLoadingPromise: Promise<any>;

const TradingViewWidget = observer(() => {
const onLoadScriptRef = useRef();

const theme = useTheme();
const { tradeStore } = useStores();

useEffect(() => {
(onLoadScriptRef as any).current = createWidget;
Expand All @@ -31,11 +34,12 @@ const TradingViewWidget = observer(() => {
(onLoadScriptRef as any).current = null;
};

function createWidget(symbol?: string) {
if (document.getElementById("tradingview_3f939") && "TradingView" in window) {
function createWidget() {
if (tradeStore.market !== undefined && document.getElementById("tradingview_3f939") && "TradingView" in window) {
new (window as any).TradingView.widget({
autosize: true,
symbol: "OKX:BTCUSDC",
// symbol: "OKX:BTCUSDC",
symbol: `OKX:${tradeStore.market.baseToken.symbol}${tradeStore.market.quoteToken.symbol}`,
interval: "30",
timezone: "Etc/UTC",
theme: "dark",
Expand All @@ -51,7 +55,7 @@ const TradingViewWidget = observer(() => {
});
}
}
}, [theme]);
}, [theme, tradeStore.market]);

return (
<Root className="tradingview-widget-container">
Expand Down
Loading

0 comments on commit 9e1ae41

Please sign in to comment.