From cf1fc1e9b382e3732773ada706d088389b54c699 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 6 Mar 2023 12:25:42 +0000 Subject: [PATCH 01/34] lowercase seriesName --- src/config/series.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/series.ts b/src/config/series.ts index 565575f3f..b86ec3abb 100644 --- a/src/config/series.ts +++ b/src/config/series.ts @@ -53,8 +53,8 @@ const USDC_2306 = '0x0032ff00028b'; const DAI_2306 = '0x0031ff00028b'; const WETH_2306 = '0x0030ff00028b'; const FRAX_2306 = '0x0138ff00028b'; -const USDT_2306 = '0x00A0FF00028B'; -const USDT_2303 = '0x00A0FF000288'; +const USDT_2306 = '0x00a0ff00028b'; +const USDT_2303 = '0x00a0ff000288'; export const validateSeries = async (provider: BaseProvider, cauldronAddress: string) => { const preText = '### SERIES SET VALIDATION ERROR ### '; From 7cc8daba9f919719a5939680dfa56490bf57253f Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 6 Mar 2023 12:26:11 +0000 Subject: [PATCH 02/34] console logging for debugging --- src/contexts/UserContext.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index ab5b39829..1ef624cf3 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -24,7 +24,7 @@ import { EULER_SUPGRAPH_ENDPOINT, RATE, ZERO_BN } from '../utils/constants'; import { SettingsContext } from './SettingsContext'; import { ETH_BASED_ASSETS } from '../config/assets'; import useTimeTillMaturity from '../hooks/useTimeTillMaturity'; -import { useAccount, useProvider } from 'wagmi'; +import { useProvider } from 'wagmi'; import request from 'graphql-request'; import { Block } from '@ethersproject/providers'; @@ -34,7 +34,6 @@ import { IUserContextActions, IUserContextState, UserContextAction, UserState } import useFork from '../hooks/useFork'; import { formatUnits } from 'ethers/lib/utils'; import useBalances, { BalanceData } from '../hooks/useBalances'; -import { FaBalanceScale } from 'react-icons/fa'; import useAccountPlus from '../hooks/useAccountPlus'; @@ -601,7 +600,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* Updates the vaults with *user* data */ const updateVaults = useCallback( async (vaultList: IVaultRoot[] = []) => { - console.log('Updating vaults...'); + console.log('Updating vaults ...', account); updateState({ type: UserState.VAULTS_LOADING, payload: true }); let _vaults: IVaultRoot[] | undefined = vaultList; @@ -616,6 +615,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { _vaults = await _getVaults(); } + /* if fetching vaults fails */ if (!_vaults) return; const updatedVaults = await Promise.all( From 466e945dfffd998e7797e9609f2d202ac6efa4d9 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 6 Mar 2023 12:26:28 +0000 Subject: [PATCH 03/34] simplify useAccountPLus --- src/hooks/useAccountPlus.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hooks/useAccountPlus.ts b/src/hooks/useAccountPlus.ts index 7c1616f02..baf93f322 100644 --- a/src/hooks/useAccountPlus.ts +++ b/src/hooks/useAccountPlus.ts @@ -12,16 +12,17 @@ const useAccountPlus = () => { const { mockUserAddress, useMockedUser } = settingsState; const data = useAccount(); - const [ userData, setUserData ] = useState(data); + const [ userData, setUserData ] = useState({address:undefined}); useEffect(() => { - if (useMockedUser) { + if (useMockedUser === true) { console.log('useAccountPlus >>> mockUser: ' + mockUserAddress); - setUserData({ ...data, address: mockUserAddress, isConnected: true, connector: undefined }); - } + setUserData({ ...data, address: mockUserAddress, isConnected: true, connector: undefined, mocked: true }); + } }, [useMockedUser]); - return useMockedUser ? {...userData} : data; + return (useMockedUser === true ? userData : data); + }; export default useAccountPlus; From 939f269afa34a03be6c281b20332ba39263a6e7b Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Mon, 6 Mar 2023 12:26:36 +0000 Subject: [PATCH 04/34] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bbe269f46..cfb3546c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "app-v2", - "version": "2.5.4", + "version": "2.5.5", "private": true, "dependencies": { "@ethersproject/providers": "^5.6.8", From 1d2fe4a98a80583227cddb3c4414ca5037d77e42 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 10:51:52 -0800 Subject: [PATCH 05/34] fix: use new contract file --- src/contexts/ChainContext.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/contexts/ChainContext.tsx b/src/contexts/ChainContext.tsx index 1c9a38487..2fcf3b571 100644 --- a/src/contexts/ChainContext.tsx +++ b/src/contexts/ChainContext.tsx @@ -4,7 +4,7 @@ import { format } from 'date-fns'; import { useCachedState } from '../hooks/generalHooks'; -import yieldEnv from './yieldEnv.json'; +import yieldEnv from './yieldEnv'; import * as contractTypes from '../contracts'; // import * as contracts from '../contracts'; import * as contracts from '../contracts'; @@ -19,7 +19,7 @@ import YieldMark from '../components/logos/YieldMark'; // import { SERIES } from '../config/series'; import { toast } from 'react-toastify'; import useChainId from '../hooks/useChainId'; -import useContracts, { ContractNames } from '../hooks/useContracts'; +import useContracts from '../hooks/useContracts'; import { ChainContextActions, ChainState, IChainContextActions, IChainContextState } from './types/chain'; import { SERIES, ISeriesStatic, validateSeries } from '../config/series'; import { Block } from '@ethersproject/providers'; @@ -287,7 +287,7 @@ const ChainProvider = ({ children }: { children: ReactNode }) => { newSeriesList.length && localStorage.setItem(cacheKey, JSON.stringify(newSeriesList)); newSeriesList.length && console.log('Yield Protocol Series data retrieved successfully.'); }, - [_chargeSeries, contracts, provider] + [_chargeSeries, provider] ); /* Attach contract instance */ @@ -413,7 +413,7 @@ const ChainProvider = ({ children }: { children: ReactNode }) => { * functionality to export protocol addresses */ const exportContractAddresses = () => { - const contractList = [...contracts].map(([v, k]) => [v, k.address]); + const contractList = [...contracts?.entries()!].map(([v, k]) => [v, k.address]); const seriesList = [...chainState.seriesRootMap].map(([v, k]) => [v, k.address]); const assetList = [...chainState.assetRootMap].map(([v, k]) => [v, k.address]); const strategyList = [...chainState.strategyRootMap].map(([v, k]) => [k.symbol, v]); From f65e1010956e36d85f508b033d0059f0b67a5f43 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 10:52:04 -0800 Subject: [PATCH 06/34] feat: yieldEnv now ts --- src/contexts/yieldEnv.json | 22 -------------------- src/contexts/yieldEnv.ts | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 22 deletions(-) delete mode 100644 src/contexts/yieldEnv.json create mode 100644 src/contexts/yieldEnv.ts diff --git a/src/contexts/yieldEnv.json b/src/contexts/yieldEnv.json deleted file mode 100644 index 8c61beb15..000000000 --- a/src/contexts/yieldEnv.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "addresses": { - "1": { - "Cauldron": "0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867", - "Ladle": "0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A", - "Witch": "0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061", - "WitchV2": "0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400", - - "Transfer1155Module": "0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06", - "WrapEtherModule": "0x22768FCaFe7BB9F03e31cb49823d1Ece30C0b8eA", - "ConvexLadleModule": "0x9Bf195997581C99cef8be95a3a816Ca19Cf1A3e6" - }, - - "42161": { - "Cauldron": "0x23cc87FBEBDD67ccE167Fa9Ec6Ad3b7fE3892E30", - "Ladle": "0x16E25cf364CeCC305590128335B8f327975d0560", - "Witch": "0x08173D0885B00BDD640aaE57D05AbB74cd00d669", - "WitchV2": "0x07c2c74811cb14a5003c3ccff7ec436d504fffb6", - "WrapEtherModule": "0x4cd01ed221d6d198e2656c16c32803bf78134568" - } - } -} diff --git a/src/contexts/yieldEnv.ts b/src/contexts/yieldEnv.ts new file mode 100644 index 000000000..53cf9f20b --- /dev/null +++ b/src/contexts/yieldEnv.ts @@ -0,0 +1,42 @@ +export enum ContractNames { + CAULDRON = 'Cauldron', + WITCH = 'Witch', + WITCHV2 = 'WitchV2', + LADLE = 'Ladle', + WRAP_ETHER_MODULE = 'WrapEtherModule', + CONVEX_LADLE_MODULE = 'ConvexLadleModule', + TRANSFER_1155_MODULE = 'Transfer1155Module', +} + +interface YieldEnv { + addresses: Map>; +} + +const yieldEnv: YieldEnv = { + addresses: new Map([ + [ + 1, + new Map([ + [ContractNames.CAULDRON, '0xc88191F8cb8e6D4a668B047c1C8503432c3Ca867'], + [ContractNames.LADLE, '0x6cB18fF2A33e981D1e38A663Ca056c0a5265066A'], + [ContractNames.WITCH, '0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061'], + [ContractNames.WITCHV2, '0x08d2f5c96bb1f6be04b49bcd869d5af01db4c400'], + [ContractNames.TRANSFER_1155_MODULE, '0x97f1d43A217aDD678bB6Dcd3C5D51F40b6729d06'], + [ContractNames.WRAP_ETHER_MODULE, '0x22768FCaFe7BB9F03e31cb49823d1Ece30C0b8eA'], + [ContractNames.CONVEX_LADLE_MODULE, '0x9Bf195997581C99cef8be95a3a816Ca19Cf1A3e6'], + ]), + ], + [ + 42161, + new Map([ + [ContractNames.CAULDRON, '0x23cc87FBEBDD67ccE167Fa9Ec6Ad3b7fE3892E30'], + [ContractNames.LADLE, '0x16E25cf364CeCC305590128335B8f327975d0560'], + [ContractNames.WITCH, '0x08173D0885B00BDD640aaE57D05AbB74cd00d669'], + [ContractNames.WITCHV2, '0x07c2c74811cb14a5003c3ccff7ec436d504fffb6'], + [ContractNames.WRAP_ETHER_MODULE, '0x4cd01ed221d6d198e2656c16c32803bf78134568'], + ]), + ], + ]), +}; + +export default yieldEnv; From 1b02e13ac8645d130c20b81111101b1da9dd0f60 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 10:52:16 -0800 Subject: [PATCH 07/34] fix: handle no addrs --- src/hooks/useContracts.ts | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/hooks/useContracts.ts b/src/hooks/useContracts.ts index 8437702fb..da0a07b0b 100644 --- a/src/hooks/useContracts.ts +++ b/src/hooks/useContracts.ts @@ -1,29 +1,23 @@ -import { Contract } from 'ethers'; import { useMemo } from 'react'; -import yieldEnv from './../contexts/yieldEnv.json'; +import yieldEnv, { ContractNames } from '../contexts/yieldEnv'; import * as contractTypes from '../contracts'; import useChainId from './useChainId'; import { useProvider } from 'wagmi'; - -export enum ContractNames { - CAULDRON = 'Cauldron', - WITCH = 'Witch', - WITCHV2 = 'WitchV2', - LADLE = 'Ladle', - WRAP_ETHER_MODULE = 'WrapEtherModule', - CONVEX_LADLE_MODULE = 'ConvexLadleModule', -} +import { Contract } from 'ethers'; const useContracts = () => { const { addresses } = yieldEnv; const chainId = useChainId(); const provider = useProvider(); - const chainAddrs = (addresses as any)[chainId]; + const chainAddrs = addresses.get(chainId); + return useMemo(() => { - return Object.keys(chainAddrs).reduce((contracts, name: string) => { - const contract = (contractTypes as any)[`${name}__factory`].connect(chainAddrs[name], provider) as Contract; + if (!chainAddrs) return; + + return [...chainAddrs.keys()].reduce((contracts, name) => { + const contract = (contractTypes as any)[`${name}__factory`].connect(chainAddrs.get(name), provider) as Contract; return contracts.set(name, contract); - }, new Map() as Map); + }, new Map() as Map); }, [chainAddrs, provider]); }; From d87a8514c56e170c81bee01c28203a7845f96b7f Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:16:56 -0800 Subject: [PATCH 08/34] fix: handle contract map undefined --- src/utils/appUtils.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/utils/appUtils.ts b/src/utils/appUtils.ts index 8a4425cf1..47fe06774 100644 --- a/src/utils/appUtils.ts +++ b/src/utils/appUtils.ts @@ -1,6 +1,7 @@ import { format, getMonth, subDays } from 'date-fns'; -import { ContractReceipt } from 'ethers'; +import { Contract, ContractReceipt } from 'ethers'; import { uniqueNamesGenerator, Config, adjectives, animals } from 'unique-names-generator'; +import { ContractMap, ContractNames } from '../contexts/yieldEnv'; import { ActionCodes, ISeries } from '../types'; @@ -185,7 +186,12 @@ export const buildGradient = (colorFrom: string, colorTo: string) => `linear-gra ${modColor(colorTo, 0)}) `; -export const getPositionPath = (txCode: string, receipt: any, contractMap?: any, seriesMap?: any) => { +export const getPositionPath = ( + txCode: string, + receipt: any, + contractMap?: ContractMap | undefined, + seriesMap?: any +) => { const action = txCode.split('_')[0]; const positionId = txCode.split('_')[1]; @@ -217,10 +223,14 @@ export const getPositionPath = (txCode: string, receipt: any, contractMap?: any, } }; -export const getVaultIdFromReceipt = (receipt: any, contractMap: any) => { - if (!receipt) return ''; - const cauldronAddr = contractMap?.get('Cauldron')?.address!; - const vaultIdHex = receipt.events.filter((e: any) => e.address === cauldronAddr)[0]?.topics[1]!; +export const getVaultIdFromReceipt = (receipt: ContractReceipt | undefined, contractMap: ContractMap | undefined) => { + if (!receipt || !contractMap) return ''; + + const cauldron = contractMap.get(ContractNames.CAULDRON); + if (!cauldron) return ''; + + const cauldronAddr = cauldron.address; + const vaultIdHex = receipt.events?.filter((e) => e.address === cauldronAddr)[0]?.topics[1]!; return vaultIdHex?.slice(0, 26) || ''; }; From 4883d5adcc09b398153c65b42a7daeca716b7da2 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:17:03 -0800 Subject: [PATCH 09/34] feat: contract map type --- src/contexts/yieldEnv.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/contexts/yieldEnv.ts b/src/contexts/yieldEnv.ts index 53cf9f20b..946382fdf 100644 --- a/src/contexts/yieldEnv.ts +++ b/src/contexts/yieldEnv.ts @@ -1,3 +1,5 @@ +import { Contract } from 'ethers'; + export enum ContractNames { CAULDRON = 'Cauldron', WITCH = 'Witch', @@ -8,6 +10,8 @@ export enum ContractNames { TRANSFER_1155_MODULE = 'Transfer1155Module', } +export type ContractMap = Map; + interface YieldEnv { addresses: Map>; } From df20d91863b7bca33d209b99b6136b44d399d5df Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:17:49 -0800 Subject: [PATCH 10/34] feat: use contract map type --- src/hooks/useContracts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hooks/useContracts.ts b/src/hooks/useContracts.ts index da0a07b0b..f47966aed 100644 --- a/src/hooks/useContracts.ts +++ b/src/hooks/useContracts.ts @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import yieldEnv, { ContractNames } from '../contexts/yieldEnv'; +import yieldEnv, { ContractMap, ContractNames } from '../contexts/yieldEnv'; import * as contractTypes from '../contracts'; import useChainId from './useChainId'; import { useProvider } from 'wagmi'; @@ -17,7 +17,7 @@ const useContracts = () => { return [...chainAddrs.keys()].reduce((contracts, name) => { const contract = (contractTypes as any)[`${name}__factory`].connect(chainAddrs.get(name), provider) as Contract; return contracts.set(name, contract); - }, new Map() as Map); + }, new Map() as ContractMap); }, [chainAddrs, provider]); }; From 5c03ee811d2950078b499a594d3fc95a7cf739b9 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:20:27 -0800 Subject: [PATCH 11/34] chore: remove unused imports --- src/contexts/ChainContext.tsx | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/contexts/ChainContext.tsx b/src/contexts/ChainContext.tsx index 2fcf3b571..d20b6df19 100644 --- a/src/contexts/ChainContext.tsx +++ b/src/contexts/ChainContext.tsx @@ -4,14 +4,11 @@ import { format } from 'date-fns'; import { useCachedState } from '../hooks/generalHooks'; -import yieldEnv from './yieldEnv'; import * as contractTypes from '../contracts'; -// import * as contracts from '../contracts'; -import * as contracts from '../contracts'; import { IAssetRoot, ISeriesRoot, IStrategyRoot, TokenType } from '../types'; -import { AssetStaticInfo, ASSETS, ETH_BASED_ASSETS } from '../config/assets'; +import { ASSETS } from '../config/assets'; -import { nameFromMaturity, getSeason, SeasonType, getSeriesAfterRollPosition } from '../utils/appUtils'; +import { nameFromMaturity, getSeason, SeasonType } from '../utils/appUtils'; import { ethereumColorMap, arbitrumColorMap } from '../config/colors'; import markMap from '../config/marks'; import YieldMark from '../components/logos/YieldMark'; @@ -21,9 +18,9 @@ import { toast } from 'react-toastify'; import useChainId from '../hooks/useChainId'; import useContracts from '../hooks/useContracts'; import { ChainContextActions, ChainState, IChainContextActions, IChainContextState } from './types/chain'; -import { SERIES, ISeriesStatic, validateSeries } from '../config/series'; +import { SERIES, ISeriesStatic } from '../config/series'; import { Block } from '@ethersproject/providers'; -import STRATEGIES, { validateStrategies } from '../config/strategies'; +import STRATEGIES from '../config/strategies'; import { Pool__factory } from '../contracts'; import { useProvider } from 'wagmi'; From c3eab3036acfadabe7c8aeb4243350d9dc243627 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:20:36 -0800 Subject: [PATCH 12/34] chore: remove unused --- src/hooks/useContracts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useContracts.ts b/src/hooks/useContracts.ts index f47966aed..5556b497b 100644 --- a/src/hooks/useContracts.ts +++ b/src/hooks/useContracts.ts @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import yieldEnv, { ContractMap, ContractNames } from '../contexts/yieldEnv'; +import yieldEnv, { ContractMap } from '../contexts/yieldEnv'; import * as contractTypes from '../contracts'; import useChainId from './useChainId'; import { useProvider } from 'wagmi'; From 87bc4d21d1189a66c79788a9483ad8a83cf7f274 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:22:40 -0800 Subject: [PATCH 13/34] fix: return if no contracts --- src/contexts/HistoryContext.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/contexts/HistoryContext.tsx b/src/contexts/HistoryContext.tsx index d424a0bd1..ad092a3ca 100644 --- a/src/contexts/HistoryContext.tsx +++ b/src/contexts/HistoryContext.tsx @@ -24,10 +24,11 @@ import { TransferEvent } from '../contracts/Strategy'; import { LiquidityEvent, TradeEvent } from '../contracts/Pool'; import { VaultGivenEvent, VaultPouredEvent, VaultRolledEvent } from '../contracts/Cauldron'; import { useAccount, useProvider } from 'wagmi'; -import useContracts, { ContractNames } from '../hooks/useContracts'; +import useContracts from '../hooks/useContracts'; import useAccountPlus from '../hooks/useAccountPlus'; import useFork from '../hooks/useFork'; +import { ContractNames } from './yieldEnv'; const dateFormat = (dateInSecs: number) => format(new Date(dateInSecs * 1000), 'dd MMM yyyy'); @@ -115,8 +116,14 @@ const HistoryProvider = ({ children }: any) => { const _transferInFilter = strategyContract.filters.Transfer(null, account); const _transferOutFilter = strategyContract.filters.Transfer(account); - const inEventList = await strategyContract.queryFilter(_transferInFilter, useForkedEnv ? forkStartBlock : 'earliest'); - const outEventList = await strategyContract.queryFilter(_transferOutFilter, useForkedEnv ? forkStartBlock : 'earliest'); // originally 0 + const inEventList = await strategyContract.queryFilter( + _transferInFilter, + useForkedEnv ? forkStartBlock : 'earliest' + ); + const outEventList = await strategyContract.queryFilter( + _transferOutFilter, + useForkedEnv ? forkStartBlock : 'earliest' + ); // originally 0 const events = await Promise.all([ ...inEventList.map(async (e: TransferEvent) => { @@ -225,6 +232,8 @@ const HistoryProvider = ({ children }: any) => { /* update Trading Historical data */ const updateTradeHistory = useCallback( async (seriesList: ISeries[]) => { + if (!contracts) return; + const tradeHistMap = new Map([]); /* get all the trade historical transactions */ await Promise.all( @@ -433,6 +442,8 @@ const HistoryProvider = ({ children }: any) => { const updateVaultHistory = useCallback( async (vaultList: IVault[]) => { + if (!contracts) return; + const vaultHistMap = new Map([]); const cauldronContract = contracts.get(ContractNames.CAULDRON) as Cauldron; @@ -473,7 +484,16 @@ const HistoryProvider = ({ children }: any) => { vaultList.map((v) => v.id) ); }, - [_parseGivenLogs, _parsePourLogs, _parseRolledLogs, contracts, diagnostics, seriesRootMap, useForkedEnv, forkStartBlock] + [ + _parseGivenLogs, + _parsePourLogs, + _parseRolledLogs, + contracts, + diagnostics, + seriesRootMap, + useForkedEnv, + forkStartBlock, + ] ); /* Exposed userActions */ From 9e60213d32be5c3faf87be2265c0e265c882ff61 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:24:49 -0800 Subject: [PATCH 14/34] fix: return if no contracts --- src/contexts/UserContext.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/contexts/UserContext.tsx b/src/contexts/UserContext.tsx index 1ef624cf3..132efb6ea 100644 --- a/src/contexts/UserContext.tsx +++ b/src/contexts/UserContext.tsx @@ -29,13 +29,13 @@ import { useProvider } from 'wagmi'; import request from 'graphql-request'; import { Block } from '@ethersproject/providers'; import useChainId from '../hooks/useChainId'; -import useContracts, { ContractNames } from '../hooks/useContracts'; +import useContracts from '../hooks/useContracts'; import { IUserContextActions, IUserContextState, UserContextAction, UserState } from './types/user'; import useFork from '../hooks/useFork'; import { formatUnits } from 'ethers/lib/utils'; import useBalances, { BalanceData } from '../hooks/useBalances'; import useAccountPlus from '../hooks/useAccountPlus'; - +import { ContractNames } from './yieldEnv'; const initState: IUserContextState = { userLoading: false, @@ -138,7 +138,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* HOOKS */ const chainId = useChainId(); const provider = useProvider(); - + const { address: account } = useAccountPlus(); const { pathname } = useRouter(); @@ -147,7 +147,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { const contracts = useContracts(); - const {getForkStartBlock} = useFork(); + const { getForkStartBlock } = useFork(); const { // data: assetBalances, @@ -194,6 +194,8 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* internal function for getting the users vaults */ const _getVaults = useCallback(async () => { + if (!contracts) return; + const Cauldron = contracts.get(ContractNames.CAULDRON) as contractTypes.Cauldron; const cacheKey = `vaults_${account}_${chainId}`; @@ -202,7 +204,9 @@ const UserProvider = ({ children }: { children: ReactNode }) => { const lastVaultUpdateKey = `lastVaultUpdate_${account}_${chainId}`; // get the latest available vault ( either from the local storage or from the forkStart) - const lastVaultUpdate = useForkedEnv ? await getForkStartBlock() : JSON.parse(localStorage.getItem(lastVaultUpdateKey)!) || 'earliest'; + const lastVaultUpdate = useForkedEnv + ? await getForkStartBlock() + : JSON.parse(localStorage.getItem(lastVaultUpdateKey)!) || 'earliest'; /* Get a list of the vaults that were BUILT */ const vaultsBuiltFilter = Cauldron.filters.VaultBuilt(null, account, null); @@ -293,9 +297,7 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* Updates the series with relevant *user* data */ const updateSeries = useCallback( - async (seriesList: ISeriesRoot[]): Promise> => { - updateState({ type: UserState.SERIES_LOADING, payload: true }); let _publicData: ISeries[] = []; let _accountData: ISeries[] = []; @@ -312,8 +314,8 @@ const UserProvider = ({ children }: { children: ReactNode }) => { ]); let sharesReserves: BigNumber; - let c: BigNumber|undefined; - let mu: BigNumber|undefined; + let c: BigNumber | undefined; + let mu: BigNumber | undefined; let currentSharePrice: BigNumber; let sharesAddress: string; @@ -600,6 +602,8 @@ const UserProvider = ({ children }: { children: ReactNode }) => { /* Updates the vaults with *user* data */ const updateVaults = useCallback( async (vaultList: IVaultRoot[] = []) => { + if (!contracts) return; + console.log('Updating vaults ...', account); updateState({ type: UserState.VAULTS_LOADING, payload: true }); From 9bcc4fbef5f344b4bba7fc4a29131fdff0ef31a8 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 12:27:46 -0800 Subject: [PATCH 15/34] fix: handle no cauldron and contracts --- src/hooks/useAssetPair.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hooks/useAssetPair.ts b/src/hooks/useAssetPair.ts index bbe040575..6d5a7d570 100644 --- a/src/hooks/useAssetPair.ts +++ b/src/hooks/useAssetPair.ts @@ -5,11 +5,12 @@ import useSWR from 'swr'; import { useProvider } from 'wagmi'; import { bytesToBytes32, decimal18ToDecimalN, WAD_BN } from '@yield-protocol/ui-math'; -import useContracts, { ContractNames } from './useContracts'; +import useContracts from './useContracts'; import { Cauldron, CompositeMultiOracle__factory } from '../contracts'; import useChainId from './useChainId'; import { UserContext } from '../contexts/UserContext'; import { stETH, wstETH } from '../config/assets'; +import { ContractNames } from '../contexts/yieldEnv'; // This hook is used to get the asset pair info for a given base and collateral (ilk) const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { @@ -22,10 +23,12 @@ const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { /* HOOKS */ const provider = useProvider(); const contracts = useContracts(); - const Cauldron = contracts.get(ContractNames.CAULDRON) as Cauldron; + const Cauldron = contracts?.get(ContractNames.CAULDRON) as Cauldron | undefined; /* GET PAIR INFO */ const getAssetPair = async (baseId: string, ilkId: string): Promise => { + if (!Cauldron) return; + const _base = assetMap.get(baseId); const _ilk = assetMap.get(ilkId); @@ -94,7 +97,7 @@ const useAssetPair = (baseId?: string, ilkId?: string, seriesId?: string) => { ); const getSeriesEntityIlks = async () => { - if (!seriesId) return undefined; + if (!seriesId || !Cauldron) return undefined; // get cauldron addIlk events for this series id const addIlkEvents = await Cauldron.queryFilter(Cauldron.filters.IlkAdded(bytesToBytes32(seriesId, 6))); return addIlkEvents.reduce((acc, { args: { ilkId } }) => { From b9af145d48ed30a4962a942c8f40d67d93745935 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Thu, 9 Mar 2023 13:05:22 -0800 Subject: [PATCH 16/34] fix: handle unsupported chain --- src/components/NetworkError.tsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/NetworkError.tsx b/src/components/NetworkError.tsx index 9691622c3..7cf29fd19 100644 --- a/src/components/NetworkError.tsx +++ b/src/components/NetworkError.tsx @@ -1,24 +1,37 @@ import { useEffect, useState } from 'react'; import { Box, Button, Layer, Text } from 'grommet'; import { FiAlertCircle } from 'react-icons/fi'; -import { useConnect, useDisconnect } from 'wagmi'; +import { useConnect, useDisconnect, useNetwork } from 'wagmi'; const NetworkError = () => { const { error } = useConnect(); + const { chain, chains } = useNetwork(); const { disconnect } = useDisconnect(); const [showError, setShowError] = useState(false); useEffect(() => { - error?.message ? setShowError(true) : setShowError(false); - }, [error]); + error?.message || chain?.unsupported ? setShowError(true) : setShowError(false); + }, [chain?.unsupported, error]); return ( <> {showError && ( - Oops. There was a connection error. + {chain?.unsupported && ( + <> + {' '} + + Chain with id {chain.id} is unsupported. Please make sure you are on a supported network. + + + )} + {error && ( + <> + Oops. There was a connection error. + + )} {error?.message}