Skip to content

Commit

Permalink
fix(rai): Adds rai options to kovan and it works! Defaults to weth on…
Browse files Browse the repository at this point in the history
… liquidity.
  • Loading branch information
Alexangelj committed Mar 13, 2021
1 parent 709aca1 commit e6ab123
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/state/options/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import { Pair, Token, TokenAmount } from '@sushiswap/sdk'
import * as SushiSwapSDK from '@sushiswap/sdk'
import ethers, { BigNumberish, BigNumber } from 'ethers'

import { Protocol } from '@primitivefi/sdk'
import { Trade, Option, SushiSwapMarket, Venue } from '@primitivefi/sdk'
import {
Protocol,
Option,
SushiSwapMarket,
Venue,
TEST_OPTIONS,
} from '@primitivefi/sdk'

import { useActiveWeb3React } from '@/hooks/user/index'
import { useAddNotif } from '@/state/notifs/hooks'
import { STABLECOINS } from '@/constants/index'
import { optionAddresses, testAddresses } from '@/constants/options'
import { optionAddresses } from '@/constants/options'
const { ChainId } = SushiSwapSDK

export const useOptions = (): OptionsState => {
Expand All @@ -43,6 +48,7 @@ export const useUpdateOptions = (): ((
const addNotif = useAddNotif()
const router = useRouter()
const dispatch = useDispatch<AppDispatch>()
const isTestnet = chainId === ChainId.RINKEBY || chainId === ChainId.KOVAN

return useCallback(
async (
Expand All @@ -54,19 +60,23 @@ export const useUpdateOptions = (): ((
const calls: OptionsAttributes[] = []
const puts: OptionsAttributes[] = []
const provider = library
const isUniswap = venue === Venue.UNISWAP ? true : false
console.log('loading options')
console.log(`loading options for ${assetName}`)
setTimeout(() => {
if (!provider) {
console.log('system fail')
return
}
}, 200)
const key =
assetName === '' || assetName === 'WETH'
? 'eth'
: assetName.toLowerCase()
const testAddresses = TEST_OPTIONS[key][chainId]?.map(
(option) => option.address
)
Protocol.getOptionsUsingMultiCall(
chainId,
chainId == ChainId.RINKEBY || chainId == ChainId.KOVAN
? testAddresses
: optionAddresses,
isTestnet ? testAddresses : optionAddresses,
provider
)
.then((optionEntitiesObject) => {
Expand All @@ -76,11 +86,7 @@ export const useUpdateOptions = (): ((
for (let i = 0; i < allKeys.length; i++) {
const key: string = allKeys[i]
const option: Option = optionEntitiesObject[key]
allPairAddresses.push(
isUniswap
? option.uniswapPairAddress
: option.sushiswapPairAddress
)
allPairAddresses.push(option.sushiswapPairAddress)
allTokensArray.push([
option.redeem.address,
option.underlying.address,
Expand Down Expand Up @@ -192,7 +198,7 @@ export const useUpdateOptions = (): ((
'WETH') &&
(option.strikePrice === '5000' ||
option.strikePrice === '30')) ||
chainId === ChainId.RINKEBY
isTestnet
) {
pairReserveTotal[0] = pairReserveTotal[0].add(
BigNumber.from(underlyingReserve)
Expand All @@ -211,7 +217,7 @@ export const useUpdateOptions = (): ((
assetName.toUpperCase() &&
(option.strikePrice === '5000' ||
option.strikePrice === '30')) ||
chainId === ChainId.RINKEBY
isTestnet
) {
pairReserveTotal[0] = pairReserveTotal[0].add(
BigNumber.from(underlyingReserve)
Expand All @@ -236,7 +242,7 @@ export const useUpdateOptions = (): ((
STABLECOINS[chainId].address ||
option.quoteValue.token.address ===
assetAddress)) ||
chainId === ChainId.RINKEBY
isTestnet
) {
pairReserveTotal[0] = pairReserveTotal[0].add(
BigNumber.from(underlyingReserve)
Expand All @@ -259,7 +265,7 @@ export const useUpdateOptions = (): ((
STABLECOINS[chainId].address ||
option.quoteValue.token.address ===
assetAddress)) ||
chainId === ChainId.RINKEBY
isTestnet
) {
pairReserveTotal[1] = pairReserveTotal[1].add(
BigNumber.from(underlyingReserve)
Expand Down

0 comments on commit e6ab123

Please sign in to comment.