Skip to content

Commit

Permalink
SOV-2028: Enforce Babelfish Aggregator pause state for tokens on Brid…
Browse files Browse the repository at this point in the history
…ge (#2517)

* Add Babelfish subgraph

* Add Babelfish client

* Fetch paused tokens

* Check the correct contract for crossbridge assets

* chore: remove old comment

---------

Co-authored-by: soulBit <[email protected]>
  • Loading branch information
tiltom and soulBit authored Apr 18, 2023
1 parent 4fef54e commit e1aa348
Show file tree
Hide file tree
Showing 16 changed files with 2,773 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ REACT_APP_INFURA_KEY=12b606df88b3420aad7828acd0f11902

REACT_APP_GRAPH_RSK=https://subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph

REACT_APP_GRAPH_BABELFISH=https://babelfish-subgraph.test.sovryn.app/subgraphs/name/babelfish/rskTestnet-graph

REACT_APP_BSC_API_KEY=QWDBQDJY6P3AQ1YA3CMXKG3ADCZQQGWPBT
2 changes: 2 additions & 0 deletions .env.mainnet.local
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ REACT_APP_BYPASS_MAINTENANCE=1

REACT_APP_GRAPH_RSK=https://subgraph.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph

REACT_APP_GRAPH_BABELFISH=https://babelfish-subgraph.sovryn.app/subgraphs/name/babelfish/rsk-graph

REACT_APP_BSC_API_KEY=QWDBQDJY6P3AQ1YA3CMXKG3ADCZQQGWPBT
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ REACT_APP_INFURA_KEY=12b606df88b3420aad7828acd0f11902

REACT_APP_GRAPH_RSK=https://subgraph.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph

REACT_APP_GRAPH_BABELFISH=https://babelfish-subgraph.sovryn.app/subgraphs/name/babelfish/rsk-graph

REACT_APP_BSC_API_KEY=QWDBQDJY6P3AQ1YA3CMXKG3ADCZQQGWPBT
2 changes: 2 additions & 0 deletions .env.testnet
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ REACT_APP_INFURA_KEY=12b606df88b3420aad7828acd0f11902

REACT_APP_GRAPH_RSK=https://subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph

REACT_APP_GRAPH_BABELFISH=https://babelfish-subgraph.test.sovryn.app/subgraphs/name/babelfish/rskTestnet-graph

REACT_APP_BSC_API_KEY=QWDBQDJY6P3AQ1YA3CMXKG3ADCZQQGWPBT
5 changes: 5 additions & 0 deletions codegen.fetch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ generates:
- ${REACT_APP_GRAPH_RSK}
plugins:
- schema-ast
./src/utils/graphql/babelfish/schema.graphql:
schema:
- ${REACT_APP_GRAPH_BABELFISH}
plugins:
- schema-ast
hooks:
afterAllFileWrite:
- prettier ./src/utils/graphql/**/schema.graphql --write
15 changes: 15 additions & 0 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ generates:
Bytes: string
BigInt: string
BigDecimal: string
./src/utils/graphql/babelfish/generated.tsx:
schema:
- './src/utils/graphql/babelfish/schema.graphql'
documents:
- './src/utils/graphql/babelfish/operations/*.graphql'
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
config:
withHooks: true
scalars:
Bytes: string
BigInt: string
BigDecimal: string
hooks:
afterAllFileWrite:
- prettier ./src/utils/graphql --write
4 changes: 4 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
REACT_APP_ESTIMATOR_URI = "https://simulator.sovryn.app"
REACT_APP_MAILCHIMP = "https://gmail.us17.list-manage.com/subscribe/post?u=e66850f0b51ebbdbe1f2c3e36&id=ef5d452839"
REACT_APP_GRAPH_RSK = "https://subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph"
REACT_APP_GRAPH_BABELFISH = "https://babelfish-subgraph.test.sovryn.app/subgraphs/name/babelfish/rskTestnet-graph"

[context.production]
[context.production.environment]
REACT_APP_NETWORK = "mainnet"
REACT_APP_GOOGLE_ANALYTICS = "GTM-KTSX2PL"
REACT_APP_GOOGLE_ANALYTICS_CLICKTHROUGH = "GTM-5MWCJN3"
REACT_APP_GRAPH_RSK = "https://subgraph.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph"
REACT_APP_GRAPH_BABELFISH = "https://babelfish-subgraph.sovryn.app/subgraphs/name/babelfish/rsk-graph"
REACT_APP_INFURA_KEY = "12b606df88b3420aad7828acd0f11902"
REACT_APP_TRANSAK_ENV = "PRODUCTION"
REACT_APP_TRANSAK_API_KEY = "fadc5140-4d8f-4eda-ab37-5999dfedf353"
Expand All @@ -41,6 +43,7 @@
REACT_APP_GOOGLE_ANALYTICS = "GTM-KTSX2PL"
REACT_APP_GOOGLE_ANALYTICS_CLICKTHROUGH = "GTM-5MWCJN3"
REACT_APP_GRAPH_RSK = "https://subgraph.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph"
REACT_APP_GRAPH_BABELFISH = "https://babelfish-subgraph.sovryn.app/subgraphs/name/babelfish/rsk-graph"
REACT_APP_INFURA_KEY = "12b606df88b3420aad7828acd0f11902"
REACT_APP_TRANSAK_ENV = "PRODUCTION"
REACT_APP_TRANSAK_API_KEY = "fadc5140-4d8f-4eda-ab37-5999dfedf353"
Expand All @@ -52,5 +55,6 @@
[context.development.environment]
REACT_APP_NETWORK = "testnet"
REACT_APP_GRAPH_RSK = "https://subgraph.test.sovryn.app/subgraphs/name/DistributedCollective/sovryn-subgraph"
REACT_APP_GRAPH_BABELFISH = "https://babelfish-subgraph.test.sovryn.app/subgraphs/name/babelfish/rskTestnet-graph"
BUILD_STORYBOOK = "true"
REACT_APP_STAGING = "false"
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ITokenItemProps {
symbol: string;
onClick: () => void;
disabled?: boolean;
pausedTokens: string[];
}

export const TokenItem: React.FC<ITokenItemProps> = ({
Expand All @@ -28,6 +29,7 @@ export const TokenItem: React.FC<ITokenItemProps> = ({
symbol,
onClick,
disabled,
pausedTokens,
}) => {
const { t } = useTranslation();
const { chain, targetChain } = useSelector(selectBridgeDepositPage);
Expand All @@ -39,10 +41,36 @@ export const TokenItem: React.FC<ITokenItemProps> = ({
[chain, sourceAsset, targetChain],
);

const xusdBridgeTokens = useMemo(
() =>
BridgeDictionary.get(targetChain, chain as Chain)?.getAsset(
CrossBridgeAsset.XUSD as CrossBridgeAsset,
)?.bridgeTokenAddresses,
[chain, targetChain],
);

const rskBridgeTokenAddress = useMemo(
() => xusdBridgeTokens?.get(sourceAsset),
[sourceAsset, xusdBridgeTokens],
);

const balance = useTokenBalance(chain as any, asset);
const isPaused = useMemo(
() =>
pausedTokens.includes(asset.bridgeTokenAddress) ||
pausedTokens.includes(asset.tokenContractAddress) ||
(!!rskBridgeTokenAddress && pausedTokens.includes(rskBridgeTokenAddress)),
[
asset.bridgeTokenAddress,
asset.tokenContractAddress,
pausedTokens,
rskBridgeTokenAddress,
],
);

const isDisabled = useCallback(
() => disabled || !bignumber(balance.value).greaterThan(0),
[balance, disabled],
() => disabled || !bignumber(balance.value).greaterThan(0) || isPaused,
[balance.value, disabled, isPaused],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { translations } from 'locales/i18n';
import { useWalletContext } from '@sovryn/react-wallet';
import { useIsBridgeDepositLocked } from 'app/pages/BridgeDepositPage/hooks/useIsBridgeDepositLocked';
import { ErrorBadge } from 'app/components/Form/ErrorBadge';
import { useGetPausedTokens } from '../../hooks/useGetPausedTokens';

export const TokenSelector: React.FC = () => {
const { chain, targetChain, targetAsset } = useSelector(
Expand All @@ -26,6 +27,8 @@ export const TokenSelector: React.FC = () => {
const dispatch = useDispatch();
const { t } = useTranslation();

const pausedTokens = useGetPausedTokens();

useEffect(() => {
if (chain === null) {
dispatch(actions.setStep(DepositStep.CHAIN_SELECTOR));
Expand Down Expand Up @@ -110,6 +113,7 @@ export const TokenSelector: React.FC = () => {
symbol={item.symbol}
onClick={() => selectSourceAsset(item.asset)}
disabled={bridgeDepositLocked}
pausedTokens={pausedTokens}
/>
);
})}
Expand Down
13 changes: 13 additions & 0 deletions src/app/pages/BridgeDepositPage/hooks/useGetPausedTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMemo } from 'react';
import { babelfishClient } from 'utils/clients';
import { useGetPausedBassetListQuery } from 'utils/graphql/babelfish/generated';

export const useGetPausedTokens = () => {
const { data } = useGetPausedBassetListQuery({ client: babelfishClient });

const pausedTokens = useMemo(() => data?.bassets.map(item => item.id) || [], [
data,
]);

return pausedTokens;
};
15 changes: 2 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import './styles/tailwindcss/index.css';
import '@sovryn/react-wallet/index.css';
import '@blueprintjs/icons/lib/css/blueprint-icons.css';

// Import global types
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as GlobalTypes from './global';

// Import root app
import { App } from 'app';
import { ServiceWorkerToaster } from './app/components/ServiceWorkerToaster/Loadable';
Expand All @@ -39,19 +35,12 @@ import { store } from './store/store';
// Initialize languages
import './locales/i18n';
import './locales/dayjs';
import { ApolloProvider, ApolloClient, InMemoryCache } from '@apollo/client';
import { graphRskUrl } from './utils/classifiers';
import { ApolloProvider } from '@apollo/client';
import { ToastContainer } from 'react-toastify';
import { rskClient } from 'utils/clients';

const MOUNT_NODE = document.getElementById('root') as HTMLElement;

const rskClient = new ApolloClient({
uri: graphRskUrl,
cache: new InMemoryCache({
resultCaching: false,
}),
});

interface Props {
Component: typeof App;
}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/classifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const bscScanApi =

export const graphRskUrl = process.env.REACT_APP_GRAPH_RSK;

export const graphBabelfishUrl = process.env.REACT_APP_GRAPH_BABELFISH;

export const ethGenesisAddress = '0x0000000000000000000000000000000000000000';

export const sovAnalyticsCookie = { name: 'SovAnalytics', value: 'optout' };
Expand Down
16 changes: 16 additions & 0 deletions src/utils/clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';
import { graphBabelfishUrl, graphRskUrl } from './classifiers';

export const rskClient = new ApolloClient({
uri: graphRskUrl,
cache: new InMemoryCache({
resultCaching: false,
}),
});

export const babelfishClient = new ApolloClient({
uri: graphBabelfishUrl,
cache: new InMemoryCache({
resultCaching: false,
}),
});
Loading

0 comments on commit e1aa348

Please sign in to comment.