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

Upgrading (#97) #101

Open
wants to merge 23 commits into
base: migrate-to-native-usdt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
50cbadc
Setup to migrate from wrapped Sollet USDT to Native USDT (#66)
nathanielparke Mar 19, 2021
e1055ec
Bump serum package version
nathanielparke Mar 19, 2021
3b99d25
Bump serum package version to v0.13.29
nathanielparke Mar 19, 2021
5b44876
Improve error parsing by using parseInstructionErrorResponse
nathanielparke Mar 20, 2021
94ef37a
Add support for the Sollet Extension (#68)
jhlx Mar 29, 2021
e1feabd
Upgrade serum-ts version
nathanielparke Mar 31, 2021
23f1032
Update serum-ts package
nathanielparke Apr 1, 2021
7c5e888
Update PhantomWalletAdapter in serum (#71)
fragosti Apr 6, 2021
f55a837
Bump sol-wallet-adapter to v0.2.0
armaniferrante Apr 20, 2021
fd8c341
fix: market selector non unique key issue
Apr 21, 2021
1d37d4c
Merge pull request #73 from dr497/fix-market-selector
dr497 Apr 21, 2021
0f5f04f
Conserve calls to getAccountInfo (#74)
nathanielparke Apr 30, 2021
a285181
Batch settle (#80)
nathanielparke May 6, 2021
0b0f0a2
Update @project-serum/serum to v0.13.36
nathanielparke May 21, 2021
1b6281e
Update @project-serum/serum to v0.13.37
nathanielparke May 22, 2021
87b3a6f
Disable auto settle
armaniferrante May 24, 2021
78e3ec9
Finish disabling auto settle
armaniferrante May 24, 2021
66175e0
Remove solong wallet
May 27, 2021
5b7d5e3
Upgrade serum-ts package
nathanielparke May 29, 2021
0169104
Use solscan.io as explorer (#93)
thanhnguyennguyen Jun 21, 2021
1fb68a5
Bump @project-serum/serum to 0.13.41
nathanielparke Jun 30, 2021
c098b44
Create associated token accounts (#96)
armaniferrante Jul 2, 2021
7b7afc8
allow ref link (#97)
dr497 Jul 3, 2021
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
2 changes: 2 additions & 0 deletions .env → .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
REACT_APP_USDT_REFERRAL_FEES_ADDRESS=''
REACT_APP_USDC_REFERRAL_FEES_ADDRESS=''
REACT_APP_ALLOW_REF_LINK=true
REACT_APP_EXCLUDE_MARKETS=[]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ yarn-debug.log*
yarn-error.log*

.idea

.env
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"@project-serum/associated-token": "0.1.0",
"@project-serum/awesome-serum": "1.0.1",
"@project-serum/pool": "0.2.2",
"@project-serum/serum": "^0.13.25",
"@project-serum/sol-wallet-adapter": "^0.1.1",
"@project-serum/serum": "^0.13.41",
"@project-serum/sol-wallet-adapter": "^0.2.0",
"@solana/spl-name-service": "^0.1.2",
"@solana/spl-token": "^0.1.6",
"@solana/web3.js": "0.86.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
Expand All @@ -26,7 +28,9 @@
"bn.js": "^5.1.3",
"craco-less": "^1.17.0",
"immutable-tuple": "^0.4.10",
"nanoid": "^3.1.22",
"qrcode.react": "^1.0.0",
"query-string": "^7.0.1",
"react": "^16.13.1",
"react-app-polyfill": "^1.0.5",
"react-copy-to-clipboard": "^5.0.2",
Expand Down
17 changes: 10 additions & 7 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import { Spin } from 'antd';
import ErrorBoundary from './components/ErrorBoundary';
import { Routes } from './routes';
import { PreferencesProvider } from './utils/preferences';
import { ReferrerProvider } from './utils/referrer';

export default function App() {
return (
<Suspense fallback={() => <Spin size="large" />}>
<GlobalStyle />
<ErrorBoundary>
<ConnectionProvider>
<WalletProvider>
<PreferencesProvider>
<Suspense fallback={() => <Spin size="large" />}>
<Routes />
</Suspense>
</PreferencesProvider>
</WalletProvider>
<ReferrerProvider>
<WalletProvider>
<PreferencesProvider>
<Suspense fallback={() => <Spin size="large" />}>
<Routes />
</Suspense>
</PreferencesProvider>
</WalletProvider>
</ReferrerProvider>
</ConnectionProvider>
</ErrorBoundary>
</Suspense>
Expand Down
2 changes: 1 addition & 1 deletion src/components/AppSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const appsAndTokens = apps.concat(
TOKEN_MINTS.map((mint) => {
return {
name: `${mint.name} SPL`,
url: `https://explorer.solana.com/address/${mint.address.toBase58()}`,
url: `https://solscan.io/address/${mint.address.toBase58()}`,
description: `${mint.name} SPL token`,
icon: '',
tags: [
Expand Down
17 changes: 16 additions & 1 deletion src/components/BasicLayout.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import { Layout } from 'antd';
import React from 'react';
import React, { useEffect } from 'react';
import TopBar from './TopBar';
import { CustomFooter as Footer } from './Footer';
import { useReferrer } from '../utils/referrer';
import queryString from 'query-string';
import { useLocation } from 'react-router-dom';
import { notify } from '../utils/notifications';
const { Header, Content } = Layout;

export default function BasicLayout({ children }) {
const { refCode, setRefCode, allowRefLink } = useReferrer();
const { search } = useLocation();
const parsed = queryString.parse(search);

useEffect(() => {
if (!!parsed.refCode && parsed.refCode !== refCode && allowRefLink) {
notify({ message: `New referrer ${parsed.refCode} added` });
setRefCode(parsed.refCode);
}
}, [parsed, refCode, setRefCode, allowRefLink]);

return (
<React.Fragment>
<Layout
Expand Down
8 changes: 4 additions & 4 deletions src/components/DeprecatedMarketsInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ export default function DeprecatedMarketsInstructions({ switchToLiveMarkets }) {
return (
<FloatingElement>
<Title level={4} style={{ color: 'rgba(255, 255, 255, 1)' }}>
Migrate to Serum DEX V3 markets
Migrate new markets
</Title>
<Typography>
Markets on older versions of the DEX are now deprecated. To migrate over
to the new markets, please cancel your orders and settle your funds on
old markets.
Markets on older versions of the DEX or using Wrapped USDT are now deprecated. To migrate over
to the new markets, please cancel your orders and settle your funds on old markets. To convert
from Wrapped USDT to Native USDT use sollet.io.
</Typography>
<div style={{ marginTop: 20, display: 'flex', justifyContent: 'center' }}>
<Button onClick={() => refresh(true)}>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { Layout, Row, Col, Grid } from 'antd';
import Link from './Link';
import { helpUrls } from './HelpUrls';
import { useReferrer } from '../utils/referrer';
const { Footer } = Layout;
const { useBreakpoint } = Grid;

Expand All @@ -19,15 +20,18 @@ const footerElements = [

export const CustomFooter = () => {
const smallScreen = !useBreakpoint().lg;

const { refCode, allowRefLink } = useReferrer();
return (
<Footer
style={{
height: '45px',
height: '55px',
paddingBottom: 10,
paddingTop: 10,
}}
>
{refCode && allowRefLink && (
<Row justify="center">Your referrer is {refCode}</Row>
)}
<Row align="middle" gutter={[16, 4]}>
{!smallScreen && (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/components/LinkAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function LinkAddress({
<Button
type="link"
icon={<LinkOutlined />}
href={'https://explorer.solana.com/address/' + address}
href={'https://solscan.io/address/' + address}
target="_blank"
rel="noopener noreferrer"
style={{ cursor: 'pointer' }}
Expand Down
54 changes: 53 additions & 1 deletion src/components/StandaloneBalancesDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import { Balances } from '../utils/types';
import StandaloneTokenAccountsSelect from './StandaloneTokenAccountSelect';
import LinkAddress from './LinkAddress';
import { InfoCircleOutlined } from '@ant-design/icons';
import { useInterval } from '../utils/useInterval';
import { useLocalStorageState } from '../utils/utils';
import { AUTO_SETTLE_DISABLED_OVERRIDE } from '../utils/preferences';
import { useReferrer } from '../utils/referrer';

const RowBox = styled(Row)`
padding-bottom: 20px;
Expand Down Expand Up @@ -50,7 +54,9 @@ export default function StandaloneBalancesDisplay() {
balances && balances.find((b) => b.coin === baseCurrency);
const quoteCurrencyBalances =
balances && balances.find((b) => b.coin === quoteCurrency);

const [autoSettleEnabled] = useLocalStorageState('autoSettleEnabled', true);
const [lastSettledAt, setLastSettledAt] = useState<number>(0);
const { usdcRef, usdtRef } = useReferrer();
async function onSettleFunds() {
if (!wallet) {
notify({
Expand Down Expand Up @@ -102,6 +108,8 @@ export default function StandaloneBalancesDisplay() {
wallet,
baseCurrencyAccount,
quoteCurrencyAccount,
usdcRef,
usdtRef,
});
} catch (e) {
notify({
Expand All @@ -112,6 +120,50 @@ export default function StandaloneBalancesDisplay() {
}
}

useInterval(() => {
const autoSettle = async () => {
if (
AUTO_SETTLE_DISABLED_OVERRIDE ||
!wallet ||
!market ||
!openOrdersAccount ||
!baseCurrencyAccount ||
!quoteCurrencyAccount ||
!autoSettleEnabled
) {
return;
}
if (
!baseCurrencyBalances?.unsettled &&
!quoteCurrencyBalances?.unsettled
) {
return;
}
if (Date.now() - lastSettledAt < 15000) {
return;
}
try {
console.log('Settling funds...');
setLastSettledAt(Date.now());
await settleFunds({
market,
openOrders: openOrdersAccount,
connection,
wallet,
baseCurrencyAccount,
quoteCurrencyAccount,
usdcRef,
usdtRef,
});
} catch (e) {
console.log('Error auto settling funds: ' + e.message);
return;
}
console.log('Finished settling funds.');
};
connected && wallet?.autoApprove && autoSettleEnabled && autoSettle();
}, 1000);

const formattedBalances: [
string | undefined,
Balances | undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const EXTERNAL_LINKS = {
'/wallet-support': 'https://serum-academy.com/en/wallet-support',
'/dex-list': 'https://serum-academy.com/en/dex-list/',
'/developer-resources': 'https://serum-academy.com/en/developer-resources/',
'/explorer': 'https://explorer.solana.com',
'/explorer': 'https://solscan.io',
'/srm-faq': 'https://projectserum.com/srm-faq',
'/swap': 'https://swap.projectserum.com',
};
Expand Down
32 changes: 14 additions & 18 deletions src/components/TradeForm.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import { Button, Input, Radio, Switch, Slider } from 'antd';
import React, { useState, useEffect } from 'react';
import {Button, Input, Radio, Slider, Switch} from 'antd';
import React, {useEffect, useState} from 'react';
import styled from 'styled-components';
import {
useSelectedBaseCurrencyBalances,
useSelectedQuoteCurrencyBalances,
useFeeDiscountKeys,
useLocallyStoredFeeDiscountKey,
useMarket,
useMarkPrice,
useSelectedOpenOrdersAccount,
useSelectedBaseCurrencyAccount,
useSelectedBaseCurrencyBalances,
useSelectedOpenOrdersAccount,
useSelectedQuoteCurrencyAccount,
useFeeDiscountKeys,
useLocallyStoredFeeDiscountKey,
useSelectedQuoteCurrencyBalances,
} from '../utils/markets';
import { useWallet } from '../utils/wallet';
import { notify } from '../utils/notifications';
import {
getDecimalCount,
roundToDecimal,
floorToDecimal,
} from '../utils/utils';
import { useSendConnection } from '../utils/connection';
import {useWallet} from '../utils/wallet';
import {notify} from '../utils/notifications';
import {floorToDecimal, getDecimalCount, roundToDecimal,} from '../utils/utils';
import {useSendConnection} from '../utils/connection';
import FloatingElement from './layout/FloatingElement';
import { getUnixTs, placeOrder } from '../utils/send';
import { SwitchChangeEventHandler } from 'antd/es/switch';
import { refreshCache } from '../utils/fetch-loop';
import {getUnixTs, placeOrder} from '../utils/send';
import {SwitchChangeEventHandler} from 'antd/es/switch';
import {refreshCache} from '../utils/fetch-loop';
import tuple from 'immutable-tuple';

const SellButton = styled(Button)`
Expand Down
4 changes: 4 additions & 0 deletions src/components/UserInfoTable/BalancesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useSendConnection } from '../../utils/connection';
import { useWallet } from '../../utils/wallet';
import { settleFunds } from '../../utils/send';
import { notify } from '../../utils/notifications';
import { useReferrer } from '../../utils/referrer';

export default function BalancesTable({
balances,
Expand All @@ -19,6 +20,7 @@ export default function BalancesTable({
const [accounts] = useTokenAccounts();
const connection = useSendConnection();
const { wallet } = useWallet();
const { usdcRef, usdtRef } = useReferrer();

async function onSettleFunds(market, openOrders) {
try {
Expand All @@ -35,6 +37,8 @@ export default function BalancesTable({
accounts,
market?.quoteMintAddress,
),
usdcRef,
usdtRef,
});
} catch (e) {
notify({
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserInfoTable/WalletBalancesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function WalletBalancesTable({
render: (walletBalance) => (
<Row align="middle">
<a
href={`https://explorer.solana.com/address/${walletBalance.mint}`}
href={`https://solscan.io/address/${walletBalance.mint}`}
target={'_blank'}
rel="noopener noreferrer"
>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/TradePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import CustomMarketDialog from '../components/CustomMarketDialog';
import { notify } from '../utils/notifications';
import { useHistory, useParams } from 'react-router-dom';
import { nanoid } from 'nanoid';

const { Option, OptGroup } = Select;

Expand Down Expand Up @@ -250,7 +251,7 @@ function MarketSelector({
{customMarkets.map(({ address, name }, i) => (
<Option
value={address}
key={address}
key={nanoid()}
name={name}
style={{
padding: '10px',
Expand Down Expand Up @@ -296,7 +297,7 @@ function MarketSelector({
.map(({ address, name, deprecated }, i) => (
<Option
value={address.toBase58()}
key={address}
key={nanoid()}
name={name}
style={{
padding: '10px',
Expand Down
2 changes: 1 addition & 1 deletion src/pages/pools/PoolPage/PoolBalancesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function BalanceItem({ mint, publicKey, isPoolToken }: BalanceItemProps) {
<Button
type="link"
icon={<LinkOutlined />}
href={'https://explorer.solana.com/address/' + publicKey.toBase58()}
href={'https://solscan.io/address/' + publicKey.toBase58()}
target="_blank"
rel="noopener noreferrer"
/>
Expand Down
6 changes: 6 additions & 0 deletions src/utils/fetch-loop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,9 @@ export function setCache(
loop.notifyListeners();
}
}

export function getCache(
cacheKey: any
) {
return globalCache.get(cacheKey);
}
Loading