Skip to content

Commit

Permalink
Auction estimate based on ref vol (#115)
Browse files Browse the repository at this point in the history
* first go at ref vol based auction estimate

* fix rerender

* remove breaking borales things

* remove breaking borales things

---------

Co-authored-by: nikhil arora <narora200@gmail.com>
  • Loading branch information
alpinechicken and nikkaroraa authored Nov 27, 2023
1 parent 5d6ad1d commit ab6353b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
- uses: borales/actions-yarn@v3.0.0
with:
cmd: install # will run `yarn install` command
- uses: borales/actions-yarn@v3.0.0
with:
cmd: test # will run `yarn test` command
- run: yarn install
- run: yarn test
20 changes: 18 additions & 2 deletions hooks/useAuctionEstimate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber } from 'ethers'
import { useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useState, useMemo } from 'react'
import shallow from 'zustand/shallow'
import { BIG_ZERO } from '../constants/numbers'
import { useCalmBullStore } from '../store/calmBullStore'
Expand All @@ -8,6 +8,7 @@ import useCrabV2Store from '../store/crabV2Store'
import usePriceStore from '../store/priceStore'
import { AuctionStatus, AuctionType } from '../types'
import { bnComparator } from '../utils'
import useControllerStore from '../store/controllerStore'
import { estimateAuction as estimateCrabAuction, getAuctionStatus } from '../utils/auction'
import { getWsqueethFromCrabAmount } from '../utils/crab'
import { calculateTotalDeposit } from '../utils/crabNetting'
Expand All @@ -17,7 +18,22 @@ import useQuoter from './useQuoter'

export const useAuctionEstimate = () => {
const auction = useCrabV2Store(s => s.auction)
const oSqthPrice = usePriceStore(s => s.oSqthPrice, bnComparator)
const { ethPriceBN } = usePriceStore(s => ({ ethPriceBN: s.ethPrice }), shallow)
const { osqthRefVol } = useCrabV2Store(s => ({ osqthRefVol: s.oSqthRefVolIndex }), shallow)
const { nfBN } = useControllerStore(s => ({ nfBN: s.normFactor }), shallow)

const ethPrice = convertBigNumber(auction.ethPrice || ethPriceBN, 18)
const nf = convertBigNumber(auction.normFactor || nfBN, 18)
const refVol = auction.osqthRefVol ?? osqthRefVol
const refPrice = ((ethPrice * nf * Math.exp((refVol / 100) ** 2 * (17.5 / 365))) / 10000) * 1e18
console.log('refVol is', refVol)
console.log('nf is', nf)
console.log('ethPrice is', ethPrice)
console.log('ref price is', refPrice)

// const oSqthPrice = usePriceStore(s => s.oSqthPrice, bnComparator)
const oSqthPrice = useMemo(() => BigNumber.from(refPrice.toFixed()), [refPrice]) // use ref price instead of pool price
console.log('oSQTH price is', oSqthPrice.toString())
const vault = useCrabV2Store(s => s.vault, shallow)
const usdcDeposits = useCrabNettingStore(s => s.depositQueued, bnComparator)
const crabDeposits = useCrabNettingStore(s => s.withdrawQueued, bnComparator)
Expand Down

3 comments on commit ab6353b

@vercel
Copy link

@vercel vercel bot commented on ab6353b Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on ab6353b Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on ab6353b Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.