Skip to content

Commit

Permalink
feat: Newport Optimism markets
Browse files Browse the repository at this point in the history
  • Loading branch information
stuontheblockchain authored May 22, 2023
1 parent 4d8df51 commit d8882b6
Show file tree
Hide file tree
Showing 107 changed files with 25,660 additions and 2,633 deletions.
File renamed without changes
Binary file removed app/public/images/arbitrum-vaults.png
Binary file not shown.
5 changes: 5 additions & 0 deletions app/public/images/op-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/public/images/optimism.png
Binary file not shown.
59 changes: 0 additions & 59 deletions app/src/components/common/VaultSelector/index.tsx

This file was deleted.

15 changes: 15 additions & 0 deletions app/src/constants/deprecated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Chain, Version } from '@lyrafinance/lyra-js'

import filterNulls from '../utils/filterNulls'

export type DeprecatedVault = {
chain: Chain
version: Version
}

export const DEPRECATED_VAULTS_LIST: DeprecatedVault[] = filterNulls([
{
chain: Chain.Optimism,
version: Version.Avalon,
},
])
1 change: 1 addition & 0 deletions app/src/constants/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export type Vault = {
allWithdrawals: LiquidityWithdrawal[]
pnl: number
pnlPercentage: number
isDeprecated: boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { PopulatedTransaction } from '@ethersproject/contracts'
import Box from '@lyra/ui/components/Box'
import Button from '@lyra/ui/components/Button'
import CardBody from '@lyra/ui/components/Card/CardBody'
import Collapsible from '@lyra/ui/components/Collapsible'
import Flex from '@lyra/ui/components/Flex'
import Input from '@lyra/ui/components/Input'
import BigNumberInput from '@lyra/ui/components/Input/BigNumberInput'
import Modal from '@lyra/ui/components/Modal'
import Text from '@lyra/ui/components/Text'
import formatNumber from '@lyra/ui/utils/formatNumber'
import { AdminAdapterMarketConfigurationParams, Market } from '@lyrafinance/lyra-js'
import { SNXPerpV2Adapter } from '@lyrafinance/lyra-js/src/contracts/newport/typechain/NewportSNXPerpV2Adapter'
import { BigNumber } from 'ethers'
import React, { useState } from 'react'

import { ZERO_BN } from '@/app/constants/bn'
import { TransactionType } from '@/app/constants/screen'
import useAdmin from '@/app/hooks/admin/useAdmin'
import useAdminTransaction from '@/app/hooks/admin/useAdminTransaction'
import fromBigNumber from '@/app/utils/fromBigNumber'

import TransactionButton from '../../common/TransactionButton'

type Props = {
market: Market
isExpanded: boolean
onClickExpand: () => void
}

const zeroDecimalKeys: (keyof AdminAdapterMarketConfigurationParams)[] = []

const AdminMarketAdapterConfigurationParams = ({ market, isExpanded, onClickExpand }: Props) => {
const admin = useAdmin(market.lyra.network)
const [isConfirmOpen, setIsConfirmOpen] = useState(false)
const [params, setParams] = useState<Partial<AdminAdapterMarketConfigurationParams>>({})
const [newParams, setNewParams] = useState<Partial<AdminAdapterMarketConfigurationParams>>({})
const [tx, setTx] = useState<PopulatedTransaction | null>(null)
const execute = useAdminTransaction(market.lyra.network, market.params.owner)
if (!market.params.adapterView) {
return null
}
const marketAdapterParams = (market.params.adapterView as SNXPerpV2Adapter.MarketAdapterStateStructOutput)?.config
const marketAdapterParamsFlat = {
staticEstimationDiscount: marketAdapterParams.staticEstimationDiscount,
snxPerpV2MarketAddress: marketAdapterParams.snxPerpV2MarketAddress,
pool: marketAdapterParams.uniswapInfo.pool,
feeTier: marketAdapterParams.uniswapInfo.feeTier,
}
return (
<>
<Collapsible
onClickHeader={onClickExpand}
header={<Text variant="cardHeading">Adapter Market Configuration Parameters</Text>}
isExpanded={isExpanded}
>
<Box p={4}>
{Object.entries(marketAdapterParamsFlat).map(([key, value]) => {
if (parseInt(key) || parseInt(key) === 0) {
return
}
const typedKey = key as keyof AdminAdapterMarketConfigurationParams
const isZeroDecimals = zeroDecimalKeys.includes(typedKey)
if (typeof value === 'string') {
const val = params[typedKey] ?? ''
return (
<Input
key={key}
label={key}
value={val.toString()}
placeholder={value}
onChange={evt => setParams({ ...params, [key]: evt.target.value })}
/>
)
}
const val = (params[typedKey] ?? ZERO_BN) as BigNumber
return (
<Flex flexDirection="column" mb={4} key={key}>
<BigNumberInput
decimals={isZeroDecimals ? 0 : 18}
label={key}
min={ZERO_BN}
value={val}
key={key}
placeholder={isZeroDecimals ? fromBigNumber(val, 0).toString() : val}
onEmpty={() => {
const toParams = { ...params }
delete toParams[typedKey]
setParams(toParams)
}}
onChange={val => {
const newGreekCacheParams = {
...params,
[key]: val,
}
setParams(newGreekCacheParams)
}}
/>
</Flex>
)
})}
<Button
width={200}
size="lg"
variant="primary"
label="Update"
onClick={async () => {
const { tx, params: newParams } = await admin.setAdapterMarketConfigurationParams(market.address, params)
setNewParams(newParams)
setTx(tx)
setIsConfirmOpen(true)
}}
/>
</Box>
</Collapsible>
<Modal
isOpen={isConfirmOpen}
onClose={() => setIsConfirmOpen(false)}
title="Confirm New Adapter Market Pricing Params"
>
<CardBody>
<Box>
{newParams
? Object.entries(newParams).map(([key, value]) => {
if (parseInt(key) || parseInt(key) === 0) {
return
}
const typedKey = key as keyof AdminAdapterMarketConfigurationParams
const isZeroDecimals = zeroDecimalKeys.includes(typedKey)
const val = value ?? ZERO_BN
return (
<Flex my={2} key={key} justifyContent="space-between">
<Text color="secondaryText">{key}</Text>
{typeof val === 'string' ? (
<Text ml={1}>{val}</Text>
) : (
<Text ml={1}>
{formatNumber(fromBigNumber(val as BigNumber, isZeroDecimals ? 0 : 18), { minDps: 0 })}
</Text>
)}
</Flex>
)
})
: null}
</Box>
<TransactionButton
transactionType={TransactionType.Admin}
network={market.lyra.network}
width="100%"
label="Confirm"
onClick={async () => {
if (tx) {
await execute(tx)
setIsConfirmOpen(false)
}
}}
/>
</CardBody>
</Modal>
</>
)
}

export default AdminMarketAdapterConfigurationParams
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Modal from '@lyra/ui/components/Modal'
import Text from '@lyra/ui/components/Text'
import formatNumber from '@lyra/ui/utils/formatNumber'
import { AdminAdapterMarketPricingParams, Market } from '@lyrafinance/lyra-js'
import { GMXAdapter } from '@lyrafinance/lyra-js/src/contracts/newport/typechain/NewportGMXAdapter'
import React, { useState } from 'react'

import { ZERO_BN } from '@/app/constants/bn'
Expand Down Expand Up @@ -45,7 +46,9 @@ const AdminMarketAdapterPricingParams = ({ market, isExpanded, onClickExpand }:
isExpanded={isExpanded}
>
<Box p={4}>
{Object.entries(market.params.adapterView.marketPricingParams).map(([key, value]) => {
{Object.entries(
(market.params.adapterView as GMXAdapter.GMXAdapterStateStructOutput)?.marketPricingParams
).map(([key, value]) => {
if (parseInt(key) || parseInt(key) === 0) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const AdminMarketFuturesPoolHedgerParams = withSuspense(
}

return (
<Flex flexDirection="column" key={key}>
<Flex flexDirection="column" mb={4} key={key}>
<BigNumberInput
decimals={isZeroDecimals ? 0 : 18}
label={key}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AdminMarketPoolHedgerParams = withSuspense(
const isZeroDecimals = zeroDecimalKeys.includes(typedKey)
const val = params[typedKey] ?? ZERO_BN
return (
<Flex flexDirection="column" key={key}>
<Flex flexDirection="column" mb={4} key={key}>
<BigNumberInput
decimals={isZeroDecimals ? 0 : 18}
label={key}
Expand Down
4 changes: 2 additions & 2 deletions app/src/containers/earn/RewardsClaimModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RowItem from '@/app/components/common/RowItem'
import { VAULT_REWARDS_DOC_URL } from '@/app/constants/links'
import { TransactionType } from '@/app/constants/screen'
import useTransaction from '@/app/hooks/account/useTransaction'
import { useMutateRewardsPageData } from '@/app/hooks/rewards/useRewardsPageData'
import { useMutateEarnPageData } from '@/app/hooks/rewards/useEarnPageData'
import formatRewardTokenAmounts from '@/app/utils/formatRewardTokenAmounts'
import formatTokenName from '@/app/utils/formatTokenName'
import getLyraSDK from '@/app/utils/getLyraSDK'
Expand All @@ -33,7 +33,7 @@ type Props = {
export default function RewardsClaimModal({ accountRewardEpoch, isOpen, onClose }: Props) {
const [isVaultExpanded, setIsVaultExpanded] = useState(true)
const execute = useTransaction(accountRewardEpoch.lyra.network)
const mutateRewardsPageData = useMutateRewardsPageData()
const mutateRewardsPageData = useMutateEarnPageData()
const totalTradingRewards = accountRewardEpoch.totalClaimableTradingRewards

const totalRewards = accountRewardEpoch.totalClaimableRewards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react'

import { SECONDS_IN_HOUR } from '@/app/constants/time'
import useNetwork from '@/app/hooks/account/useNetwork'
import { LatestRewardEpoch } from '@/app/hooks/rewards/useRewardsPageData'
import { LatestRewardEpoch } from '@/app/hooks/rewards/useEarnPageData'

type Props = {
latestRewardEpochs: LatestRewardEpoch[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useMemo } from 'react'
import LabelItem from '@/app/components/common/LabelItem'
import { AppNetwork } from '@/app/constants/networks'
import RewardsUnstakeModal from '@/app/containers/earn_index/RewardsUnstakeModal'
import { LatestRewardEpoch } from '@/app/hooks/rewards/useRewardsPageData'
import { LatestRewardEpoch } from '@/app/hooks/rewards/useEarnPageData'
import { LyraBalances } from '@/app/utils/common/fetchLyraBalances'
import { getStkLyraBalanceForNetwork } from '@/app/utils/common/getLyraBalanceForNetwork'
import { LyraStaking } from '@/app/utils/rewards/fetchLyraStaking'
Expand Down
2 changes: 1 addition & 1 deletion app/src/containers/earn_index/RewardsStakingCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CardSeparator from '@lyra/ui/components/Card/CardSeparator'
import useIsMobile from '@lyra/ui/hooks/useIsMobile'
import React from 'react'

import { LatestRewardEpoch } from '@/app/hooks/rewards/useRewardsPageData'
import { LatestRewardEpoch } from '@/app/hooks/rewards/useEarnPageData'
import { LyraBalances } from '@/app/utils/common/fetchLyraBalances'
import { LyraStaking } from '@/app/utils/rewards/fetchLyraStaking'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppNetwork } from '@/app/constants/networks'
import { TransactionType } from '@/app/constants/screen'
import useTransaction from '@/app/hooks/account/useTransaction'
import useWalletAccount from '@/app/hooks/account/useWalletAccount'
import { useMutateRewardsPageData } from '@/app/hooks/rewards/useRewardsPageData'
import { useMutateEarnPageData } from '@/app/hooks/rewards/useEarnPageData'
import getContract from '@/app/utils/common/getContract'
import { LyraStaking } from '@/app/utils/rewards/fetchLyraStaking'

Expand All @@ -19,7 +19,7 @@ type Props = {
const RewardsStakingClaimButton = ({ lyraStaking, onClaim }: Props) => {
const account = useWalletAccount()
const execute = useTransaction(AppNetwork.Ethereum)
const mutateRewardsPageData = useMutateRewardsPageData()
const mutateRewardsPageData = useMutateEarnPageData()
const { claimableRewards } = lyraStaking
const handleStkLyraClaim = async () => {
if (!account) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AppNetwork } from '@/app/constants/networks'
import { TransactionType } from '@/app/constants/screen'
import useTransaction from '@/app/hooks/account/useTransaction'
import useWalletAccount from '@/app/hooks/account/useWalletAccount'
import { useMutateRewardsPageData } from '@/app/hooks/rewards/useRewardsPageData'
import { useMutateEarnPageData } from '@/app/hooks/rewards/useEarnPageData'
import { LyraBalances } from '@/app/utils/common/fetchLyraBalances'
import getContract from '@/app/utils/common/getContract'
import { getStkLyraBalanceForNetwork } from '@/app/utils/common/getLyraBalanceForNetwork'
Expand All @@ -29,7 +29,7 @@ type Props = {
const RewardsUnstakeModalButton = ({ amount, lyraBalances, lyraStaking, onClose, ...styleProps }: Props) => {
const account = useWalletAccount()
const execute = useTransaction(AppNetwork.Ethereum)
const mutateRewardsPageData = useMutateRewardsPageData()
const mutateRewardsPageData = useMutateEarnPageData()

const handleClickRequestUnstake = useCallback(async () => {
if (!account) {
Expand Down
Loading

0 comments on commit d8882b6

Please sign in to comment.