From 22aad392435e79d2f60f22262992aa0285ec2127 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 May 2023 10:43:30 -0400 Subject: [PATCH 1/3] Add conversion rate --- .../src/constants/mainnetAbi/sfrxeth.json | 472 ++++++++++++++++++ dapp-oeth/src/hooks/useSwapEstimator.js | 29 +- dapp-oeth/src/utils/contracts.js | 3 +- 3 files changed, 494 insertions(+), 10 deletions(-) create mode 100644 dapp-oeth/src/constants/mainnetAbi/sfrxeth.json diff --git a/dapp-oeth/src/constants/mainnetAbi/sfrxeth.json b/dapp-oeth/src/constants/mainnetAbi/sfrxeth.json new file mode 100644 index 0000000000..772ab0bab7 --- /dev/null +++ b/dapp-oeth/src/constants/mainnetAbi/sfrxeth.json @@ -0,0 +1,472 @@ +[ + { + "inputs": [ + { + "internalType": "contract ERC20", + "name": "_underlying", + "type": "address" + }, + { + "internalType": "uint32", + "name": "_rewardsCycleLength", + "type": "uint32" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { "inputs": [], "name": "SyncError", "type": "error" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint32", + "name": "cycleEnd", + "type": "uint32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "rewardAmount", + "type": "uint256" + } + ], + "name": "NewRewardsCycle", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "assets", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "asset", + "outputs": [ + { "internalType": "contract ERC20", "name": "", "type": "address" } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "convertToAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "name": "convertToShares", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "deposit", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "bool", "name": "approveMax", "type": "bool" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "depositWithSignature", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "lastRewardAmount", + "outputs": [{ "internalType": "uint192", "name": "", "type": "uint192" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastSync", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxDeposit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "maxMint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "maxRedeem", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "maxWithdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" } + ], + "name": "mint", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "name": "previewDeposit", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "previewMint", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "name": "previewRedeem", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "name": "previewWithdraw", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pricePerShare", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "redeem", + "outputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsCycleEnd", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rewardsCycleLength", + "outputs": [{ "internalType": "uint32", "name": "", "type": "uint32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "syncRewards", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalAssets", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "assets", "type": "uint256" }, + { "internalType": "address", "name": "receiver", "type": "address" }, + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "withdraw", + "outputs": [ + { "internalType": "uint256", "name": "shares", "type": "uint256" } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/dapp-oeth/src/hooks/useSwapEstimator.js b/dapp-oeth/src/hooks/useSwapEstimator.js index 85ac9a7bd9..0651aa3e9e 100644 --- a/dapp-oeth/src/hooks/useSwapEstimator.js +++ b/dapp-oeth/src/hooks/useSwapEstimator.js @@ -3,20 +3,16 @@ import { ethers, BigNumber } from 'ethers' import { useStoreState } from 'pullstate' import { get, minBy } from 'lodash' import AccountStore from 'stores/AccountStore' -import { - mintAbsoluteGasLimitBuffer, - mintPercentGasLimitBuffer, - redeemPercentGasLimitBuffer, - approveCoinGasLimits, - max_price, -} from 'utils/constants' +import { approveCoinGasLimits, max_price } from 'utils/constants' import { usePrevious } from 'utils/hooks' import useCurrencySwapper from 'hooks/useCurrencySwapper' import ContractStore from 'stores/ContractStore' -import { calculateSwapAmounts, formatCurrency } from 'utils/math' +import { calculateSwapAmounts } from 'utils/math' import fetchWithTimeout from 'utils/fetchWithTimeout' import { find } from 'lodash' +const parseFloatBN = (value) => parseFloat(ethers.utils.formatEther(value)) + const errorIncludes = (e, errorTxt) => { return ( (e.data && e.data.message && e.data.message.includes(errorTxt)) || @@ -374,6 +370,21 @@ const useSwapEstimator = ({ } } + let amountReceived = amount + + if (coinToSwap === 'sfrxeth') { + const [estimatedDeposit, frxEthMintPrice] = await Promise.all([ + contracts.sfrxeth + .previewDeposit(ethers.utils.parseUnits(String(amount))) + .then(parseFloatBN), + contracts.vault + .priceUnitMint(contracts.frxeth.address) + .then(parseFloatBN), + ]) + // previewDeposit * frx eth price should give a mint estimate receive + amountReceived = estimatedDeposit * frxEthMintPrice + } + const approveAllowanceNeeded = allowancesLoaded ? parseFloat(allowances[coinToSwap].zapper) < amount : true @@ -389,7 +400,7 @@ const useSwapEstimator = ({ approveGasUsage, approveAllowanceNeeded, inputAmount: parseFloat(inputAmountRaw), - amountReceived: amount, + amountReceived, } } diff --git a/dapp-oeth/src/utils/contracts.js b/dapp-oeth/src/utils/contracts.js index dc4136f368..e8610b31be 100644 --- a/dapp-oeth/src/utils/contracts.js +++ b/dapp-oeth/src/utils/contracts.js @@ -16,6 +16,7 @@ import daiAbi from 'constants/mainnetAbi/dai.json' import ognAbi from 'constants/mainnetAbi/ogn.json' import ogvAbi from 'constants/mainnetAbi/ogv.json' import veogvAbi from 'constants/mainnetAbi/veogv.json' +import sfrxethAbi from 'constants/mainnetAbi/sfrxeth.json' const curveFactoryMiniAbi = [ { @@ -241,7 +242,7 @@ export async function setupContracts(account, library, chainId, fetchId) { addresses.mainnet.WOETHProxy, network.contracts['WOETH'].abi ) - const sfrxeth = getContract(addresses.mainnet.sfrxETH, ognAbi) + const sfrxeth = getContract(addresses.mainnet.sfrxETH, sfrxethAbi) const zapper = getContract( addresses.mainnet.OETHZapper, network.contracts['OETHZapper'].abi From 709221e8af191d8b3066bc9c724ddfea66e213e3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 16 May 2023 12:20:56 -0400 Subject: [PATCH 2/3] Fix redeem and activity values --- dapp-oeth/public/images/activity.png | Bin 584 -> 530 bytes dapp-oeth/src/components/Nav.js | 7 ++++++- .../src/components/buySell/SwapCurrencyPill.js | 2 -- .../src/components/buySell/SwapHomepage.js | 14 +++++++------- dapp-oeth/src/hooks/useSwapEstimator.js | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dapp-oeth/public/images/activity.png b/dapp-oeth/public/images/activity.png index ebea1e1f343e100d7747399f8b830b5de93cdd4f..8d4530c075f1809465c3bba36bf16853ae1a3071 100644 GIT binary patch delta 468 zcmV;_0W1E<1d;@h7YZB*1^@s6at+^985T@@v`(_vfGr(&%CWb$gOlCUM zum9`cR;m9k?elT}>a9G_ALe|WtlDm$;)$e>Bjq77(cl=Ok|m{W zyqCk@>eZ(=piSFaRk<6MM12_*D27?3?_q&8AbB@Iz+NMRVL}(J=Xe5ONcyigFfAkK zb`Ilr3CgF&3z))`X+uJ_9L55aM?nnaGG;K`fGvR|X+NT&^%|e9j8q8QGsvn1J-{zI zZ@t7berE(f1;bpJ1_;#5VXSB$%%X9BY4n429E?&JHe18^b-gXx34@>LE1}pKVKHng zFmvV)%be+~j0Lbl;0m?~akd-A+DK{FtuxYLFbn%(tc{cg!_bIeUg}@JkBeZB_1U;{ zIjt(8#OI+~Q)lbX9FWA7kvyG=w>G=BL9;W1{xCn_@(5yQz;kB9=1dF((y6mQ$icv3 za6rU!=+>roW!<`iNF_eVy7doo(Ddxf?rD(N`Q%}AT2Tl6mA(N?UqdHHDmc>s0000< KMNUMnLSTZ&TiiYX delta 522 zcmV+l0`>ip1jq!C7YYyv1^@s616EOjbw;$qE~mNiTr1s6-_eF(-fj%*p3!KN3NFxQ|Lb4F)KPnP-xUg<8Y{giAL~4GS=rAi$A- z{z4EsDq2gbeIEsxDQI_R$h_5Rn}H@le3#8*6lA8Lm*rJ3%TW-$4?gAeRar zdc z|Hb+tjjvDp&9~Af&Vf*n=Ei=kr}hPgT%J4xAJ&I0hD3s_{Ca1c^J(V1hiBn+jJMQV zAIsy1Akn;O&?16)cahjaf^{`2pp-#Jg1O0K%~gs8` z {