Skip to content

Commit

Permalink
Add review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KMKoushik committed Feb 3, 2023
1 parent 1fbb2a7 commit eef9832
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { formatNumber } from '@utils/formatter'
import useStyles from '@components/Strategies/styles'
import { useBullProfitData } from '@state/bull/hooks'
import { getNextHedgeDate } from '@state/crab/utils'
import { getBullProfitDataPoints } from '@utils/strategyPayoff'
import { getBullExcessProfitDataPoints } from '@utils/strategyPayoff'

const useTooltipStyles = makeStyles(() => ({
root: {
Expand Down Expand Up @@ -135,7 +135,7 @@ const getDataPoints = (funding: number, ethPriceAtLastHedge: number, percentRang
const Chart: React.FC<{ currentFunding: number }> = ({ currentFunding }) => {
const ethPriceAtLastHedgeValue = useAtomValue(ethPriceAtLastHedgeAtomV2)
const ethPrice = useOnChainETHPrice()
const { profitData, loading } = useBullProfitData()
const { profitData } = useBullProfitData()

const impliedFunding = 2 * currentFunding // for 2 days
const ethPriceAtLastHedge = Number(toTokenAmount(ethPriceAtLastHedgeValue, 18))
Expand All @@ -150,7 +150,7 @@ const Chart: React.FC<{ currentFunding: number }> = ({ currentFunding }) => {
const nextHedgeTime = getNextHedgeDate(new Date(profitData.time * 1000)).getTime()
const timeUntilNextHedge = nextHedgeTime - new Date(profitData.time * 1000).getTime()
console.log('timeUntilNextHedge', timeUntilNextHedge)
return getBullProfitDataPoints(
return getBullExcessProfitDataPoints(
profitData.ethPriceAtHedge,
profitData.nf,
profitData.shortAmt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import useAmplitude from '@hooks/useAmplitude'
import { SITE_EVENTS } from '@utils/amplitude'
import { DateTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers'
import DateFnsUtils from '@date-io/date-fns'
import { firstDepositTimeAtom, firstDepositBlockAtom } from '@state/crab/atoms'
import { useSetAtom } from 'jotai'
import { useAtom, useSetAtom } from 'jotai'
import { bullFirstDepositBlockAtom, bullFirstDepositTimestampAtom } from '@state/bull/atoms'

const useTextFieldStyles = makeStyles((theme) =>
Expand Down Expand Up @@ -96,17 +95,16 @@ const gitBookLink = 'https://opyn.gitbook.io/opyn-strategies/zen-bull/introducti

const DepositTimePicker: React.FC = () => {
const aboutClasses = useAboutStyles()
const setDepositTime = useSetAtom(bullFirstDepositTimestampAtom)
const [depositTime, setDepositTime] = useAtom(bullFirstDepositTimestampAtom)
const setDepositBlock = useSetAtom(bullFirstDepositBlockAtom)
const [date, setDate] = useState(new Date())
const [date, setDate] = useState(new Date(depositTime ? depositTime * 1000 : Date.now()))

const onDepositDateChange = async (date: Date | null) => {
if (date) {
setDate(date)
setDepositTime(date.getTime() / 1000)
const resp = await fetch(`/api/getBlockNumber?timestamp=${date.getTime() / 1000}`)
const data = await resp.json()
console.log(data)
setDepositBlock(data.blockNumber)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import useAmplitude from '@hooks/useAmplitude'
import { SITE_EVENTS } from '@utils/amplitude'
import { DateTimePicker, MuiPickersUtilsProvider } from '@material-ui/pickers'
import DateFnsUtils from '@date-io/date-fns'
import { useAtomValue, useSetAtom } from 'jotai'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { addressAtom } from '@state/wallet/atoms'
import { firstDepositBlockAtom, firstDepositTimeAtom } from '@state/crab/atoms'

Expand Down Expand Up @@ -95,9 +95,9 @@ const gitBookLink = 'https://opyn.gitbook.io/opyn-strategies/crab-strategy/intro

const DepositTimePicker: React.FC = () => {
const aboutClasses = useAboutStyles()
const setDepositTime = useSetAtom(firstDepositTimeAtom)
const [depositTime, setDepositTime] = useAtom(firstDepositTimeAtom)
const setDepositBlock = useSetAtom(firstDepositBlockAtom)
const [date, setDate] = useState(new Date())
const [date, setDate] = useState(new Date(depositTime ? depositTime * 1000 : Date.now()))

const onDepositDateChange = async (date: Date | null) => {
if (date) {
Expand Down
10 changes: 5 additions & 5 deletions packages/frontend/src/utils/strategyPayoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const getCrabProfitDataPoints = (
}
}

export const getBullProfitDataPoints = (
export const getBullExcessProfitDataPoints = (
ethPriceAtHedge: number,
nf: number,
shortAmt: number,
Expand Down Expand Up @@ -134,10 +134,10 @@ export const getBullProfitDataPoints = (
const increment = new BigNumber(0.05)
const ending = new BigNumber(percentRange)

const ethRate = Math.exp(ethSupplyApy / (365 / time))
const usdRate = Math.exp(usdcBorrowApy / (365 / time))
const ethReturns = eulerEth * ethRate - eulerEth
const usdReturns = eulerUsdc * usdRate - eulerUsdc
const ethFutureValue = Math.exp(ethSupplyApy / (365 / time))
const usdFutureValue = Math.exp(usdcBorrowApy / (365 / time))
const ethReturns = eulerEth * ethFutureValue - eulerEth
const usdReturns = eulerUsdc * usdFutureValue - eulerUsdc

const { thresholdLower, thresholdUpper } = getProfitThresholds(
0.5 * gammaPortfolio,
Expand Down

0 comments on commit eef9832

Please sign in to comment.