From 3fb17cfe4d70f0b73f200b7ed0fe2d719dcd9365 Mon Sep 17 00:00:00 2001 From: Michael Wu <87842872+michaelxuwu@users.noreply.github.com> Date: Thu, 25 May 2023 12:38:42 +1000 Subject: [PATCH] feat: Optimism Newport trading --- .../index.tsx | 30 +- .../index.tsx | 9 +- app/src/hooks/market/useTradePageData.ts | 7 +- app/src/utils/getDefaultMarket.ts | 3 +- app/src/utils/lyra.ts | 3 +- sdk/src/admin/index.ts | 55 +- sdk/src/constants/mappings.ts | 3 +- .../abis/NewportSNXPerpsV2PoolHedger.json | 2505 ++++++++--------- .../typechain/NewportSNXPerpsV2PoolHedger.ts | 87 +- .../NewportSNXPerpsV2PoolHedger__factory.ts | 233 +- sdk/src/market/index.ts | 3 +- sdk/src/quote/getQuoteDisabledReason.ts | 22 +- sdk/src/utils/canHedge.ts | 6 +- sdk/src/utils/canHedgeArbitrum.ts | 9 +- sdk/src/utils/canHedgeOptimism.ts | 36 +- .../utils/fetchNewportOptimismMarketViews.ts | 5 +- sdk/src/utils/fetchSpotPriceHistory.ts | 1 - sdk/src/utils/getLyraDeploymentSubgraphURI.ts | 1 - sdk/src/utils/parseBaseSymbol.ts | 2 - ui/components/Table/index.tsx | 154 +- 20 files changed, 1364 insertions(+), 1810 deletions(-) diff --git a/app/src/containers/admin/AdminMarketAdapterConfigurationParams/index.tsx b/app/src/containers/admin/AdminMarketAdapterConfigurationParams/index.tsx index 91e2019e..39aa1a0b 100644 --- a/app/src/containers/admin/AdminMarketAdapterConfigurationParams/index.tsx +++ b/app/src/containers/admin/AdminMarketAdapterConfigurationParams/index.tsx @@ -65,6 +65,7 @@ const AdminMarketAdapterConfigurationParams = ({ market, isExpanded, onClickExpa const val = params[typedKey] ?? '' return ( setParams({ ...params, [key]: evt.target.value })} /> ) + } else if (typeof value === 'number') { + const val = params[typedKey] ?? '' + return ( + { + const toParams = { ...params, [key]: parseFloat(evt.target.value) } + if (evt.target.value === '') { + delete toParams[typedKey] + } + setParams(toParams) + }} + /> + ) } const val = (params[typedKey] ?? ZERO_BN) as BigNumber return ( @@ -82,18 +101,18 @@ const AdminMarketAdapterConfigurationParams = ({ market, isExpanded, onClickExpa min={ZERO_BN} value={val} key={key} - placeholder={isZeroDecimals ? fromBigNumber(val, 0).toString() : val} + placeholder={isZeroDecimals ? fromBigNumber(value, 0).toString() : value} onEmpty={() => { const toParams = { ...params } delete toParams[typedKey] setParams(toParams) }} onChange={val => { - const newGreekCacheParams = { + const newParams = { ...params, [key]: val, } - setParams(newGreekCacheParams) + setParams(newParams) }} /> @@ -116,7 +135,8 @@ const AdminMarketAdapterConfigurationParams = ({ market, isExpanded, onClickExpa setIsConfirmOpen(false)} - title="Confirm New Adapter Market Pricing Params" + title="Confirm New Adapter Market Configuration Params" + desktopWidth={700} > @@ -131,7 +151,7 @@ const AdminMarketAdapterConfigurationParams = ({ market, isExpanded, onClickExpa return ( {key} - {typeof val === 'string' ? ( + {typeof val === 'string' || typeof val === 'number' ? ( {val} ) : ( diff --git a/app/src/containers/admin/AdminMarketFuturesPoolHedgerParams/index.tsx b/app/src/containers/admin/AdminMarketFuturesPoolHedgerParams/index.tsx index 5873b290..0aa24e3d 100644 --- a/app/src/containers/admin/AdminMarketFuturesPoolHedgerParams/index.tsx +++ b/app/src/containers/admin/AdminMarketFuturesPoolHedgerParams/index.tsx @@ -11,7 +11,12 @@ import Modal from '@lyra/ui/components/Modal' import Shimmer from '@lyra/ui/components/Shimmer' import Text from '@lyra/ui/components/Text' import formatNumber from '@lyra/ui/utils/formatNumber' -import { FuturesPoolHedgerParams, Market } from '@lyrafinance/lyra-js' +import { + FuturesPoolHedgerParams, + GMXFuturesPoolHedgerParams, + Market, + SNXFuturesPoolHedgerParams, +} from '@lyrafinance/lyra-js' import React, { useState } from 'react' import { ZERO_BN } from '@/app/constants/bn' @@ -29,7 +34,7 @@ type Props = { onClickExpand: () => void } -const zeroDecimalKeys: (keyof FuturesPoolHedgerParams)[] = ['minCancelDelay'] +const zeroDecimalKeys: (keyof GMXFuturesPoolHedgerParams | keyof SNXFuturesPoolHedgerParams)[] = ['minCancelDelay'] const AdminMarketFuturesPoolHedgerParams = withSuspense( ({ market, isExpanded, onClickExpand }: Props) => { diff --git a/app/src/hooks/market/useTradePageData.ts b/app/src/hooks/market/useTradePageData.ts index fa3eea0f..1c577c46 100644 --- a/app/src/hooks/market/useTradePageData.ts +++ b/app/src/hooks/market/useTradePageData.ts @@ -7,7 +7,6 @@ import coerce from '@/app/utils/coerce' import fetchMarkets from '@/app/utils/fetchMarkets' import getLyraSDK from '@/app/utils/getLyraSDK' import getPageHeartbeat from '@/app/utils/getPageHeartbeat' -import { lyraAvalon } from '@/app/utils/lyra' import useWalletAccount from '../account/useWalletAccount' import useFetch, { useMutate } from '../data/useFetch' @@ -18,12 +17,10 @@ type TradeRoot = { } const fetchTradePageData = async (network: Network, owner: string | null): Promise => { - const lyra = network === Network.Optimism ? lyraAvalon : getLyraSDK(network) - const maybeFetchPositions = async (): Promise => (owner ? lyra.openPositions(owner) : []) + const maybeFetchPositions = async (): Promise => (owner ? getLyraSDK(network).openPositions(owner) : []) const [markets, openPositions] = await Promise.all([fetchMarkets([network]), maybeFetchPositions()]) return { - // TODO @michaelxuwu update filtering when trading goes live - markets: markets.filter(m => m.lyra.network !== Network.Optimism || m.lyra.version === Version.Avalon), + markets: markets.filter(m => m.lyra.version !== Version.Avalon), openPositions: openPositions.sort((a, b) => a.expiryTimestamp - b.expiryTimestamp), } } diff --git a/app/src/utils/getDefaultMarket.ts b/app/src/utils/getDefaultMarket.ts index 3efb02ea..33f847a4 100644 --- a/app/src/utils/getDefaultMarket.ts +++ b/app/src/utils/getDefaultMarket.ts @@ -3,8 +3,7 @@ import { Network } from '@lyrafinance/lyra-js' export const getDefaultMarket = (network: Network) => { switch (network) { case Network.Arbitrum: - return 'eth-usdc' case Network.Optimism: - return 'seth-susd' + return 'eth-usdc' } } diff --git a/app/src/utils/lyra.ts b/app/src/utils/lyra.ts index bc591cf6..f3403de4 100644 --- a/app/src/utils/lyra.ts +++ b/app/src/utils/lyra.ts @@ -14,7 +14,7 @@ export const arbitrumProvider = new CachedStaticJsonRpcProvider( arbitrumNetworkConfig.chainId ) -const getLyraSubgraphURI = (chain: Chain, version: Version): string | undefined => { +const getLyraSubgraphURI = (chain: Chain, version: Version = Version.Newport): string | undefined => { const SATSUMA_API_KEY = process.env.REACT_APP_SATSUMA_API_KEY if (!SATSUMA_API_KEY) { // Use SDK default @@ -26,6 +26,7 @@ const getLyraSubgraphURI = (chain: Chain, version: Version): string | undefined case Version.Avalon: return `https://subgraph.satsuma-prod.com/${SATSUMA_API_KEY}/lyra/optimism-mainnet/api` case Version.Newport: + default: return `https://subgraph.satsuma-prod.com/${SATSUMA_API_KEY}/lyra/optimism-mainnet-newport/api` } case Chain.OptimismGoerli: diff --git a/sdk/src/admin/index.ts b/sdk/src/admin/index.ts index 864d9d58..22941e51 100644 --- a/sdk/src/admin/index.ts +++ b/sdk/src/admin/index.ts @@ -1,16 +1,13 @@ import { BigNumber } from '@ethersproject/bignumber' import { PopulatedTransaction } from '@ethersproject/contracts' -import Lyra, { MarketContractAddresses, Version } from '..' +import Lyra, { MarketContractAddresses, Network, Version } from '..' import { LyraContractId, LyraGlobalContractId, LyraMarketContractId } from '../constants/contracts' import { LyraContractMap, LyraMarketContractMap } from '../constants/mappings' import { GMXAdapter, NewportGMXAdapter } from '../contracts/newport/typechain/NewportGMXAdapter' -import { - GMXFuturesPoolHedger, - NewportGMXFuturesPoolHedger, -} from '../contracts/newport/typechain/NewportGMXFuturesPoolHedger' +import { NewportGMXFuturesPoolHedger } from '../contracts/newport/typechain/NewportGMXFuturesPoolHedger' import { OptionGreekCache } from '../contracts/newport/typechain/NewportOptionGreekCache' -import { SNXPerpsV2PoolHedger } from '../contracts/newport/typechain/NewportSNXPerpsV2PoolHedger' +import { NewportSNXPerpsV2PoolHedger } from '../contracts/newport/typechain/NewportSNXPerpsV2PoolHedger' import { NewportSNXPerpV2Adapter, SNXPerpV2Adapter } from '../contracts/newport/typechain/NewportSNXPerpV2Adapter' import buildTx from '../utils/buildTx' import fetchGlobalOwner from '../utils/fetchGlobalOwner' @@ -211,7 +208,19 @@ export type PoolHedgerParams = { hedgeCap: BigNumber } -export type FuturesPoolHedgerParams = { +export type FuturesPoolHedgerParams = GMXFuturesPoolHedgerParams | SNXFuturesPoolHedgerParams + +export type SNXFuturesPoolHedgerParams = { + targetLeverage: BigNumber + maximumFundingRate: BigNumber + deltaThreshold: BigNumber + marketDepthBuffer: BigNumber + priceDeltaBuffer: BigNumber + worstStableRate: BigNumber + maxOrderCap: BigNumber +} + +export type GMXFuturesPoolHedgerParams = { acceptableSpotSlippage: BigNumber deltaThreshold: BigNumber marketDepthBuffer: BigNumber @@ -779,7 +788,7 @@ export class Admin { ) { const market = await this.lyra.market(marketAddressOrName) if (!(market.params.adapterView as SNXPerpV2Adapter.MarketAdapterStateStructOutput)) { - throw new Error('Adapter market pricing parameters not supported on this market') + throw new Error('Adapter market configuration parameters not supported on this market') } const marketAdapterConfig = (market.params.adapterView as SNXPerpV2Adapter.MarketAdapterStateStructOutput).config const fromParamsFlat: AdminAdapterMarketConfigurationParams = { @@ -837,6 +846,7 @@ export class Admin { params: Partial ): Promise> { const market = await this.lyra.market(marketAddressOrName) + if (market.lyra.version !== Version.Newport || !market.params.hedgerView) { throw new Error('Parameters not supported on version') } @@ -847,30 +857,25 @@ export class Admin { market.lyra.version, LyraMarketContractId.PoolHedger ) - - const futurePoolHedgerParams: - | SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParametersStructOutput - | GMXFuturesPoolHedger.FuturesPoolHedgerParametersStructOutput = - (market.params.hedgerView as GMXFuturesPoolHedger.GMXFuturesPoolHedgerViewStructOutput) - ?.futuresPoolHedgerParams ?? - (market.params.hedgerView as SNXPerpsV2PoolHedger.HedgerStateStructOutput)?.futuresPoolHedgerParams - const toParams = { - ...futurePoolHedgerParams, + ...market.params.hedgerView.futuresPoolHedgerParams, ...params, } - - const owner = await market.owner() - - const calldata = (futuresPoolHedger as NewportGMXFuturesPoolHedger).interface.encodeFunctionData( - 'setFuturesPoolHedgerParams', - [toParams] - ) + const calldata = + market.lyra.network === Network.Optimism + ? (futuresPoolHedger as NewportSNXPerpsV2PoolHedger).interface.encodeFunctionData( + 'setFuturesPoolHedgerParams', + [toParams as SNXFuturesPoolHedgerParams] + ) + : (futuresPoolHedger as NewportGMXFuturesPoolHedger).interface.encodeFunctionData( + 'setFuturesPoolHedgerParams', + [toParams as GMXFuturesPoolHedgerParams] + ) const tx = buildTx( this.lyra.provider, this.lyra.provider.network.chainId, futuresPoolHedger.address, - owner, + market.params.owner, calldata ) tx.gasLimit = BigNumber.from(10_000_000) diff --git a/sdk/src/constants/mappings.ts b/sdk/src/constants/mappings.ts index 3139c2ca..bc686451 100644 --- a/sdk/src/constants/mappings.ts +++ b/sdk/src/constants/mappings.ts @@ -26,6 +26,7 @@ import { NewportOptionMarketViewer, NewportOptionToken, NewportShortCollateral, + NewportSNXPerpsV2PoolHedger, NewportSNXPerpV2Adapter, NewportTestFaucet, } from '../contracts/newport/typechain' @@ -71,7 +72,7 @@ export type LyraMarketNewportContractMap = { [LyraMarketContractId.OptionGreekCache]: NewportOptionGreekCache [LyraMarketContractId.LiquidityToken]: NewportLiquidityToken [LyraMarketContractId.LiquidityPool]: NewportLiquidityPool - [LyraMarketContractId.PoolHedger]: NewportGMXFuturesPoolHedger + [LyraMarketContractId.PoolHedger]: NewportGMXFuturesPoolHedger | NewportSNXPerpsV2PoolHedger } export type LyraMarketContractMap = V extends Version.Avalon diff --git a/sdk/src/contracts/newport/abis/NewportSNXPerpsV2PoolHedger.json b/sdk/src/contracts/newport/abis/NewportSNXPerpsV2PoolHedger.json index 53009f4c..c86f7ad9 100644 --- a/sdk/src/contracts/newport/abis/NewportSNXPerpsV2PoolHedger.json +++ b/sdk/src/contracts/newport/abis/NewportSNXPerpsV2PoolHedger.json @@ -1,1372 +1,1135 @@ [ - { - "inputs":[ - - ], - "stateMutability":"nonpayable", - "type":"constructor" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - } - ], - "name":"AlreadyInitialised", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"contract IERC20Decimals", - "name":"asset", - "type":"address" - }, - { - "internalType":"address", - "name":"approving", - "type":"address" - }, - { - "internalType":"uint256", - "name":"approvalAmount", - "type":"uint256" - } - ], - "name":"ApprovalFailure", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"uint8", - "name":"id", - "type":"uint8" - }, - { - "internalType":"address", - "name":"addr", - "type":"address" - } - ], - "name":"DuplicateEntry", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"uint256", - "name":"lastInteraction", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"interactionDelta", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"currentTime", - "type":"uint256" - } - ], - "name":"InteractionDelayNotExpired", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "components":[ - { - "internalType":"uint256", - "name":"targetLeverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maximumFundingRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deltaThreshold", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"marketDepthBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"priceDeltaBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"worstStableRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxOrderCap", - "type":"uint256" - } - ], - "internalType":"struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", - "name":"params", - "type":"tuple" - } - ], - "name":"InvalidFuturesPoolHedgerParams", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"uint256", - "name":"quoteReceived", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"minCollateral", - "type":"uint256" - } - ], - "name":"NotEnoughQuoteForMinCollateral", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"address", - "name":"caller", - "type":"address" - }, - { - "internalType":"address", - "name":"liquidityPool", - "type":"address" - } - ], - "name":"OnlyLiquidityPool", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"address", - "name":"caller", - "type":"address" - }, - { - "internalType":"address", - "name":"nominatedOwner", - "type":"address" - } - ], - "name":"OnlyNominatedOwner", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"address", - "name":"caller", - "type":"address" - }, - { - "internalType":"address", - "name":"owner", - "type":"address" - } - ], - "name":"OnlyOwner", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"int256", - "name":"pendingDelta", - "type":"int256" - } - ], - "name":"PendingOrderDeltaError", - "type":"error" - }, - { - "inputs":[ - - ], - "name":"PerpMarketReturnedInvalid", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"address", - "name":"approvee", - "type":"address" - }, - { - "internalType":"uint256", - "name":"amount", - "type":"uint256" - } - ], - "name":"QuoteApprovalFailure", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"address", - "name":"from", - "type":"address" - }, - { - "internalType":"address", - "name":"to", - "type":"address" - }, - { - "internalType":"uint256", - "name":"amount", - "type":"uint256" - } - ], - "name":"QuoteTransferFailed", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"thrower", - "type":"address" - }, - { - "internalType":"uint8", - "name":"id", - "type":"uint8" - } - ], - "name":"RemovingInvalidId", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"quoteAsset", - "type":"address" - }, - { - "internalType":"address", - "name":"sUSD", - "type":"address" - }, - { - "internalType":"uint256", - "name":"curve_rate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxSlippageRate", - "type":"uint256" - } - ], - "name":"StableSwapSlippageOutOfBounds", - "type":"error" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"asset", - "type":"address" - } - ], - "name":"UnsupportedToken", - "type":"error" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"bool", - "name":"state", - "type":"bool" - } - ], - "name":"ApprovalsUpdated", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"uint256", - "name":"oldCollat", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"newCollat", - "type":"uint256" - } - ], - "name":"CollateralUpdated", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"targetLeverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maximumFundingRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deltaThreshold", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"marketDepthBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"priceDeltaBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"worstStableRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxOrderCap", - "type":"uint256" - } - ], - "indexed":false, - "internalType":"struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", - "name":"params", - "type":"tuple" - } - ], - "name":"FuturesPoolHedgerParamsSet", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"uint256", - "name":"oldAmount", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"newAmount", - "type":"uint256" - } - ], - "name":"LongSetTo", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"address", - "name":"oldOwner", - "type":"address" - }, - { - "indexed":false, - "internalType":"address", - "name":"newOwner", - "type":"address" - } - ], - "name":"OwnerChanged", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"address", - "name":"newOwner", - "type":"address" - } - ], - "name":"OwnerNominated", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"interactionDelay", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgeCap", - "type":"uint256" - } - ], - "indexed":false, - "internalType":"struct PoolHedger.PoolHedgerParameters", - "name":"poolHedgerParams", - "type":"tuple" - } - ], - "name":"PoolHedgerParametersSet", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"int256", - "name":"oldNetDelta", - "type":"int256" - }, - { - "indexed":false, - "internalType":"int256", - "name":"currentNetDelta", - "type":"int256" - }, - { - "indexed":false, - "internalType":"int256", - "name":"expectedNetDelta", - "type":"int256" - } - ], - "name":"PositionUpdateSubmitted", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"uint256", - "name":"amountQuote", - "type":"uint256" - } - ], - "name":"QuoteReturnedToLP", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"uint256", - "name":"oldShort", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"newShort", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"oldCollateral", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"newCollateral", - "type":"uint256" - } - ], - "name":"ShortSetTo", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"address", - "name":"quoteAsset", - "type":"address" - }, - { - "indexed":false, - "internalType":"address", - "name":"sUSD", - "type":"address" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"curve_rate", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"maxSlippage", - "type":"uint256" - } - ], - "name":"SlippageOutOfBounds", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"address", - "name":"quoteAsset", - "type":"address" - }, - { - "indexed":false, - "internalType":"address", - "name":"sUSD", - "type":"address" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"amountIn", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"amountOut", - "type":"uint256" - } - ], - "name":"USDCCollateralSwapForMargin", - "type":"event" - }, - { - "anonymous":false, - "inputs":[ - { - "indexed":false, - "internalType":"address", - "name":"quoteAsset", - "type":"address" - }, - { - "indexed":false, - "internalType":"address", - "name":"sUSD", - "type":"address" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"amountIn", - "type":"uint256" - }, - { - "indexed":false, - "internalType":"uint256", - "name":"amountOut", - "type":"uint256" - } - ], - "name":"sUSDCollateralSwap", - "type":"event" - }, - { - "inputs":[ - - ], - "name":"acceptOwnership", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"addressResolver", - "outputs":[ - { - "internalType":"contract IAddressResolver", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"uint256", - "name":"", - "type":"uint256" - }, - { - "internalType":"bool", - "name":"deltaIncrease", - "type":"bool" - }, - { - "internalType":"uint256", - "name":"", - "type":"uint256" - } - ], - "name":"canHedge", - "outputs":[ - { - "internalType":"bool", - "name":"", - "type":"bool" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"curveSwap", - "outputs":[ - { - "internalType":"contract ICurve", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"exchangeAdapter", - "outputs":[ - { - "internalType":"contract BaseExchangeAdapter", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"futuresPoolHedgerParams", - "outputs":[ - { - "internalType":"uint256", - "name":"targetLeverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maximumFundingRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deltaThreshold", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"marketDepthBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"priceDeltaBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"worstStableRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxOrderCap", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"getCappedExpectedHedge", - "outputs":[ - { - "internalType":"int256", - "name":"", - "type":"int256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"getCurrentHedgedNetDelta", - "outputs":[ - { - "internalType":"int256", - "name":"", - "type":"int256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"getCurrentPositionMargin", - "outputs":[ - { - "internalType":"uint256", - "name":"", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"getHedgerState", - "outputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"lastInteraction", - "type":"uint256" - }, - { - "internalType":"int256", - "name":"hedgedDelta", - "type":"int256" - }, - { - "internalType":"uint256", - "name":"margin", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"leverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgerQuoteBalance", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgerMarginQuoteBalance", - "type":"uint256" - }, - { - "internalType":"bool", - "name":"canHedgeDeltaIncrease", - "type":"bool" - }, - { - "internalType":"bool", - "name":"canHedgeDeltaDecrease", - "type":"bool" - }, - { - "internalType":"int256", - "name":"cappedExpectedHedge", - "type":"int256" - }, - { - "internalType":"bool", - "name":"snxHasEnoughMarketDepth", - "type":"bool" - }, - { - "internalType":"bool", - "name":"marketSuspended", - "type":"bool" - }, - { - "internalType":"bool", - "name":"curveRateStable", - "type":"bool" - }, - { - "internalType":"uint256", - "name":"pendingDeltaLiquidity", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"usedDeltaLiquidity", - "type":"uint256" - }, - { - "internalType":"int256", - "name":"pendingDelta", - "type":"int256" - }, - { - "internalType":"uint256", - "name":"pendingMargin", - "type":"uint256" - }, - { - "internalType":"int256", - "name":"fundingRate", - "type":"int256" - }, - { - "internalType":"bytes32", - "name":"trackingCode", - "type":"bytes32" - }, - { - "internalType":"address", - "name":"optionMarket", - "type":"address" - }, - { - "internalType":"address", - "name":"perpsMarket", - "type":"address" - }, - { - "internalType":"address", - "name":"curveSwap", - "type":"address" - }, - { - "internalType":"address", - "name":"quoteAsset", - "type":"address" - }, - { - "components":[ - { - "internalType":"uint256", - "name":"targetLeverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maximumFundingRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deltaThreshold", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"marketDepthBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"priceDeltaBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"worstStableRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxOrderCap", - "type":"uint256" - } - ], - "internalType":"struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", - "name":"futuresPoolHedgerParams", - "type":"tuple" - }, - { - "components":[ - { - "internalType":"uint256", - "name":"interactionDelay", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgeCap", - "type":"uint256" - } - ], - "internalType":"struct PoolHedger.PoolHedgerParameters", - "name":"poolHedgerParams", - "type":"tuple" - } - ], - "internalType":"struct SNXPerpsV2PoolHedger.HedgerState", - "name":"", - "type":"tuple" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"uint256", - "name":"spotPrice", - "type":"uint256" - } - ], - "name":"getHedgingLiquidity", - "outputs":[ - { - "internalType":"uint256", - "name":"pendingDeltaLiquidity", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"usedDeltaLiquidity", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"getPoolHedgerParams", - "outputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"interactionDelay", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgeCap", - "type":"uint256" - } - ], - "internalType":"struct PoolHedger.PoolHedgerParameters", - "name":"", - "type":"tuple" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"hedgeDelta", - "outputs":[ - - ], - "stateMutability":"payable", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"contract IAddressResolver", - "name":"_addressResolver", - "type":"address" - }, - { - "internalType":"contract BaseExchangeAdapter", - "name":"_exchangeAdapter", - "type":"address" - }, - { - "internalType":"contract OptionMarket", - "name":"_optionMarket", - "type":"address" - }, - { - "internalType":"contract OptionGreekCache", - "name":"_optionGreekCache", - "type":"address" - }, - { - "internalType":"contract LiquidityPool", - "name":"_liquidityPool", - "type":"address" - }, - { - "internalType":"contract IPerpsV2MarketConsolidated", - "name":"_perpMarketProxy", - "type":"address" - }, - { - "internalType":"contract ERC20", - "name":"_quoteAsset", - "type":"address" - }, - { - "internalType":"contract ERC20", - "name":"_sUSD", - "type":"address" - }, - { - "internalType":"contract ICurve", - "name":"_curveSwap", - "type":"address" - }, - { - "internalType":"bytes32", - "name":"_marketKey", - "type":"bytes32" - } - ], - "name":"init", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"lastInteraction", - "outputs":[ - { - "internalType":"uint256", - "name":"", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"marketKey", - "outputs":[ - { - "internalType":"bytes32", - "name":"", - "type":"bytes32" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"_owner", - "type":"address" - } - ], - "name":"nominateNewOwner", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"nominatedOwner", - "outputs":[ - { - "internalType":"address", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"owner", - "outputs":[ - { - "internalType":"address", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"perpsMarket", - "outputs":[ - { - "internalType":"contract IPerpsV2MarketConsolidated", - "name":"", - "type":"address" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"resetInteractionDelay", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"targetLeverage", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maximumFundingRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deltaThreshold", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"marketDepthBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"priceDeltaBuffer", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"worstStableRate", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"maxOrderCap", - "type":"uint256" - } - ], - "internalType":"struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", - "name":"_futuresPoolHedgerParams", - "type":"tuple" - } - ], - "name":"setFuturesPoolHedgerParams", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - { - "components":[ - { - "internalType":"uint256", - "name":"interactionDelay", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"hedgeCap", - "type":"uint256" - } - ], - "internalType":"struct PoolHedger.PoolHedgerParameters", - "name":"_poolHedgerParams", - "type":"tuple" - } - ], - "name":"setPoolHedgerParams", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"bytes32", - "name":"_trackingCode", - "type":"bytes32" - } - ], - "name":"setTrackingCode", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"trackingCode", - "outputs":[ - { - "internalType":"bytes32", - "name":"", - "type":"bytes32" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"updateCollateral", - "outputs":[ - - ], - "stateMutability":"payable", - "type":"function" - } -] + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + } + ], + "name": "AlreadyInitialised", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "internalType": "uint256", + "name": "lastInteraction", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "interactionDelta", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "currentTime", + "type": "uint256" + } + ], + "name": "InteractionDelayNotExpired", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "targetLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maximumFundingRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deltaThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "marketDepthBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceDeltaBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "worstStableRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxOrderCap", + "type": "uint256" + } + ], + "internalType": "struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", + "name": "params", + "type": "tuple" + } + ], + "name": "InvalidFuturesPoolHedgerParams", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "internalType": "address", + "name": "liquidityPool", + "type": "address" + } + ], + "name": "OnlyLiquidityPool", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "internalType": "address", + "name": "nominatedOwner", + "type": "address" + } + ], + "name": "OnlyNominatedOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OnlyOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "pendingDelta", + "type": "int256" + } + ], + "name": "PendingOrderDeltaError", + "type": "error" + }, + { + "inputs": [], + "name": "PerpMarketReturnedInvalid", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "thrower", + "type": "address" + }, + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "QuoteTransferFailed", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "oldCollat", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newCollat", + "type": "uint256" + } + ], + "name": "CollateralUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "targetLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maximumFundingRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deltaThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "marketDepthBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceDeltaBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "worstStableRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxOrderCap", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", + "name": "params", + "type": "tuple" + } + ], + "name": "FuturesPoolHedgerParamsSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "oldOwner", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnerChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnerNominated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "interactionDelay", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgeCap", + "type": "uint256" + } + ], + "indexed": false, + "internalType": "struct PoolHedger.PoolHedgerParameters", + "name": "poolHedgerParams", + "type": "tuple" + } + ], + "name": "PoolHedgerParametersSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "int256", + "name": "oldNetDelta", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "currentNetDelta", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "expectedNetDelta", + "type": "int256" + } + ], + "name": "PositionUpdateSubmitted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "amountQuote", + "type": "uint256" + } + ], + "name": "QuoteReturnedToLP", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "quoteAsset", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sUSD", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "curve_rate", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "maxSlippage", + "type": "uint256" + } + ], + "name": "SlippageOutOfBounds", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "trackingCode", + "type": "bytes32" + } + ], + "name": "TrackingCodeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "quoteAsset", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sUSD", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + } + ], + "name": "USDCCollateralSwapForMargin", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "quoteAsset", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sUSD", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountIn", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + } + ], + "name": "sUSDCollateralSwap", + "type": "event" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "addressResolver", + "outputs": [ + { + "internalType": "contract IAddressResolver", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "deltaIncrease", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "canHedge", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "curveSwap", + "outputs": [ + { + "internalType": "contract ICurve", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "exchangeAdapter", + "outputs": [ + { + "internalType": "contract BaseExchangeAdapter", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "futuresPoolHedgerParams", + "outputs": [ + { + "internalType": "uint256", + "name": "targetLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maximumFundingRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deltaThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "marketDepthBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceDeltaBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "worstStableRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxOrderCap", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCappedExpectedHedge", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentHedgedNetDelta", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getCurrentPositionMargin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getHedgerState", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lastInteraction", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "hedgedDelta", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "margin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "leverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgerQuoteBalance", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgerMarginQuoteBalance", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "canHedgeDeltaIncrease", + "type": "bool" + }, + { + "internalType": "bool", + "name": "canHedgeDeltaDecrease", + "type": "bool" + }, + { + "internalType": "int256", + "name": "cappedExpectedHedge", + "type": "int256" + }, + { + "internalType": "bool", + "name": "snxHasEnoughMarketDepth", + "type": "bool" + }, + { + "internalType": "bool", + "name": "marketSuspended", + "type": "bool" + }, + { + "internalType": "bool", + "name": "curveRateStable", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "pendingDeltaLiquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usedDeltaLiquidity", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "pendingDelta", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "longInterest", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shortInterest", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxTotalMarketSize", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "pendingMargin", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "fundingRate", + "type": "int256" + }, + { + "internalType": "bytes32", + "name": "trackingCode", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "optionMarket", + "type": "address" + }, + { + "internalType": "address", + "name": "perpsMarket", + "type": "address" + }, + { + "internalType": "address", + "name": "curveSwap", + "type": "address" + }, + { + "internalType": "address", + "name": "quoteAsset", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "targetLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maximumFundingRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deltaThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "marketDepthBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceDeltaBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "worstStableRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxOrderCap", + "type": "uint256" + } + ], + "internalType": "struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", + "name": "futuresPoolHedgerParams", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "interactionDelay", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgeCap", + "type": "uint256" + } + ], + "internalType": "struct PoolHedger.PoolHedgerParameters", + "name": "poolHedgerParams", + "type": "tuple" + } + ], + "internalType": "struct SNXPerpsV2PoolHedger.HedgerState", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "spotPrice", + "type": "uint256" + } + ], + "name": "getHedgingLiquidity", + "outputs": [ + { + "internalType": "uint256", + "name": "pendingDeltaLiquidity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "usedDeltaLiquidity", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPoolHedgerParams", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "interactionDelay", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgeCap", + "type": "uint256" + } + ], + "internalType": "struct PoolHedger.PoolHedgerParameters", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "hedgeDelta", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IAddressResolver", + "name": "_addressResolver", + "type": "address" + }, + { + "internalType": "contract BaseExchangeAdapter", + "name": "_exchangeAdapter", + "type": "address" + }, + { + "internalType": "contract OptionMarket", + "name": "_optionMarket", + "type": "address" + }, + { + "internalType": "contract OptionGreekCache", + "name": "_optionGreekCache", + "type": "address" + }, + { + "internalType": "contract LiquidityPool", + "name": "_liquidityPool", + "type": "address" + }, + { + "internalType": "contract IPerpsV2MarketConsolidated", + "name": "_perpMarketProxy", + "type": "address" + }, + { + "internalType": "contract ERC20", + "name": "_quoteAsset", + "type": "address" + }, + { + "internalType": "contract ERC20", + "name": "_sUSD", + "type": "address" + }, + { + "internalType": "contract ICurve", + "name": "_curveSwap", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_marketKey", + "type": "bytes32" + } + ], + "name": "init", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "lastInteraction", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "marketKey", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + } + ], + "name": "nominateNewOwner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "nominatedOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "perpsMarket", + "outputs": [ + { + "internalType": "contract IPerpsV2MarketConsolidated", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "resetInteractionDelay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "targetLeverage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maximumFundingRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deltaThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "marketDepthBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "priceDeltaBuffer", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "worstStableRate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxOrderCap", + "type": "uint256" + } + ], + "internalType": "struct SNXPerpsV2PoolHedger.SNXPerpsV2PoolHedgerParameters", + "name": "_futuresPoolHedgerParams", + "type": "tuple" + } + ], + "name": "setFuturesPoolHedgerParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "interactionDelay", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "hedgeCap", + "type": "uint256" + } + ], + "internalType": "struct PoolHedger.PoolHedgerParameters", + "name": "_poolHedgerParams", + "type": "tuple" + } + ], + "name": "setPoolHedgerParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "_trackingCode", + "type": "bytes32" + } + ], + "name": "setTrackingCode", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "trackingCode", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "updateCollateral", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] \ No newline at end of file diff --git a/sdk/src/contracts/newport/typechain/NewportSNXPerpsV2PoolHedger.ts b/sdk/src/contracts/newport/typechain/NewportSNXPerpsV2PoolHedger.ts index 0e50d2bb..4dcba3f0 100644 --- a/sdk/src/contracts/newport/typechain/NewportSNXPerpsV2PoolHedger.ts +++ b/sdk/src/contracts/newport/typechain/NewportSNXPerpsV2PoolHedger.ts @@ -73,6 +73,9 @@ export declare namespace SNXPerpsV2PoolHedger { pendingDeltaLiquidity: PromiseOrValue; usedDeltaLiquidity: PromiseOrValue; pendingDelta: PromiseOrValue; + longInterest: PromiseOrValue; + shortInterest: PromiseOrValue; + maxTotalMarketSize: PromiseOrValue; pendingMargin: PromiseOrValue; fundingRate: PromiseOrValue; trackingCode: PromiseOrValue; @@ -102,6 +105,9 @@ export declare namespace SNXPerpsV2PoolHedger { BigNumber, BigNumber, BigNumber, + BigNumber, + BigNumber, + BigNumber, string, string, string, @@ -125,6 +131,9 @@ export declare namespace SNXPerpsV2PoolHedger { pendingDeltaLiquidity: BigNumber; usedDeltaLiquidity: BigNumber; pendingDelta: BigNumber; + longInterest: BigNumber; + shortInterest: BigNumber; + maxTotalMarketSize: BigNumber; pendingMargin: BigNumber; fundingRate: BigNumber; trackingCode: string; @@ -408,49 +417,34 @@ export interface NewportSNXPerpsV2PoolHedgerInterface extends utils.Interface { ): Result; events: { - "ApprovalsUpdated(bool)": EventFragment; "CollateralUpdated(uint256,uint256)": EventFragment; "FuturesPoolHedgerParamsSet(tuple)": EventFragment; - "LongSetTo(uint256,uint256)": EventFragment; "OwnerChanged(address,address)": EventFragment; "OwnerNominated(address)": EventFragment; "PoolHedgerParametersSet(tuple)": EventFragment; "PositionUpdateSubmitted(int256,int256,int256)": EventFragment; "QuoteReturnedToLP(uint256)": EventFragment; - "ShortSetTo(uint256,uint256,uint256,uint256)": EventFragment; "SlippageOutOfBounds(address,address,uint256,uint256)": EventFragment; + "TrackingCodeSet(bytes32)": EventFragment; "USDCCollateralSwapForMargin(address,address,uint256,uint256)": EventFragment; "sUSDCollateralSwap(address,address,uint256,uint256)": EventFragment; }; - getEvent(nameOrSignatureOrTopic: "ApprovalsUpdated"): EventFragment; getEvent(nameOrSignatureOrTopic: "CollateralUpdated"): EventFragment; getEvent(nameOrSignatureOrTopic: "FuturesPoolHedgerParamsSet"): EventFragment; - getEvent(nameOrSignatureOrTopic: "LongSetTo"): EventFragment; getEvent(nameOrSignatureOrTopic: "OwnerChanged"): EventFragment; getEvent(nameOrSignatureOrTopic: "OwnerNominated"): EventFragment; getEvent(nameOrSignatureOrTopic: "PoolHedgerParametersSet"): EventFragment; getEvent(nameOrSignatureOrTopic: "PositionUpdateSubmitted"): EventFragment; getEvent(nameOrSignatureOrTopic: "QuoteReturnedToLP"): EventFragment; - getEvent(nameOrSignatureOrTopic: "ShortSetTo"): EventFragment; getEvent(nameOrSignatureOrTopic: "SlippageOutOfBounds"): EventFragment; + getEvent(nameOrSignatureOrTopic: "TrackingCodeSet"): EventFragment; getEvent( nameOrSignatureOrTopic: "USDCCollateralSwapForMargin" ): EventFragment; getEvent(nameOrSignatureOrTopic: "sUSDCollateralSwap"): EventFragment; } -export interface ApprovalsUpdatedEventObject { - state: boolean; -} -export type ApprovalsUpdatedEvent = TypedEvent< - [boolean], - ApprovalsUpdatedEventObject ->; - -export type ApprovalsUpdatedEventFilter = - TypedEventFilter; - export interface CollateralUpdatedEventObject { oldCollat: BigNumber; newCollat: BigNumber; @@ -474,17 +468,6 @@ export type FuturesPoolHedgerParamsSetEvent = TypedEvent< export type FuturesPoolHedgerParamsSetEventFilter = TypedEventFilter; -export interface LongSetToEventObject { - oldAmount: BigNumber; - newAmount: BigNumber; -} -export type LongSetToEvent = TypedEvent< - [BigNumber, BigNumber], - LongSetToEventObject ->; - -export type LongSetToEventFilter = TypedEventFilter; - export interface OwnerChangedEventObject { oldOwner: string; newOwner: string; @@ -541,19 +524,6 @@ export type QuoteReturnedToLPEvent = TypedEvent< export type QuoteReturnedToLPEventFilter = TypedEventFilter; -export interface ShortSetToEventObject { - oldShort: BigNumber; - newShort: BigNumber; - oldCollateral: BigNumber; - newCollateral: BigNumber; -} -export type ShortSetToEvent = TypedEvent< - [BigNumber, BigNumber, BigNumber, BigNumber], - ShortSetToEventObject ->; - -export type ShortSetToEventFilter = TypedEventFilter; - export interface SlippageOutOfBoundsEventObject { quoteAsset: string; sUSD: string; @@ -568,6 +538,16 @@ export type SlippageOutOfBoundsEvent = TypedEvent< export type SlippageOutOfBoundsEventFilter = TypedEventFilter; +export interface TrackingCodeSetEventObject { + trackingCode: string; +} +export type TrackingCodeSetEvent = TypedEvent< + [string], + TrackingCodeSetEventObject +>; + +export type TrackingCodeSetEventFilter = TypedEventFilter; + export interface USDCCollateralSwapForMarginEventObject { quoteAsset: string; sUSD: string; @@ -982,9 +962,6 @@ export interface NewportSNXPerpsV2PoolHedger extends BaseContract { }; filters: { - "ApprovalsUpdated(bool)"(state?: null): ApprovalsUpdatedEventFilter; - ApprovalsUpdated(state?: null): ApprovalsUpdatedEventFilter; - "CollateralUpdated(uint256,uint256)"( oldCollat?: null, newCollat?: null @@ -1001,12 +978,6 @@ export interface NewportSNXPerpsV2PoolHedger extends BaseContract { params?: null ): FuturesPoolHedgerParamsSetEventFilter; - "LongSetTo(uint256,uint256)"( - oldAmount?: null, - newAmount?: null - ): LongSetToEventFilter; - LongSetTo(oldAmount?: null, newAmount?: null): LongSetToEventFilter; - "OwnerChanged(address,address)"( oldOwner?: null, newOwner?: null @@ -1039,19 +1010,6 @@ export interface NewportSNXPerpsV2PoolHedger extends BaseContract { ): QuoteReturnedToLPEventFilter; QuoteReturnedToLP(amountQuote?: null): QuoteReturnedToLPEventFilter; - "ShortSetTo(uint256,uint256,uint256,uint256)"( - oldShort?: null, - newShort?: null, - oldCollateral?: null, - newCollateral?: null - ): ShortSetToEventFilter; - ShortSetTo( - oldShort?: null, - newShort?: null, - oldCollateral?: null, - newCollateral?: null - ): ShortSetToEventFilter; - "SlippageOutOfBounds(address,address,uint256,uint256)"( quoteAsset?: null, sUSD?: null, @@ -1065,6 +1023,9 @@ export interface NewportSNXPerpsV2PoolHedger extends BaseContract { maxSlippage?: null ): SlippageOutOfBoundsEventFilter; + "TrackingCodeSet(bytes32)"(trackingCode?: null): TrackingCodeSetEventFilter; + TrackingCodeSet(trackingCode?: null): TrackingCodeSetEventFilter; + "USDCCollateralSwapForMargin(address,address,uint256,uint256)"( quoteAsset?: null, sUSD?: null, diff --git a/sdk/src/contracts/newport/typechain/factories/NewportSNXPerpsV2PoolHedger__factory.ts b/sdk/src/contracts/newport/typechain/factories/NewportSNXPerpsV2PoolHedger__factory.ts index 5d2a73d3..d0d3a9da 100644 --- a/sdk/src/contracts/newport/typechain/factories/NewportSNXPerpsV2PoolHedger__factory.ts +++ b/sdk/src/contracts/newport/typechain/factories/NewportSNXPerpsV2PoolHedger__factory.ts @@ -26,53 +26,6 @@ const _abi = [ name: "AlreadyInitialised", type: "error", }, - { - inputs: [ - { - internalType: "address", - name: "thrower", - type: "address", - }, - { - internalType: "contract IERC20Decimals", - name: "asset", - type: "address", - }, - { - internalType: "address", - name: "approving", - type: "address", - }, - { - internalType: "uint256", - name: "approvalAmount", - type: "uint256", - }, - ], - name: "ApprovalFailure", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "thrower", - type: "address", - }, - { - internalType: "uint8", - name: "id", - type: "uint8", - }, - { - internalType: "address", - name: "addr", - type: "address", - }, - ], - name: "DuplicateEntry", - type: "error", - }, { inputs: [ { @@ -153,27 +106,6 @@ const _abi = [ name: "InvalidFuturesPoolHedgerParams", type: "error", }, - { - inputs: [ - { - internalType: "address", - name: "thrower", - type: "address", - }, - { - internalType: "uint256", - name: "quoteReceived", - type: "uint256", - }, - { - internalType: "uint256", - name: "minCollateral", - type: "uint256", - }, - ], - name: "NotEnoughQuoteForMinCollateral", - type: "error", - }, { inputs: [ { @@ -253,27 +185,6 @@ const _abi = [ name: "PerpMarketReturnedInvalid", type: "error", }, - { - inputs: [ - { - internalType: "address", - name: "thrower", - type: "address", - }, - { - internalType: "address", - name: "approvee", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - name: "QuoteApprovalFailure", - type: "error", - }, { inputs: [ { @@ -300,72 +211,6 @@ const _abi = [ name: "QuoteTransferFailed", type: "error", }, - { - inputs: [ - { - internalType: "address", - name: "thrower", - type: "address", - }, - { - internalType: "uint8", - name: "id", - type: "uint8", - }, - ], - name: "RemovingInvalidId", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "quoteAsset", - type: "address", - }, - { - internalType: "address", - name: "sUSD", - type: "address", - }, - { - internalType: "uint256", - name: "curve_rate", - type: "uint256", - }, - { - internalType: "uint256", - name: "maxSlippageRate", - type: "uint256", - }, - ], - name: "StableSwapSlippageOutOfBounds", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "asset", - type: "address", - }, - ], - name: "UnsupportedToken", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "bool", - name: "state", - type: "bool", - }, - ], - name: "ApprovalsUpdated", - type: "event", - }, { anonymous: false, inputs: [ @@ -436,25 +281,6 @@ const _abi = [ name: "FuturesPoolHedgerParamsSet", type: "event", }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "oldAmount", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "newAmount", - type: "uint256", - }, - ], - name: "LongSetTo", - type: "event", - }, { anonymous: false, inputs: [ @@ -550,37 +376,6 @@ const _abi = [ name: "QuoteReturnedToLP", type: "event", }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "oldShort", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "newShort", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "oldCollateral", - type: "uint256", - }, - { - indexed: false, - internalType: "uint256", - name: "newCollateral", - type: "uint256", - }, - ], - name: "ShortSetTo", - type: "event", - }, { anonymous: false, inputs: [ @@ -612,6 +407,19 @@ const _abi = [ name: "SlippageOutOfBounds", type: "event", }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bytes32", + name: "trackingCode", + type: "bytes32", + }, + ], + name: "TrackingCodeSet", + type: "event", + }, { anonymous: false, inputs: [ @@ -912,6 +720,21 @@ const _abi = [ name: "pendingDelta", type: "int256", }, + { + internalType: "uint256", + name: "longInterest", + type: "uint256", + }, + { + internalType: "uint256", + name: "shortInterest", + type: "uint256", + }, + { + internalType: "uint256", + name: "maxTotalMarketSize", + type: "uint256", + }, { internalType: "uint256", name: "pendingMargin", diff --git a/sdk/src/market/index.ts b/sdk/src/market/index.ts index 891880ca..5128d027 100644 --- a/sdk/src/market/index.ts +++ b/sdk/src/market/index.ts @@ -215,7 +215,6 @@ export class Market { owner: string, tokenPrice: BigNumber, block: Block, - // TODO @michaelxuwu remove this when parmas added to viewer hedgerView?: PoolHedgerView, adapterView?: ExchangeAdapterView, poolHedgerParams?: PoolHedgerParams @@ -291,7 +290,7 @@ export class Market { const forceCloseParams = marketView.marketParameters.forceCloseParams const varianceFeeParams = marketView.marketParameters.varianceFeeParams const lpParams = marketView.marketParameters.lpParams - // cosnt marketAdapterConfigParams = marketView.marketParameters + const sharedParams = { optionPriceFee1xPoint: pricingParams.optionPriceFee1xPoint.toNumber(), optionPriceFee2xPoint: pricingParams.optionPriceFee2xPoint.toNumber(), diff --git a/sdk/src/quote/getQuoteDisabledReason.ts b/sdk/src/quote/getQuoteDisabledReason.ts index 02369180..74dfa0a9 100644 --- a/sdk/src/quote/getQuoteDisabledReason.ts +++ b/sdk/src/quote/getQuoteDisabledReason.ts @@ -126,16 +126,18 @@ export default function getQuoteDisabledReason( return QuoteDisabledReason.UnableToHedgeDelta } - // Disable quote for opening and closing in the case where the feeds differ by a great amount, but allow force closes. - const { adapterView } = option.market().params - const gmxAdapterView = adapterView as GMXAdapter.GMXAdapterStateStructOutput - if (gmxAdapterView && !isForceClose && (priceType === PriceType.MAX_PRICE || priceType === PriceType.MIN_PRICE)) { - const { gmxMaxPrice: forceMaxSpotPrice, gmxMinPrice: forceMinSpotPrice } = gmxAdapterView - const minPriceVariance = getPriceVariance(forceMinSpotPrice, market.params.referenceSpotPrice) - const maxPriceVariance = getPriceVariance(forceMaxSpotPrice, market.params.referenceSpotPrice) - const varianceThreshold = gmxAdapterView.marketPricingParams.priceVarianceCBPercent - if (minPriceVariance.gt(varianceThreshold) || maxPriceVariance.gt(varianceThreshold)) { - return QuoteDisabledReason.PriceVarianceTooHigh + if (market.lyra.network === Network.Arbitrum) { + // Disable quote for opening and closing in the case where the feeds differ by a great amount, but allow force closes. + const { adapterView } = option.market().params + const gmxAdapterView = adapterView as GMXAdapter.GMXAdapterStateStructOutput + if (gmxAdapterView && !isForceClose && (priceType === PriceType.MAX_PRICE || priceType === PriceType.MIN_PRICE)) { + const { gmxMaxPrice: forceMaxSpotPrice, gmxMinPrice: forceMinSpotPrice } = gmxAdapterView + const minPriceVariance = getPriceVariance(forceMinSpotPrice, market.params.referenceSpotPrice) + const maxPriceVariance = getPriceVariance(forceMaxSpotPrice, market.params.referenceSpotPrice) + const varianceThreshold = gmxAdapterView.marketPricingParams.priceVarianceCBPercent + if (minPriceVariance.gt(varianceThreshold) || maxPriceVariance.gt(varianceThreshold)) { + return QuoteDisabledReason.PriceVarianceTooHigh + } } } diff --git a/sdk/src/utils/canHedge.ts b/sdk/src/utils/canHedge.ts index 043f9322..86e802fb 100644 --- a/sdk/src/utils/canHedge.ts +++ b/sdk/src/utils/canHedge.ts @@ -1,6 +1,8 @@ import { BigNumber } from 'ethers' import { Network, PoolHedgerParams } from '..' +import { GMXFuturesPoolHedger } from '../contracts/newport/typechain/NewportGMXFuturesPoolHedger' +import { SNXPerpsV2PoolHedger } from '../contracts/newport/typechain/NewportSNXPerpsV2PoolHedger' import { PoolHedgerView } from '../market' import { Option } from '../option' import canHedgeOnArbitrum from './canHedgeArbitrum' @@ -24,7 +26,7 @@ export default function canHedge( option, size, increasesPoolDelta, - hedgerView, + hedgerView as GMXFuturesPoolHedger.GMXFuturesPoolHedgerViewStructOutput, poolHedgerParams ) case Network.Optimism: @@ -34,7 +36,7 @@ export default function canHedge( option, size, increasesPoolDelta, - hedgerView, + hedgerView as SNXPerpsV2PoolHedger.HedgerStateStructOutput, poolHedgerParams ) } diff --git a/sdk/src/utils/canHedgeArbitrum.ts b/sdk/src/utils/canHedgeArbitrum.ts index 75af112f..cea7a237 100644 --- a/sdk/src/utils/canHedgeArbitrum.ts +++ b/sdk/src/utils/canHedgeArbitrum.ts @@ -3,7 +3,6 @@ import { BigNumber } from 'ethers' import { PoolHedgerParams } from '../admin' import { UNIT } from '../constants/bn' import { GMXFuturesPoolHedger } from '../contracts/newport/typechain/NewportGMXFuturesPoolHedger' -import { PoolHedgerView } from '../market' import { Option } from '../option' import getCappedExpectedHedge from './getCappedExpectedHedge' @@ -13,14 +12,10 @@ export default function canHedgeOnArbitrum( option: Option, size: BigNumber, increasesPoolDelta: boolean, - hedgerView: PoolHedgerView, + hedgerView: GMXFuturesPoolHedger.GMXFuturesPoolHedgerViewStructOutput, poolHedgerParams: PoolHedgerParams ) { - const gmxHedgerView = hedgerView as GMXFuturesPoolHedger.GMXFuturesPoolHedgerViewStructOutput - if (!gmxHedgerView) { - throw new Error('Invalid PoolHedgerView for canHedgeOnArbitrum') - } - const { currentHedge, gmxView, futuresPoolHedgerParams } = gmxHedgerView + const { currentHedge, gmxView, futuresPoolHedgerParams } = hedgerView if (!futuresPoolHedgerParams.vaultLiquidityCheckEnabled) { return true } diff --git a/sdk/src/utils/canHedgeOptimism.ts b/sdk/src/utils/canHedgeOptimism.ts index 65574187..10850662 100644 --- a/sdk/src/utils/canHedgeOptimism.ts +++ b/sdk/src/utils/canHedgeOptimism.ts @@ -2,7 +2,6 @@ import { BigNumber } from 'ethers' import { PoolHedgerParams } from '../admin' import { SNXPerpsV2PoolHedger } from '../contracts/newport/typechain/NewportSNXPerpsV2PoolHedger' -import { PoolHedgerView } from '../market' import { Option } from '../option' import getCappedExpectedHedge from './getCappedExpectedHedge' @@ -24,23 +23,28 @@ export default function canHedgeOnOptimism( option: Option, size: BigNumber, increasesPoolDelta: boolean, - hedgerView: PoolHedgerView, + hedgerView: SNXPerpsV2PoolHedger.HedgerStateStructOutput, poolHedgerParams: PoolHedgerParams ) { - const snxHedgerView = hedgerView as SNXPerpsV2PoolHedger.HedgerStateStructOutput - if (!snxHedgerView) { - throw new Error('Invalid PoolHedgerView for canHedgeOnOptimism') - } + const { + marketSuspended, + hedgedDelta: currentHedge, + futuresPoolHedgerParams, + fundingRate, + shortInterest, + longInterest, + maxTotalMarketSize, + } = hedgerView - if (snxHedgerView.marketSuspended) { + if (marketSuspended) { return false } const cappedExpectedHedge = getCappedExpectedHedge(option, size, netDelta, poolHedgerParams, increasesPoolDelta) const cappedExpectedHedgeAbs = cappedExpectedHedge.abs() - const currentHedge = snxHedgerView.hedgedDelta + const currentHedgeAbs = currentHedge.abs() - if (cappedExpectedHedgeAbs.lte(currentHedge) && cappedExpectedHedge.mul(currentHedge).gte(0)) { + if (cappedExpectedHedgeAbs.lte(currentHedgeAbs) && cappedExpectedHedge.mul(currentHedge).gte(0)) { // Delta is shrinking (potentially flipping, but still smaller than current hedge), so we skip the check return true } @@ -55,27 +59,19 @@ export default function canHedgeOnOptimism( return true } // check that the curve swap rates are acceptable - if (!snxHedgerView.curveRateStable) { + if (!hedgerView.curveRateStable) { return false } if (cappedExpectedHedgeAbs.gt(currentHedge.abs())) { // check funding rate is within bounds and so is liquidity - const fundingRate = snxHedgerView.fundingRate - const maxFundingRate = snxHedgerView.futuresPoolHedgerParams.maximumFundingRate + const maxFundingRate = futuresPoolHedgerParams.maximumFundingRate if (fundingRate.abs().gt(maxFundingRate)) { return false } } - // TODO - // const shortInterest = snxHedgerView.poolHedgerParams.shortInterest - // const longInterest = snxHedgerView.poolHedgerParams.longInterest - // const maxTotalMarketSize = snxHedgerView.poolHedgerParams.maxTotalMarketSize - const shortInterest = BigNumber.from(0) - const longInterest = BigNumber.from(0) - const maxTotalMarketSize = BigNumber.from(0) - const marketDepthBuffer = snxHedgerView.futuresPoolHedgerParams.marketDepthBuffer + const marketDepthBuffer = futuresPoolHedgerParams.marketDepthBuffer // Check remaining market liquidity if (cappedExpectedHedge.mul(currentHedge).gt(0)) { diff --git a/sdk/src/utils/fetchNewportOptimismMarketViews.ts b/sdk/src/utils/fetchNewportOptimismMarketViews.ts index 31bee05d..28fe3293 100644 --- a/sdk/src/utils/fetchNewportOptimismMarketViews.ts +++ b/sdk/src/utils/fetchNewportOptimismMarketViews.ts @@ -1,7 +1,7 @@ import { BigNumber } from 'ethers' import { PoolHedgerParams } from '../admin' -import { ZERO_BN } from '../constants/bn' +import { MAX_BN, ZERO_BN } from '../constants/bn' import { LyraContractId, LyraMarketContractId } from '../constants/contracts' import { LyraContractMap, LyraMarketContractMap } from '../constants/mappings' import { OptionMarketViewer } from '../contracts/newport/typechain/NewportOptionMarketViewer' @@ -73,6 +73,9 @@ const TESTNET_HEDGER_VIEW: SNXPerpsV2PoolHedger.HedgerStateStruct = { interactionDelay: ZERO_BN, hedgeCap: ZERO_BN, }, + longInterest: ZERO_BN, + shortInterest: ZERO_BN, + maxTotalMarketSize: MAX_BN, } export default async function fetchNewportOptimismMarketViews(lyra: Lyra): Promise<{ diff --git a/sdk/src/utils/fetchSpotPriceHistory.ts b/sdk/src/utils/fetchSpotPriceHistory.ts index 438eb2c9..49f82efd 100644 --- a/sdk/src/utils/fetchSpotPriceHistory.ts +++ b/sdk/src/utils/fetchSpotPriceHistory.ts @@ -50,7 +50,6 @@ export default async function fetchSpotPriceHistory( const estNumCandles = candleDuration > 0 ? (endTimestamp - startTimestamp) / candleDuration : 0 const numBatches = Math.ceil(estNumCandles / SPOT_PRICE_SNAPSHOT_LIMIT) - const data = await subgraphRequestWithLoop( lyra, spotPriceSnapshotsQuery, diff --git a/sdk/src/utils/getLyraDeploymentSubgraphURI.ts b/sdk/src/utils/getLyraDeploymentSubgraphURI.ts index a2f488ac..97a85bc1 100644 --- a/sdk/src/utils/getLyraDeploymentSubgraphURI.ts +++ b/sdk/src/utils/getLyraDeploymentSubgraphURI.ts @@ -11,7 +11,6 @@ const getLyraDeploymentSubgraphURI = (chain: Chain, version: Version = Version.N default: return 'https://subgraph.satsuma-prod.com/d14de8f7fd46/lyra/optimism-mainnet-newport/api' } - /*eslint-disable-next-line no-fallthrough */ case Chain.OptimismGoerli: return 'https://subgraph.satsuma-prod.com/d14de8f7fd46/lyra/optimism-goerli/api' case Chain.Arbitrum: diff --git a/sdk/src/utils/parseBaseSymbol.ts b/sdk/src/utils/parseBaseSymbol.ts index 724310d2..7b2491da 100644 --- a/sdk/src/utils/parseBaseSymbol.ts +++ b/sdk/src/utils/parseBaseSymbol.ts @@ -20,8 +20,6 @@ export default function parseBaseSymbol(lyra: Lyra, marketAddressOrName: string) } } else { switch (rawBaseKey.toLowerCase()) { - // TODO @michaelxuwu Update for Op Newport release - // case 'seth': case 'eth': case 'weth': return 'WETH' diff --git a/ui/components/Table/index.tsx b/ui/components/Table/index.tsx index ae513411..3c966a6d 100644 --- a/ui/components/Table/index.tsx +++ b/ui/components/Table/index.tsx @@ -210,107 +210,93 @@ export default function Table({ ) : null return ( - <> + {tableMarkerEl} - - {row.cells.map((cell: any, cellIdx) => { - return ( - { - if (row.original.onToggleExpand) { - row.original.onToggleExpand(!isExpanded) - } - if (row.original.onClick) { - row.original.onClick() - } - }} - as="td" - key={cellIdx} - alignItems="center" - px={DEFAULT_CELL_PX} - py={DEFAULT_CELL_PY} - {...(prepareCellProps(cell) as any)} - > - {cell.render('Cell')} - - ) - })} - - {expandedContent ? ( - { - if (row.original.isExpandedContentClickable) { + {row.cells.map((cell: any, cellIdx) => { + return ( + { if (row.original.onToggleExpand) { row.original.onToggleExpand(!isExpanded) } if (row.original.onClick) { row.original.onClick() } + }} + as="td" + key={cellIdx} + alignItems="center" + px={DEFAULT_CELL_PX} + py={DEFAULT_CELL_PY} + {...(prepareCellProps(cell) as any)} + > + {cell.render('Cell')} + + ) + })} + + {expandedContent ? ( + { + if (row.original.isExpandedContentClickable) { + if (row.original.onToggleExpand) { + row.original.onToggleExpand(!isExpanded) } - }} - as="tr" - sx={{ - borderBottom: - !isOutline && isExpanded && rowIdx < pagedRows.length - 1 ? '2px solid' : undefined, - borderColor: 'background', - }} - > - - - - {expandedContent} - - - + if (row.original.onClick) { + row.original.onClick() + } + } + }} + as="tr" + sx={{ + borderBottom: !isOutline && isExpanded && rowIdx < pagedRows.length - 1 ? '2px solid' : undefined, + borderColor: 'background', + }} + > + + + + {expandedContent} + + - ) : null} - - + + ) : null} + ) })}