Skip to content

Commit

Permalink
🐛 ethereum: fix web for ethereum mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
franm91 committed Mar 26, 2024
1 parent cc5289e commit 546c43a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 38 deletions.
21 changes: 13 additions & 8 deletions components/asset/FloatingPool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import FloatingPoolInfo from './FloatingPoolInfo';
import { Box, Grid } from '@mui/material';
import HistoricalRateChart from 'components/charts/HistoricalRateChart';
import UtilizationRateChart from 'components/charts/UtilizationRateChart';
import { useWeb3 } from 'hooks/useWeb3';
import { mainnet } from 'wagmi';

type AssetFloatingPoolProps = {
symbol: string;
};

const AssetFloatingPool: FC<AssetFloatingPoolProps> = ({ symbol }) => {
const { chain } = useWeb3();
return (
<Box display="flex" flexDirection="column" gap="8px">
<Grid
Expand All @@ -32,14 +35,16 @@ const AssetFloatingPool: FC<AssetFloatingPoolProps> = ({ symbol }) => {
>
<HistoricalRateChart symbol={symbol} />
</Box>
<Box
boxShadow={({ palette }) => (palette.mode === 'light' ? '0px 4px 12px rgba(175, 177, 182, 0.2)' : '')}
borderRadius="0px 0px 6px 6px"
bgcolor="components.bg"
p="16px"
>
<UtilizationRateChart type="floating" symbol={symbol} />
</Box>
{chain.id !== mainnet.id && (
<Box
boxShadow={({ palette }) => (palette.mode === 'light' ? '0px 4px 12px rgba(175, 177, 182, 0.2)' : '')}
borderRadius="0px 0px 6px 6px"
bgcolor="components.bg"
p="16px"
>
<UtilizationRateChart type="floating" symbol={symbol} />
</Box>
)}
</Box>
);
};
Expand Down
11 changes: 9 additions & 2 deletions components/asset/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useWeb3 } from 'hooks/useWeb3';
import Alert from '@mui/material/Alert';
import { useFloatingBalances } from 'hooks/useFloatingBalances';
import { useFixedBalances } from 'hooks/useFixedBalances';
import { mainnet } from 'wagmi';

type Props = {
symbol: string;
Expand Down Expand Up @@ -154,8 +155,14 @@ const AssetHeaderInfo: FC<Props> = ({ symbol }) => {

const borrowableUtilization = useMemo(() => {
if (!marketAccount) return;
return Number(WAD - marketAccount.reserveFactor) / 1e18;
}, [marketAccount]);

if (displayNetworkId === mainnet.id) return 0.9;

if ('reserveFactor' in marketAccount) {
return Number(WAD - marketAccount.reserveFactor) / 1e18;
}
return;
}, [displayNetworkId, marketAccount]);

return (
<>
Expand Down
23 changes: 14 additions & 9 deletions components/asset/MaturityPool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import MaturityPoolsMobile from './MaturityPoolsMobile';
import useAccountData from 'hooks/useAccountData';
import { formatUnits } from 'viem';
import SpreadModelChart from 'components/charts/SpreadModelChart';
import { mainnet } from 'wagmi';
import { useWeb3 } from 'hooks/useWeb3';

type Rate = {
maturity: bigint;
Expand All @@ -24,6 +26,7 @@ const AssetMaturityPools: FC<Props> = ({ symbol }) => {
const { marketAccount } = useAccountData(symbol);
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const { chain } = useWeb3();

const { totalDeposited, totalBorrowed, bestDeposit, bestBorrow } = useMemo<{
totalDeposited?: number;
Expand Down Expand Up @@ -94,15 +97,17 @@ const AssetMaturityPools: FC<Props> = ({ symbol }) => {
</Grid>
)}
</Grid>
<Box
boxShadow={({ palette }) => (palette.mode === 'light' ? '0px 4px 12px rgba(175, 177, 182, 0.2)' : '')}
borderRadius="0px 0px 6px 6px"
bgcolor="components.bg"
p="16px"
height={480}
>
<SpreadModelChart symbol={symbol} />
</Box>
{chain.id !== mainnet.id && (
<Box
boxShadow={({ palette }) => (palette.mode === 'light' ? '0px 4px 12px rgba(175, 177, 182, 0.2)' : '')}
borderRadius="0px 0px 6px 6px"
bgcolor="components.bg"
p="16px"
height={480}
>
<SpreadModelChart symbol={symbol} />
</Box>
)}
</Box>
);
};
Expand Down
2 changes: 1 addition & 1 deletion config/networkData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"1": {
"etherscan": "https://etherscan.io",
"subgraph": {
"exactly": "https://gateway.thegraph.com/api/3bd03f49a36caaa5ed4efc5a27c5425d/subgraphs/id/As6Xz6GCvbW8B9Xb7Rx2LqQeJcL3FcUyD8Tk95L8rG5d",
"exactly": "https://api.thegraph.com/subgraphs/name/itofarina/exa-op-sandbox",
"sablier": "https://api.thegraph.com/subgraphs/name/sablier-labs/sablier-v2"
}
},
Expand Down
10 changes: 8 additions & 2 deletions hooks/useAccountData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from 'abitype';

import AccountDataContext from 'contexts/AccountDataContext';
import usePreviewerExactly from 'hooks/usePreviewerExactly';
import { previewerABI } from 'types/abi';
import { previewerABI, legacyPreviewerABI } from 'types/abi';

export type MarketAccount = AbiParametersToPrimitiveTypes<
type NewMarketAccount = AbiParametersToPrimitiveTypes<
ExtractAbiFunction<typeof previewerABI, 'exactly'>['outputs']
>[number][number];

export type LegacyMarketAccount = AbiParametersToPrimitiveTypes<
ExtractAbiFunction<typeof legacyPreviewerABI, 'exactly'>['outputs']
>[number][number];

export type MarketAccount = NewMarketAccount | LegacyMarketAccount;

type AccountDataHook = {
marketAccount?: MarketAccount;
accountData?: readonly MarketAccount[];
Expand Down
3 changes: 2 additions & 1 deletion hooks/useIRM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import useAccountData from './useAccountData';

export default function useIRM(symbol: string) {
const { marketAccount } = useAccountData(symbol);
return marketAccount?.interestRateModel?.parameters;
if (!marketAccount) return;
if ('parameters' in marketAccount.interestRateModel) return marketAccount?.interestRateModel?.parameters;
}
24 changes: 16 additions & 8 deletions hooks/usePreviewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { isAddress } from 'viem';
import { mainnet, optimismSepolia, optimism } from 'wagmi/chains';

import { useWeb3 } from './useWeb3';
import { previewerABI } from 'types/abi';
import { previewerABI, legacyPreviewerABI } from 'types/abi';
import mainnetPreviewer from '@exactly/protocol/deployments/ethereum/Previewer.json' assert { type: 'json' };
import optimismPreviewer from '@exactly/protocol/deployments/optimism/Previewer.json' assert { type: 'json' };
import sepoliaPreviewer from '@exactly/protocol/deployments/op-sepolia/Previewer.json' assert { type: 'json' };
import { Previewer } from 'types/contracts';
import { Previewer, LegacyPreviewer } from 'types/contracts';

export default (): Previewer | undefined => {
export default (): Previewer | LegacyPreviewer | undefined => {
const { chain } = useWeb3();

return useMemo(() => {
Expand All @@ -22,10 +22,18 @@ export default (): Previewer | undefined => {

if (!address || !isAddress(address)) return;

return getContract({
chainId: chain.id,
address,
abi: previewerABI,
});
if (chain.id === mainnet.id) {
return getContract({
chainId: chain.id,
address,
abi: legacyPreviewerABI,
});
} else {
return getContract({
chainId: chain.id,
address,
abi: previewerABI,
});
}
}, [chain.id]);
};
23 changes: 16 additions & 7 deletions hooks/usePreviewerExactly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isAddress, zeroAddress } from 'viem';
import { mainnet, optimismSepolia, optimism } from 'wagmi/chains';

import { useWeb3 } from './useWeb3';
import { usePreviewerExactly } from 'types/abi';
import { usePreviewerExactly, useLegacyPreviewerExactly } from 'types/abi';
import mainnetPreviewer from '@exactly/protocol/deployments/ethereum/Previewer.json' assert { type: 'json' };
import optimismPreviewer from '@exactly/protocol/deployments/optimism/Previewer.json' assert { type: 'json' };
import sepoliaPreviewer from '@exactly/protocol/deployments/op-sepolia/Previewer.json' assert { type: 'json' };
Expand All @@ -18,10 +18,19 @@ export default (override?: number) => {

if (!address || !isAddress(address)) throw new Error(`No deployment for ${chain.id}`);

return usePreviewerExactly({
chainId: override ?? chain.id,
address,
args: [walletAddress ?? zeroAddress],
staleTime: 5_000,
});
if (chain.id === mainnet.id) {
return useLegacyPreviewerExactly({
chainId: override ?? chain.id,
address,
args: [walletAddress ?? zeroAddress],
staleTime: 5_000,
});
} else {
return usePreviewerExactly({
chainId: override ?? chain.id,
address,
args: [walletAddress ?? zeroAddress],
staleTime: 5_000,
});
}
};
2 changes: 2 additions & 0 deletions types/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
marketABI,
marketEthRouterABI,
previewerABI,
legacyPreviewerABI,
rewardsControllerABI,
permit2ABI,
sablierV2LockupLinearABI,
Expand All @@ -23,6 +24,7 @@ export type ReadContractType<T extends Abi> = ReturnType<typeof getContract<T, u
export type ERC20 = ContractType<typeof erc20ABI>;
export type Auditor = ContractType<typeof auditorABI>;
export type Previewer = ReadContractType<typeof previewerABI>;
export type LegacyPreviewer = ReadContractType<typeof legacyPreviewerABI>;
export type Market = ContractType<typeof marketABI>;
export type MarketETHRouter = ContractType<typeof marketEthRouterABI>;
export type InterestRateModel = ContractType<typeof interestRateModelABI>;
Expand Down
2 changes: 2 additions & 0 deletions wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import EXAPool from '@exactly/protocol/deployments/optimism/EXAPool.json' assert
import Swapper from '@exactly/protocol/deployments/optimism/Swapper.json' assert { type: 'json' };
import EXAGauge from '@exactly/protocol/deployments/optimism/EXAGauge.json' assert { type: 'json' };
import Previewer from '@exactly/protocol/deployments/op-sepolia/Previewer.json' assert { type: 'json' };
import LegacyPreviewer from '@exactly/protocol/deployments/ethereum/Previewer.json' assert { type: 'json' };
import DebtManager from '@exactly/protocol/deployments/op-sepolia/DebtManager.json' assert { type: 'json' };
import DebtPreviewer from '@exactly/protocol/deployments/op-sepolia/DebtPreviewer.json' assert { type: 'json' };
import MarketETHRouter from '@exactly/protocol/deployments/op-sepolia/MarketETHRouter.json' assert { type: 'json' };
Expand Down Expand Up @@ -41,6 +42,7 @@ export default defineConfig({
{ name: 'Swapper', abi: Swapper.abi as Abi },
{ name: 'EXAGauge', abi: EXAGauge.abi as Abi },
{ name: 'Previewer', abi: Previewer.abi as Abi },
{ name: 'LegacyPreviewer', abi: LegacyPreviewer.abi as Abi },
{ name: 'DebtManager', abi: DebtManager.abi as Abi },
{ name: 'DebtPreviewer', abi: DebtPreviewer.abi as Abi },
{ name: 'MarketETHRouter', abi: MarketETHRouter.abi as Abi },
Expand Down

0 comments on commit 546c43a

Please sign in to comment.