From 0421af27a55afe8c4d529eccbdfb138769447db6 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 08:53:20 -0800 Subject: [PATCH 01/17] on button hover in pool view spacing changes within center panel wrap Fixes #712 --- src/components/buttons/TransactButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/buttons/TransactButton.tsx b/src/components/buttons/TransactButton.tsx index 592cac5de..aa9fee86d 100644 --- a/src/components/buttons/TransactButton.tsx +++ b/src/components/buttons/TransactButton.tsx @@ -4,7 +4,7 @@ import styled from 'styled-components'; const StyledButton = styled(Button)` /* height: ${(props: any) => (props.mobile ? '3rem' : '3rem')}; */ - border: ${(props) => (props.theme.dark ? '#141a1e' : '2px solid white')}; + border: ${(props) => (props.theme.dark ? '2px solid #141a1e' : '2px solid white')}; :hover { transform: scale(1.01); From 51bd7214922666e4ec1e1f790df5b28a1d8ca556 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 08:57:43 -0800 Subject: [PATCH 02/17] update rcp endpoints to use same project within infura --- .env | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 955fffd97..3d3865004 100644 --- a/.env +++ b/.env @@ -4,7 +4,7 @@ REACT_APP_INFURA_KEY_V1=646dc0f33d2449878b28e0afa25267f6 REACT_APP_RPC_URL_42='https://kovan.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' REACT_APP_RPC_URL_1='https://mainnet.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' REACT_APP_RPC_URL_4='https://rinkeby.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' -REACT_APP_RPC_URL_10='https://optimism-mainnet.infura.io/v3/82c9d66897df4cf7a9e74ab44826affe' -REACT_APP_RPC_URL_69='https://optimism-kovan.infura.io/v3/277b589655694280bcb3cd7ebf79032c' -REACT_APP_RPC_URL_42161='https://arbitrum-mainnet.infura.io/v3/cbbe5034491045709e466f05dcd5ad5a' -REACT_APP_RPC_URL_421611='https://arbitrum-rinkeby.infura.io/v3/9adffa99cbf64552a492081225822885' +REACT_APP_RPC_URL_10='https://optimism-mainnet.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' +REACT_APP_RPC_URL_69='https://optimism-kovan.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' +REACT_APP_RPC_URL_42161='https://arbitrum-mainnet.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' +REACT_APP_RPC_URL_421611='https://arbitrum-rinkeby.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2' From bd5ebaf0e1b95959a03e75a32d13ac721e30cfa7 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 10:06:49 -0800 Subject: [PATCH 03/17] update series selector filtering to account for user in lend position --- src/components/selectors/SeriesSelector.tsx | 34 ++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index 4c44c280e..0e151e567 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -3,7 +3,7 @@ import { Avatar, Box, Grid, ResponsiveContext, Select, Text } from 'grommet'; import { ethers } from 'ethers'; import styled from 'styled-components'; -import { ActionType, ISeries, IUserContextActions, IUserContextState } from '../../types'; +import { ActionType, ISeries, IUserContext, IUserContextActions, IUserContextState } from '../../types'; import { UserContext } from '../../contexts/UserContext'; import { maxBaseIn, maxBaseOut } from '../../utils/yieldMath'; import { useApr } from '../../hooks/useApr'; @@ -121,9 +121,10 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou settingsState: { diagnostics }, } = useContext(SettingsContext); - const { userState, userActions }: { userState: IUserContextState; userActions: IUserContextActions } = - useContext(UserContext); - const { selectedSeries, selectedBase, seriesMap, seriesLoading } = userState; + const { userState, userActions }: { userState: IUserContextState; userActions: IUserContextActions } = useContext( + UserContext + ) as IUserContext; + const { selectedSeries, selectedBase, seriesMap, seriesLoading, selectedVault } = userState; const [localSeries, setLocalSeries] = useState(); const [options, setOptions] = useState([]); @@ -166,21 +167,26 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou ) .sort((a: ISeries, b: ISeries) => b.maturity! - a.maturity!); - /* if required, filter out the globally selected asset and */ + /* if required, filter out the globally selected asset */ if (selectSeriesLocally) { - filteredOpts = filteredOpts.filter((_series: ISeries) => _series.id !== _selectedSeries?.id); + filteredOpts = opts + .filter( + (_series) => + actionType === ActionType.LEND && _series.baseId === selectedSeries?.baseId && !_series.seriesIsMature + ) // if in lend position then use base series + .filter((_series) => actionType === ActionType.LEND && _series.id !== selectedSeries?.id); // filter out currently globally selected series } /* if current selected series is NOT in the list of available series (for a particular base), or bases don't match: set the selected series to null. */ - if ( - _selectedSeries && - _selectedSeries.baseId !== selectedBase?.idToUse // ) - ) - userActions.setSelectedSeries(null); - - setOptions(filteredOpts.sort((a: ISeries, b: ISeries) => a.maturity - b.maturity)); - }, [seriesMap, selectedBase, selectSeriesLocally, _selectedSeries, userActions]); + // if ( + // _selectedSeries && + // _selectedSeries.baseId !== selectedBase?.idToUse // ) + // ) + // userActions.setSelectedSeries(null); + + setOptions(filteredOpts.sort((a, b) => a.maturity - b.maturity)); + }, [seriesMap, selectedBase, selectSeriesLocally, _selectedSeries, userActions, selectedSeries, actionType]); const handleSelect = (_series: ISeries) => { if (!selectSeriesLocally) { From 527274d60ebe822a46585336860edfc11c2406a6 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 10:17:46 -0800 Subject: [PATCH 04/17] fix checks --- src/components/selectors/SeriesSelector.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index 0e151e567..a4e677884 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -167,14 +167,11 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou ) .sort((a: ISeries, b: ISeries) => b.maturity! - a.maturity!); - /* if required, filter out the globally selected asset */ + /* if within a position, filter out appropriate series based on selected vault or selected series */ if (selectSeriesLocally) { filteredOpts = opts - .filter( - (_series) => - actionType === ActionType.LEND && _series.baseId === selectedSeries?.baseId && !_series.seriesIsMature - ) // if in lend position then use base series - .filter((_series) => actionType === ActionType.LEND && _series.id !== selectedSeries?.id); // filter out currently globally selected series + .filter((_series) => _series.baseId === selectedSeries?.baseId && !_series.seriesIsMature) // only use selected series' base + .filter((_series) => _series.id !== selectedSeries?.id); // filter out currently globally selected series } /* if current selected series is NOT in the list of available series (for a particular base), or bases don't match: @@ -186,7 +183,16 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou // userActions.setSelectedSeries(null); setOptions(filteredOpts.sort((a, b) => a.maturity - b.maturity)); - }, [seriesMap, selectedBase, selectSeriesLocally, _selectedSeries, userActions, selectedSeries, actionType]); + }, [ + seriesMap, + selectedBase, + selectSeriesLocally, + _selectedSeries, + userActions, + selectedSeries, + actionType, + selectedVault, + ]); const handleSelect = (_series: ISeries) => { if (!selectSeriesLocally) { From 43386323554ce883ecbf1e5193da2fc02d139cfc Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 10:22:08 -0800 Subject: [PATCH 05/17] remove explicitly setting globally selected series when selecting series locally --- src/components/selectors/SeriesSelector.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index a4e677884..9fee87ca6 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -157,15 +157,15 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou /* Keeping options/selection fresh and valid: */ useEffect(() => { - const opts = Array.from(seriesMap.values()) as ISeries[]; + const opts = Array.from(seriesMap.values()); /* filter out options based on base Id and if mature */ let filteredOpts = opts .filter( - (_series: ISeries) => _series.baseId === selectedBase?.idToUse && !_series.seriesIsMature + (_series) => _series.baseId === selectedBase?.idToUse && !_series.seriesIsMature // !ignoredSeries?.includes(_series.baseId) ) - .sort((a: ISeries, b: ISeries) => b.maturity! - a.maturity!); + .sort((a, b) => b.maturity! - a.maturity!); /* if within a position, filter out appropriate series based on selected vault or selected series */ if (selectSeriesLocally) { @@ -174,14 +174,6 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou .filter((_series) => _series.id !== selectedSeries?.id); // filter out currently globally selected series } - /* if current selected series is NOT in the list of available series (for a particular base), or bases don't match: - set the selected series to null. */ - // if ( - // _selectedSeries && - // _selectedSeries.baseId !== selectedBase?.idToUse // ) - // ) - // userActions.setSelectedSeries(null); - setOptions(filteredOpts.sort((a, b) => a.maturity - b.maturity)); }, [ seriesMap, From 4c5e828717466636f308c64d164d1fe9aedac6dd Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 10:23:13 -0800 Subject: [PATCH 06/17] spelling --- src/components/selectors/SeriesSelector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index 9fee87ca6..85269851a 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -171,7 +171,7 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou if (selectSeriesLocally) { filteredOpts = opts .filter((_series) => _series.baseId === selectedSeries?.baseId && !_series.seriesIsMature) // only use selected series' base - .filter((_series) => _series.id !== selectedSeries?.id); // filter out currently globally selected series + .filter((_series) => _series.id !== selectedSeries?.id); // filter out current globally selected series } setOptions(filteredOpts.sort((a, b) => a.maturity - b.maturity)); From c7826823494e55ebca516d061a6a177274b5a0c8 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 10:29:26 -0800 Subject: [PATCH 07/17] remove extra sort --- src/components/selectors/SeriesSelector.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/selectors/SeriesSelector.tsx b/src/components/selectors/SeriesSelector.tsx index 85269851a..32ad2d3c0 100644 --- a/src/components/selectors/SeriesSelector.tsx +++ b/src/components/selectors/SeriesSelector.tsx @@ -160,12 +160,10 @@ function SeriesSelector({ selectSeriesLocally, inputValue, actionType, cardLayou const opts = Array.from(seriesMap.values()); /* filter out options based on base Id and if mature */ - let filteredOpts = opts - .filter( - (_series) => _series.baseId === selectedBase?.idToUse && !_series.seriesIsMature - // !ignoredSeries?.includes(_series.baseId) - ) - .sort((a, b) => b.maturity! - a.maturity!); + let filteredOpts = opts.filter( + (_series) => _series.baseId === selectedBase?.idToUse && !_series.seriesIsMature + // !ignoredSeries?.includes(_series.baseId) + ); /* if within a position, filter out appropriate series based on selected vault or selected series */ if (selectSeriesLocally) { From 8b1f115a8969ec44f4033fe44ff9b522d9b15df7 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 12:34:45 -0800 Subject: [PATCH 08/17] formatting --- src/hooks/viewHelperHooks/useCollateralHelpers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/hooks/viewHelperHooks/useCollateralHelpers.ts b/src/hooks/viewHelperHooks/useCollateralHelpers.ts index 55a0bc004..98c469206 100644 --- a/src/hooks/viewHelperHooks/useCollateralHelpers.ts +++ b/src/hooks/viewHelperHooks/useCollateralHelpers.ts @@ -45,10 +45,10 @@ export const useCollateralHelpers = ( if (assetPairInfo) { /* set the pertinent oracle price */ setOraclePrice(decimalNToDecimal18(assetPairInfo.pairPrice, assetPairInfo.baseDecimals)); - + /* set min collaterateralisation ratio */ setMinCollatRatio(assetPairInfo?.minRatio); - setMinCollatRatioPct( (assetPairInfo?.minRatio * 100).toString()); + setMinCollatRatioPct((assetPairInfo?.minRatio * 100).toString()); /* set min safe coll ratio */ const _minSafeCollatRatio = assetPairInfo?.minRatio < 1.4 ? 1.5 : assetPairInfo?.minRatio + 1; @@ -66,7 +66,6 @@ export const useCollateralHelpers = ( })(); }, [activeAccount, selectedIlk, setMaxCollateral]); - /* handle changes to input values */ useEffect(() => { /* NOTE: this whole function ONLY deals with decimal18, existing values are converted to decimal18 */ @@ -140,7 +139,6 @@ export const useCollateralHelpers = ( minSafeCollatRatio, ]); - /* Monitor for undercollaterization/ danger-collateralisation, and set flags if reqd. */ useEffect(() => { parseFloat(collateralizationRatio!) >= minCollatRatio! From f6a726ddc5a9d4fc318ed5c3a58d16a3f2895803 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:03:21 -0800 Subject: [PATCH 09/17] add tooltip about keeping collat ratio above min collat ratio --- src/views/VaultPosition.tsx | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index ca999feb9..16f9cc610 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -1,9 +1,9 @@ import React, { useContext, useState, useEffect } from 'react'; import { useHistory, useParams } from 'react-router-dom'; -import { Box, CheckBox, ResponsiveContext, Select, Text, TextInput } from 'grommet'; +import { Tip, Box, CheckBox, ResponsiveContext, Select, Text, TextInput } from 'grommet'; import { ThemeContext } from 'styled-components'; -import { FiClock, FiTrendingUp, FiAlertTriangle, FiArrowRight } from 'react-icons/fi'; +import { FiClock, FiTrendingUp, FiAlertTriangle, FiArrowRight, FiInfo } from 'react-icons/fi'; import { abbreviateHash, cleanValue, nFormatter } from '../utils/appUtils'; import { UserContext } from '../contexts/UserContext'; import InputWrap from '../components/wraps/InputWrap'; @@ -311,14 +311,31 @@ const VaultPosition = () => { icon={} loading={vaultsLoading} /> - } - loading={vaultsLoading} - /> + + } + loading={vaultsLoading} + /> + + + Keep your collateralization ratio above {minCollatRatioPct}% to prevent liquidation + + } + dropProps={{ + align: { bottom: 'top', left: 'right' }, + }} + > + + ({collateralizationPercent}%) + + + + + )} From 0a0cb0ee49be05bc8e341dea2379077ecebd344a Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:22:32 -0800 Subject: [PATCH 10/17] add extra info when removing collat about dangerous collat levels --- src/views/VaultPosition.tsx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index 16f9cc610..862be6322 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -130,11 +130,8 @@ const VaultPosition = () => { '0', _selectedVault ); - const { collateralizationPercent: removeCollEst } = useCollateralHelpers( - '0', - `-${removeCollatInput! || '0'}`, - _selectedVault - ); + const { collateralizationPercent: removeCollEst, unhealthyCollatRatio: removeCollEstUnhealthyRatio } = + useCollateralHelpers('0', `-${removeCollatInput! || '0'}`, _selectedVault); const { collateralizationPercent: addCollEst } = useCollateralHelpers( '0', `${addCollatInput! || '0'}`, @@ -625,9 +622,16 @@ const VaultPosition = () => { ) : ( - - Your collateralization ratio will be: {nFormatter(parseFloat(removeCollEst!), 2)}% - + + + Your collateralization ratio will be: {nFormatter(parseFloat(removeCollEst!), 2)}% + + {removeCollEstUnhealthyRatio && ( + + Removing this much collateral will make the vault in danger of liquidation + + )} + ) } From 2875cc978af2da97ba9b8c422ad3be85dc5438cc Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:32:58 -0800 Subject: [PATCH 11/17] move additional min collat ratio language to info bite children --- src/components/InfoBite.tsx | 9 ++++++--- src/views/VaultPosition.tsx | 37 +++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/components/InfoBite.tsx b/src/components/InfoBite.tsx index 55438e0df..dc69dab3c 100644 --- a/src/components/InfoBite.tsx +++ b/src/components/InfoBite.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { FC } from 'react'; import { Box, Text } from 'grommet'; import Skeleton from './wraps/SkeletonWrap'; @@ -9,14 +9,17 @@ interface IInfoBite { loading?: boolean; } -const InfoBite = ({ label, value, icon, loading }: IInfoBite) => ( +const InfoBite: FC = ({ label, value, icon, loading, children }) => ( {icon && {icon}} {label} - {loading ? : value} + + {loading ? : value} + {children} + ); diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index 862be6322..e4a7fcf52 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -314,24 +314,25 @@ const VaultPosition = () => { value={`${cleanValue(_selectedVault?.ink_, vaultIlk?.decimals!)} ${vaultIlk?.displaySymbol}`} icon={} loading={vaultsLoading} - /> - - - Keep your collateralization ratio above {minCollatRatioPct}% to prevent liquidation - - } - dropProps={{ - align: { bottom: 'top', left: 'right' }, - }} - > - - ({collateralizationPercent}%) - - - - + > + + + Keep your collateralization ratio above {minCollatRatioPct}% to prevent liquidation + + } + dropProps={{ + align: { bottom: 'top', left: 'right' }, + }} + > + + ({collateralizationPercent}%) + + + + + From cd5423927447a2294381b4b8a8ec48929b125d6d Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:33:33 -0800 Subject: [PATCH 12/17] add space --- src/views/LendPosition.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/views/LendPosition.tsx b/src/views/LendPosition.tsx index d876d7b84..d74e04629 100644 --- a/src/views/LendPosition.tsx +++ b/src/views/LendPosition.tsx @@ -196,7 +196,10 @@ const LendPosition = () => { value={ fyTokenMarketValue === 'Low liquidity' ? 'Low Liquidity' - : `${cleanValue(fyTokenMarketValue, selectedBase?.digitFormat!)}${selectedBase?.displaySymbol!}` + : `${cleanValue( + fyTokenMarketValue, + selectedBase?.digitFormat! + )} ${selectedBase?.displaySymbol!}` } icon={selectedBase?.image} loading={seriesLoading} From d47ff461d33d2aece6963befbb53b1d32c31edaf Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:40:23 -0800 Subject: [PATCH 13/17] change tip direction --- src/views/VaultPosition.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index e4a7fcf52..9cd949fc3 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -323,7 +323,7 @@ const VaultPosition = () => { } dropProps={{ - align: { bottom: 'top', left: 'right' }, + align: { top: 'bottom' }, }} > From 6e6f56abe34efbcac95cd24d8660a2ccdd692ac8 Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Wed, 8 Dec 2021 13:59:55 -0800 Subject: [PATCH 14/17] only show info icon when not mobile --- src/views/VaultPosition.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index 9cd949fc3..0140a4183 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -328,7 +328,7 @@ const VaultPosition = () => { > ({collateralizationPercent}%) - + {!mobile && } From cb4fbe8d6bacecccf5b9d7619c74474b88c837f4 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Thu, 9 Dec 2021 09:12:04 +0000 Subject: [PATCH 15/17] temp comment out tip --- src/views/VaultPosition.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/views/VaultPosition.tsx b/src/views/VaultPosition.tsx index 0140a4183..ddc5142be 100644 --- a/src/views/VaultPosition.tsx +++ b/src/views/VaultPosition.tsx @@ -316,7 +316,8 @@ const VaultPosition = () => { loading={vaultsLoading} > - ({collateralizationPercent}%) + {/* Keep your collateralization ratio above {minCollatRatioPct}% to prevent liquidation @@ -330,7 +331,7 @@ const VaultPosition = () => { ({collateralizationPercent}%) {!mobile && } - + */} From d6f09d32e83e829726ad4f0e903cbf85ade22a53 Mon Sep 17 00:00:00 2001 From: brucedonovan Date: Thu, 9 Dec 2021 15:06:13 +0000 Subject: [PATCH 16/17] add in elements for forking --- README.md | 39 +- cache/solidity-files-cache.json | 4 - hardhat.config.js | 25 + package.json | 4 + scripts/hardhat-script.js | 32 + src/config/assets.ts | 2 +- yarn.lock | 1493 +++++++++++++++++++++++++++++-- 7 files changed, 1499 insertions(+), 100 deletions(-) delete mode 100644 cache/solidity-files-cache.json create mode 100644 hardhat.config.js create mode 100644 scripts/hardhat-script.js diff --git a/README.md b/README.md index a95149150..cb97640d4 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,15 @@ -# Yield app v2 +# Basic Sample Hardhat Project -## A. Setup Blockchain Environment +This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts. -### Option 1: Run development environment locally **(Recommended for now)** +Try running some of the following tasks: -In a new console: - -1. **clone** the environments-v2 repo: `git clone https://github.com/yieldprotocol/environments-v2.git` -2. **checkout tagged release** `git checkout RC4` -3. **install** the environment `yarn` -4. **Start a local hardhat chain instance**: `npx hardhat node` -5. optional: **Add your testing account** to the list of accounts to be auto-funded with test tokens: - - (edit `externalTestAccounts` array line 32 in file `./environments/development.ts` ) - -In a new console - -1. **Run the dev environment deploy/setup** `npx hardhat run ./environments/development.ts --network localhost` - -### Option 2: Use Rinkeby Testnet - -No setup required, simply point metamask to the correct network - -## B. Run User Interface (this Repo): - -Fire up the UI locally: - -1. **install and run** `yarn && yarn start` -2. In the browser, connect metamask to the localhost network, and reset the metamask account (for just in case). +```shell +npx hardhat accounts +npx hardhat compile +npx hardhat clean +npx hardhat test +npx hardhat node +node scripts/sample-script.js +npx hardhat help +``` diff --git a/cache/solidity-files-cache.json b/cache/solidity-files-cache.json deleted file mode 100644 index cb236ef8b..000000000 --- a/cache/solidity-files-cache.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "_format": "hh-sol-cache-2", - "files": {} -} diff --git a/hardhat.config.js b/hardhat.config.js new file mode 100644 index 000000000..0b69f49a7 --- /dev/null +++ b/hardhat.config.js @@ -0,0 +1,25 @@ +require("@nomiclabs/hardhat-waffle"); + +// This is a sample Hardhat task. To learn how to create your own go to +// https://hardhat.org/guides/create-task.html +task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { + const accounts = await hre.ethers.getSigners(); + for (const account of accounts) { + console.log(account.address); + } +}); + +/** + * @type import('hardhat/config').HardhatUserConfig + */ +module.exports = { + solidity: "0.8.4", + networks: { + hardhat: { + chainId: 1, + forking: { + url: "https://mainnet.infura.io/v3/2af222f674024a0f84b5f0aad0da72a2", + } + } + } +}; diff --git a/package.json b/package.json index cc4db663a..a60b5e93b 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,8 @@ ] }, "devDependencies": { + "@nomiclabs/hardhat-ethers": "^2.0.0", + "@nomiclabs/hardhat-waffle": "^2.0.1", "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^13.2.1", @@ -85,6 +87,8 @@ "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-react": "^7.26.1", "eslint-plugin-react-hooks": "^4.2.0", + "ethereum-waffle": "^3.2.0\n", + "hardhat": "^2.7.0", "prettier": "^2.4.1", "react-test-renderer": "^17.0.2", "source-map-explorer": "^2.5.2", diff --git a/scripts/hardhat-script.js b/scripts/hardhat-script.js new file mode 100644 index 000000000..90cd8197e --- /dev/null +++ b/scripts/hardhat-script.js @@ -0,0 +1,32 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node