diff --git a/client/src/components/AssetBalance.js b/client/src/components/AssetBalance.js index 9b78f9d..fd601e2 100644 --- a/client/src/components/AssetBalance.js +++ b/client/src/components/AssetBalance.js @@ -66,10 +66,14 @@ const AssetBalance = ({ asset, clickAction, swapAmount, + balances, setSwapAmount, direction, provider }) => { + const currBalance = balances.length && balances.find(inv => inv.id === asset.id); + const assetBalance = currBalance?.balance || asset.balance; + return (
@@ -84,7 +88,7 @@ const AssetBalance = ({ onChange={(e) => setSwapAmount(e.target.value)} value={swapAmount || '0.0'} min="0.00" - max={asset.balance} + max={assetBalance} placeholder="0.0" > @@ -94,19 +98,19 @@ const AssetBalance = ({ {direction !== 'to' ? <> -

Balance: {Number(asset.balance).toFixed(4)|| '0.0'} {asset.symbol}

+

Balance: {Number(assetBalance).toFixed(4)|| '0.0'} {asset.symbol}

- +

|

- +

|

- +

|

- +
: -

Current Balance: {Number(asset.balance).toFixed(4) || '0.0'} {asset.symbol}

+

Current Balance: {Number(assetBalance).toFixed(4) || '0.0'} {asset.symbol}

}
} diff --git a/client/src/constants.js b/client/src/constants.js index bf06e9f..52f37f4 100644 --- a/client/src/constants.js +++ b/client/src/constants.js @@ -147,4 +147,4 @@ export const NETWORK = chainId => { } }; -export const TESSER_CONTRACT = "0xD1760AA0FCD9e64bA4ea43399Ad789CFd63C7809"; \ No newline at end of file +export const TESSER_CONTRACT = "0x6f2E42BB4176e9A7352a8bF8886255Be9F3D2d13"; \ No newline at end of file diff --git a/client/src/containers/Dashboard/index.js b/client/src/containers/Dashboard/index.js index 79a7f81..df5ba03 100644 --- a/client/src/containers/Dashboard/index.js +++ b/client/src/containers/Dashboard/index.js @@ -23,7 +23,6 @@ import { } from './dashboard.style'; import { ethers } from 'ethers'; import IERC20 from '../../utils/helpers/IERC20.json' -import CURVE_ABI from '../../utils/helpers/curveGaugeAbi.json' import { TESSER_CONTRACT } from '../../constants.js'; const initState = { @@ -40,6 +39,12 @@ const isMarket = (asset) => { return (asset.type === 'LP' || asset.type === 'Farm') } +const getRandomIntInclusive = (min, max) => { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +}; + const approveConn = async (token, user, amount, provider) => { const erc20 = new ethers.Contract(token, IERC20, provider); await erc20.approve(user, amount); @@ -55,31 +60,27 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao const TesserController = new ethers.Contract(TESSER_CONTRACT, TesserContract, userSigner) const getBalances = async (data, type) => { - const assets = [...data]; - for (let asset of assets) { + for (let asset of data) { if (asset.address === '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0') { const balance = await provider.getBalance(address) const formatBalance = ethers.utils.formatUnits(balance, asset.decimals); - asset['balance'] = formatBalance - } else if (asset.address === '0x19793B454D3AfC7b454F206Ffe95aDE26cA6912c') { - const contractAddress = asset.address; - const contract = new ethers.Contract(contractAddress, CURVE_ABI, userSigner); - const balance = await contract.balanceOf(address); - const formatBalance = ethers.utils.formatUnits(balance, asset.decimals); - asset['balance'] = formatBalance || 0.0; - } else if (!asset.balance) { + asset['balance'] = formatBalance; + } else { const contractAddress = asset.outputToken || asset.address; const contract = new ethers.Contract(contractAddress, IERC20, provider); - const balance = await contract.balanceOf(address); - const formatBalance = ethers.utils.formatUnits(balance, asset.decimals); + let formatBalance = asset.balanceStored; + if (!asset.balanceStored) { + const balance = await contract.balanceOf(address); + formatBalance = ethers.utils.formatUnits(balance, asset.decimals); + } asset['balance'] = formatBalance; } } if (type === 'tokens') { - setTokens(assets); + setTokens((prevState) => (data)); } else { - setInvestments(assets); + setInvestments((prevState) => (data)); } } @@ -88,8 +89,8 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao if (address && !!provider) { const tokens = [...investmentsData.tokens]; const investments = [...investmentsData.investments]; - getBalances(tokens, 'tokens') - getBalances(investments, 'investments') + getBalances(tokens, 'tokens'); + getBalances(investments, 'investments'); } }, [address, provider]); @@ -134,9 +135,6 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao const toSelected = swapSelection.to.asset !== {} const buttonDisabled = !(fromSelected && toSelected); - - // migrate from prot to prot but not - // deposit const tesserInvestments = async () => { let transaction setTesser(!tesserStarted) @@ -152,7 +150,7 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao console.log('migrate') if (swapSelection.from.asset.address === "0x68456B298c230415E2DE7aD4897A79Ee3f1A965a") fromAddress = "0x445FE580eF8d70FF569aB36e80c647af338db351" const adapterAddressFrom = await TesserController.getAdapterAddressForMarket(fromAddress); - const bigInt = '' + (swapSelection.from.value * (10 ** swapSelection.from.asset.decimals)) + const bigInt = '' + (parseInt('' + swapSelection.from.value * (10 ** swapSelection.from.asset.decimals))); await approveConn(fromAddress, adapterAddressFrom, bigInt, userSigner); transaction = await TesserController.migrate( @@ -167,11 +165,11 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao //withdraw const adapterAddressFrom = await TesserController.getAdapterAddressForMarket(fromAddress); const toAddress = swapSelection.from.asset.outputToken || swapSelection.from.asset.address; - const bigInt = '' + (swapSelection.from.value * (10 ** swapSelection.from.asset.decimals)) + const bigInt = '' + (parseInt('' + swapSelection.from.value * (10 ** swapSelection.from.asset.decimals))); await approveConn(toAddress, adapterAddressFrom, bigInt, userSigner) transaction = await TesserController.withdraw(toAddress, [bigInt], false) - } else if (swapSelection.from.asset.address === "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0"){ - const bigInt = '' + (swapSelection.from.value * (10 ** swapSelection.from.asset.decimals)) + } else if (swapSelection.from.asset.address === "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0") { + const bigInt = '' + (parseInt('' + swapSelection.from.value * (10 ** swapSelection.from.asset.decimals))); transaction = await TesserController.depositETH( toAddress, false, @@ -183,11 +181,11 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao console.log('deposit') // deposit or depositOtherTokens if (swapSelection.to.asset.inputTokens.includes(fromAddress)) { - const bigInt = '' + (swapSelection.from.value * (10 ** swapSelection.from.asset.decimals)) + const bigInt = '' + (parseInt('' + swapSelection.from.value * (10 ** swapSelection.from.asset.decimals))); const adapterAddressTo = await TesserController.getAdapterAddressForMarket(swapSelection.to.asset.address); await approveConn(fromAddress, adapterAddressTo, bigInt, userSigner) transaction = await TesserController.deposit( - fromAddress, + toAddress, [bigInt], false ) @@ -207,43 +205,25 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao // withdraw const adapterAddressFrom = await TesserController.getAdapterAddressForMarket(fromAddress); const toAddress = swapSelection.from.asset.outputToken || swapSelection.from.asset.address; - const bigInt = '' + (swapSelection.from.value * (10 ** swapSelection.from.asset.decimals)) + const bigInt = '' + (parseInt('' + swapSelection.from.value * (10 ** swapSelection.from.asset.decimals))); await approveConn(toAddress, adapterAddressFrom, bigInt, userSigner) transaction = await TesserController.withdraw(toAddress, [bigInt], false) } const receipt = await transaction.wait() console.log(receipt) + await getBalances(tokens, 'tokens') + await getBalances(investments, 'investments') if (receipt.status === 1) { - setTimeout(() => { - getBalances(tokens, 'tokens') - getBalances(investments, 'investments') - setSwapSelection(initState) - }, 2000); - - setTimeout(() => { - setTesser(false) + setTimeout(async () => { + setSwapValue(0.0, 'from') setModal({ state: false }) - }, 1000); - // refresh data - + setTesser(false) + }, 1000); } else { - getBalances(tokens, 'tokens') - getBalances(investments, 'investments') - setTesser(false) setModal({ state: false }) - // refresh data - setTimeout(() => { - setSwapSelection(initState) - - }, 500); + setTesser(false) } - } - - const getRandomIntInclusive = (min, max) => { - min = Math.ceil(min); - max = Math.floor(max); - return Math.floor(Math.random() * (max - min + 1)) + min; }; const tesseringModal = () => { @@ -279,27 +259,20 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao ); }; - const filteredData = showStakeDao - ? { - tokens: [...tokens], - protocols: [...investmentsData.protocols].filter(prot => prot.address !== "0x361a5a4993493ce00f61c32d4ecca5512b82ce90"), - investments: [...investments] - } - : - { - tokens: [...tokens], - protocols: [...investmentsData.protocols], - investments: [...investments] - } const selectionModal = () => { return prot.address !== "0x361a5a4993493ce00f61c32d4ecca5512b82ce90"), + investments: investments + }} setSwapAsset={(asset) => setSwapAsset(asset, modal.direction)} /> } - const ModalContent = tesserStarted ? tesseringModal() : selectionModal() @@ -310,7 +283,7 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao } } - return ( + return ( {modal.state && Tesser openSelector('from')} swapAmount={swapSelection.from.value} setSwapAmount={(value) => setSwapValue(value, 'from')} @@ -332,6 +306,7 @@ const Dashboard = ({ address, provider, userSigner, loadWeb3Modal, showStakeDao openSelector('to')} direction={'to'} provider={provider} diff --git a/client/src/containers/Landing/index.js b/client/src/containers/Landing/index.js deleted file mode 100644 index 12508d5..0000000 --- a/client/src/containers/Landing/index.js +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react'; -import { - ContainerSt -} from '../../components/UI'; -import styled from 'styled-components' - -const ButtonSt = styled.button` - all: unset; - width: 300px; - height: 60px; - border-radius: 40px; - font-size: 1.3em; - border: 1px solid darkviolet; - background-color: white; - text-align: center; - color: darkviolet; - transition: 0.6s all; - - &:hover { - border: 1px solid white; - background-color: darkviolet; - color: white; - } -`; - -const Landing = ({ history, loadWeb3Modal }) => { - return ( - - loadWeb3Modal() }>Enter dApp - - ) -} - -export default Landing; \ No newline at end of file diff --git a/client/src/containers/Landing/landing.style.js b/client/src/containers/Landing/landing.style.js deleted file mode 100644 index e69de29..0000000 diff --git a/client/src/utils/helpers/chainDataSources.json b/client/src/utils/helpers/chainDataSources.json index dcac522..22527e8 100644 --- a/client/src/utils/helpers/chainDataSources.json +++ b/client/src/utils/helpers/chainDataSources.json @@ -10,6 +10,16 @@ "abi": "IERC20", "type": "token" }, + { + "id": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6", + "address": "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6", + "name": "wrapped BTC", + "logo": "WBTC-logo.png", + "decimals": 8, + "symbol": "WBTC", + "abi": "IERC20", + "type": "token" + }, { "id": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0", "address": "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0", @@ -66,7 +76,7 @@ "logo": "AAVE-logo.png", "decimals": 18, "symbol": "AAVE", - "investments": ["aave-usdt", "aave-dai", "aave-usdc", "aave-wmatic"] + "investments": ["aave-usdt", "aave-dai", "aave-usdc", "aave-wmatic", "aave-wbtc"] }, { "address": "0x361a5a4993493ce00f61c32d4ecca5512b82ce90", @@ -153,6 +163,17 @@ "symbol": "amDAI", "type": "LP" }, + { + "id": "aave-wbtc", + "address": "0x5c2ed810328349100A66B82b78a1791B101C9D61", + "outputToken": "0x5c2ed810328349100A66B82b78a1791B101C9D61", + "inputTokens": ["0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6"], + "name": "amWBTC", + "decimals": 8, + "description": "wBTC deposit in Aave", + "symbol": "amWBTC", + "type": "LP" + }, { "id": "stakeDAO-curve.fi-dai-usdc-usdt", "address": "0x68456B298c230415E2DE7aD4897A79Ee3f1A965a", @@ -189,7 +210,7 @@ "description": "SushiSwap USDC-USDT Pool", "symbol": "SLP: USDC-USDT", "type": "LP", - "balance": "358.98" + "balanceStored": "358.98" }, { "id": "usdc-dai-sushi", @@ -204,7 +225,7 @@ "description": "SushiSwap USDC-DAI Pool", "symbol": "SLP: USDC-DAI", "type": "LP", - "balance": "450.30" + "balanceStored": "450.30" }, { "id": "usdc-usdt-quick", @@ -219,7 +240,7 @@ "description": "QuickSwap USDC-USDT Pool", "symbol": "QLP: USDC-USDT", "type": "LP", - "balance": "1275.34" + "balanceStored": "1275.34" }, { "id": "wmatic-usdc-quick", @@ -234,7 +255,7 @@ "description": "QuickSwap WMATIC-USDC Pool", "symbol": "QLP: WMATIC-USDC", "type": "LP", - "balance": "40" + "balanceStored": "40" } ] }