Skip to content

Commit

Permalink
v5.3.1
Browse files Browse the repository at this point in the history
v5.3.1
  • Loading branch information
platschi authored Dec 21, 2022
2 parents 6a3452f + dab5592 commit c82bb2a
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 585 deletions.
3 changes: 0 additions & 3 deletions constants/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export const MAX_TIMESTAMP: number = 8640000000000000;
// for Fee History
export const DEFAULT_NUMBER_OF_FUTURES_FEE: number = 9999;

// leverage adjustment
export const DEFAULT_NP_LEVERAGE_ADJUSTMENT: number = 0.9975;

// for mobile leaderboard
export const DEFAULT_LEADERBOARD_ROWS = 20;

Expand Down
2 changes: 1 addition & 1 deletion constants/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { wei } from '@synthetixio/wei';

import { FuturesOrderType } from 'queries/futures/types';

export const ISOLATED_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market', 'next price'];
export const ISOLATED_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market'];
export const CROSS_MARGIN_ORDER_TYPES: FuturesOrderType[] = ['market', 'limit', 'stop market'];
export const ORDER_KEEPER_ETH_DEPOSIT = wei(0.01);
export const DEFAULT_MAX_LEVERAGE = wei(10);
Expand Down
5 changes: 0 additions & 5 deletions constants/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,6 @@ export const QUERY_KEYS = {
networkId,
market,
],
NextPriceDetails: (
networkId: NetworkId,
walletAddress: string | null,
currencyKey: string | null
) => ['futures', 'currentRoundId', networkId, walletAddress, currencyKey],
OverviewStats: (networkId: NetworkId) => ['futures', 'overview-stats', networkId],
CrossMarginSettings: (networkId: NetworkId, settingsAddress: string) => [
'futures',
Expand Down
2 changes: 2 additions & 0 deletions pages/dashboard/staking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
import DashboardLayout from 'sections/dashboard/DashboardLayout';
import StakingPortfolio, { StakeTab } from 'sections/dashboard/Stake/StakingPortfolio';
import StakingTabs from 'sections/dashboard/Stake/StakingTabs';
import GitHashID from 'sections/shared/Layout/AppLayout/GitHashID';
import { useAppDispatch, useAppSelector } from 'state/hooks';
import { fetchClaimableRewards, fetchEscrowData, fetchStakingData } from 'state/staking/actions';

Expand Down Expand Up @@ -39,6 +40,7 @@ const StakingPage: StakingComponent = () => {
</Head>
<StakingPortfolio setCurrentTab={setCurrentTab} />
<StakingTabs currentTab={currentTab} onChangeTab={handleChangeTab} />
<GitHashID />
</>
);
};
Expand Down
2 changes: 0 additions & 2 deletions pages/exchange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Connector from 'containers/Connector';
import ExchangeContent from 'sections/exchange/ExchangeContent';
import ExchangeHead from 'sections/exchange/ExchangeHead';
import AppLayout from 'sections/shared/Layout/AppLayout';
import Header from 'sections/shared/Layout/AppLayout/Header';
import { resetCurrencies } from 'state/exchange/actions';
import { useAppDispatch, useAppSelector } from 'state/hooks';
import { FullScreenContainer, MobileScreenContainer } from 'styles/common';
Expand All @@ -34,7 +33,6 @@ const Exchange: ExchangeComponent = () => {
<ExchangeHead />
<DesktopOnlyView>
<FullScreenContainer>
<Header />
<ExchangeContent />
<NotificationContainer />
</FullScreenContainer>
Expand Down
2 changes: 1 addition & 1 deletion queries/futures/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4308,5 +4308,5 @@ export const getTotals = async function <K extends keyof TotalResult>(

// additional types
export type FuturesAccountType = 'isolated_margin' | 'cross_margin';
export type FuturesOrderType = 'NextPrice' | 'Limit' | 'Market' | 'StopMarket';
export type FuturesOrderType = 'Limit' | 'Market' | 'StopMarket';
export type FuturesOrderStatus = 'Pending' | 'Filled' | 'Cancelled' | 'Open';
2 changes: 1 addition & 1 deletion queries/futures/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export type FuturesTradeInputs = {
orderPrice?: Wei | undefined;
};

export type FuturesOrderType = 'market' | 'next price' | 'stop market' | 'limit';
export type FuturesOrderType = 'market' | 'stop market' | 'limit';

export type SpotsFee = {
timestamp: string;
Expand Down
21 changes: 5 additions & 16 deletions queries/futures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { chain } from 'wagmi';
import { ETH_UNIT } from 'constants/network';
import { MarketClosureReason } from 'hooks/useMarketClosed';
import { SynthsTrades, SynthsVolumes } from 'queries/synths/type';
import { FuturesMarket, FuturesOrder, FuturesOrderTypeDisplay } from 'sdk/types/futures';
import { FuturesOrder, FuturesOrderTypeDisplay } from 'sdk/types/futures';
import { formatCurrency, formatDollars, weiFromWei } from 'utils/formatters/number';
import {
FuturesMarketAsset,
Expand Down Expand Up @@ -49,22 +49,14 @@ export const getFuturesMarketContract = (asset: string | null, contracts: Contra
};

const mapOrderType = (orderType: Partial<FuturesOrderType>): FuturesOrderTypeDisplay => {
return orderType === 'NextPrice'
? 'Next Price'
: orderType === 'StopMarket'
? 'Stop Market'
: orderType;
return orderType === 'StopMarket' ? 'Stop Market' : orderType;
};

export const mapFuturesOrders = (
o: FuturesOrderResult,
marketInfo: FuturesMarket | undefined
): FuturesOrder => {
export const mapFuturesOrders = (o: FuturesOrderResult): FuturesOrder => {
const asset: FuturesMarketAsset = parseBytes32String(o.asset) as FuturesMarketAsset;
const size = weiFromWei(o.size);
const targetPrice = weiFromWei(o.targetPrice ?? 0);
const targetRoundId = new Wei(o.targetRoundId, 0);
const currentRoundId = wei(marketInfo?.currentRoundId ?? 0);
const marginDelta = weiFromWei(o.marginDelta);
return {
...o,
Expand All @@ -82,11 +74,8 @@ export const mapFuturesOrders = (
}),
targetPriceTxt: formatDollars(targetPrice),
side: size.gt(0) ? PositionSide.LONG : PositionSide.SHORT,
isStale: o.orderType === 'NextPrice' && currentRoundId.gte(wei(o.targetRoundId).add(2)),
isExecutable:
o.orderType === 'NextPrice' && targetRoundId
? currentRoundId.eq(targetRoundId) || currentRoundId.eq(targetRoundId.add(1))
: false,
isStale: false,
isExecutable: false,
};
};

Expand Down
12 changes: 3 additions & 9 deletions sdk/services/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ export default class FuturesService {
feeRates: {
makerFee: wei(feeRates.makerFee),
takerFee: wei(feeRates.takerFee),
makerFeeNextPrice: wei(feeRates.makerFeeNextPrice),
takerFeeNextPrice: wei(feeRates.takerFeeNextPrice),
},
openInterest: {
shortPct: wei(marketSize).eq(0)
Expand Down Expand Up @@ -385,7 +383,7 @@ export default class FuturesService {
};
}

public async getOpenOrders(account: string, markets: FuturesMarket[]) {
public async getOpenOrders(account: string) {
const response = await request(
this.futuresGqlEndpoint,
gql`
Expand All @@ -409,8 +407,7 @@ export default class FuturesService {

const openOrders: FuturesOrder[] = response
? response.futuresOrders.map((o: any) => {
const marketInfo = markets.find((m) => m.asset === o.asset);
return mapFuturesOrders(o, marketInfo);
return mapFuturesOrders(o);
})
: [];
return openOrders;
Expand Down Expand Up @@ -519,14 +516,11 @@ export default class FuturesService {
public async modifyIsolatedMarginPosition<T extends boolean>(
marketAddress: string,
sizeDelta: Wei,
useNextPrice = false,
estimationOnly: T
): TxReturn<T> {
const market = FuturesMarket__factory.connect(marketAddress, this.sdk.context.signer);
const root = estimationOnly ? market.estimateGas : market;
return useNextPrice
? (root.submitNextPriceOrderWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any)
: (root.modifyPositionWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any);
return root.modifyPositionWithTracking(sizeDelta.toBN(), KWENTA_TRACKING_CODE) as any;
}
}

Expand Down
9 changes: 1 addition & 8 deletions sdk/types/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export type FuturesMarket<T = Wei> = {
feeRates: {
makerFee: T;
takerFee: T;
makerFeeNextPrice: T;
takerFeeNextPrice: T;
};
openInterest?: {
shortPct: number;
Expand Down Expand Up @@ -168,12 +166,7 @@ export type FuturesPosition<T = Wei> = {
};

// This type exists to rename enum types from the subgraph to display-friendly types
export type FuturesOrderTypeDisplay =
| 'Next Price'
| 'Limit'
| 'Stop Market'
| 'Market'
| 'Liquidation';
export type FuturesOrderTypeDisplay = 'Limit' | 'Stop Market' | 'Market' | 'Liquidation';

export type FuturesOrder<T = Wei> = {
id: string;
Expand Down
1 change: 1 addition & 0 deletions sections/dashboard/Stake/StakingTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const StakingTabsHeader = styled.div`
`;

const StakingTabsContainer = styled.div`
margin-bottom: 50px;
${media.lessThan('md')`
padding: 15px;
`}
Expand Down
43 changes: 1 addition & 42 deletions sections/futures/FeeInfoBox/FeeInfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
selectTradeSizeInputs,
} from 'state/futures/selectors';
import { useAppSelector } from 'state/hooks';
import { computeNPFee, computeMarketFee } from 'utils/costCalculations';
import { computeMarketFee } from 'utils/costCalculations';
import { formatCurrency, formatDollars, formatPercent, zeroBN } from 'utils/formatters/number';

const FeeInfoBox: React.FC = () => {
Expand All @@ -32,19 +32,6 @@ const FeeInfoBox: React.FC = () => {
);
const marketInfo = useAppSelector(selectMarketInfo);

const { commitDeposit, nextPriceFee } = useMemo(() => computeNPFee(marketInfo, nativeSizeDelta), [
marketInfo,
nativeSizeDelta,
]);

const totalDeposit = useMemo(() => {
return (commitDeposit ?? zeroBN).add(marketInfo?.keeperDeposit ?? zeroBN);
}, [commitDeposit, marketInfo?.keeperDeposit]);

const nextPriceDiscount = useMemo(() => {
return (nextPriceFee ?? zeroBN).sub(commitDeposit ?? zeroBN);
}, [commitDeposit, nextPriceFee]);

const staticRate = useMemo(() => computeMarketFee(marketInfo, nativeSizeDelta), [
marketInfo,
nativeSizeDelta,
Expand Down Expand Up @@ -114,30 +101,6 @@ const FeeInfoBox: React.FC = () => {
},
};
}
if (orderType === 'next price') {
return {
'Keeper Deposit': {
value: !!marketInfo?.keeperDeposit ? formatDollars(marketInfo.keeperDeposit) : NO_VALUE,
},
'Commit Deposit': {
value: !!commitDeposit
? formatDollars(commitDeposit, { minDecimals: commitDeposit.lt(0.01) ? 4 : 2 })
: NO_VALUE,
},
'Total Deposit': {
value: formatDollars(totalDeposit),
spaceBeneath: true,
},
'Next Price Discount': {
value: !!nextPriceDiscount ? formatDollars(nextPriceDiscount) : NO_VALUE,
color: nextPriceDiscount.lt(0) ? 'green' : nextPriceDiscount.gt(0) ? 'red' : undefined,
},
'Estimated Fees': {
value: formatDollars(totalDeposit.add(nextPriceDiscount ?? zeroBN)),
keyNode: dynamicFeeRate?.gt(0) ? <ToolTip /> : null,
},
};
}
return accountType === 'isolated_margin'
? {
Fee: {
Expand All @@ -154,13 +117,9 @@ const FeeInfoBox: React.FC = () => {
isolatedMarginFee,
crossMarginFees,
orderFeeRate,
dynamicFeeRate,
commitDeposit,
accountType,
marketInfo?.keeperDeposit,
nextPriceDiscount,
marketCostTooltip,
totalDeposit,
]);

return <StyledInfoBox details={feesInfo} />;
Expand Down
15 changes: 0 additions & 15 deletions sections/futures/LeverageInput/LeverageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
selectMarketAssetRate,
selectMarketInfo,
selectMaxLeverage,
selectNextPriceDisclaimer,
selectOrderType,
selectPosition,
} from 'state/futures/selectors';
import { useAppDispatch, useAppSelector } from 'state/hooks';
Expand All @@ -29,8 +27,6 @@ const LeverageInput: FC = () => {
const dispatch = useAppDispatch();
const [mode, setMode] = useState<'slider' | 'input'>('input');
const leverage = useAppSelector(selectIsolatedMarginLeverage);
const orderType = useAppSelector(selectOrderType);
const isDisclaimerDisplayed = useAppSelector(selectNextPriceDisclaimer);
const position = useAppSelector(selectPosition);
const marketInfo = useAppSelector(selectMarketInfo);
const maxLeverage = useAppSelector(selectMaxLeverage);
Expand Down Expand Up @@ -83,11 +79,6 @@ const LeverageInput: FC = () => {
</LeverageTitle>
{modeButton}
</LeverageRow>
{orderType === 'next price' && isDisclaimerDisplayed && (
<LeverageDisclaimer>
{t('futures.market.trade.input.leverage.disclaimer')}
</LeverageDisclaimer>
)}
{mode === 'slider' ? (
<SliderRow>
<LeverageSlider
Expand Down Expand Up @@ -182,12 +173,6 @@ const TextButton = styled.button`
cursor: pointer;
`;

const LeverageDisclaimer = styled.div`
font-size: 13px;
color: ${(props) => props.theme.colors.selectedTheme.gray};
margin: 0 8px 12px;
`;

export const StyledInput = styled(CustomNumericInput)`
font-family: ${(props) => props.theme.fonts.mono};
text-overflow: ellipsis;
Expand Down
39 changes: 3 additions & 36 deletions sections/futures/MarketInfoBox/MarketInfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,17 @@ import InfoBox from 'components/InfoBox';
import PreviewArrow from 'components/PreviewArrow';
import { FuturesPotentialTradeDetails } from 'sdk/types/futures';
import {
selectLeverageSide,
selectMarketInfo,
selectMaxLeverage,
selectOrderType,
selectPosition,
selectTradePreview,
selectTradeSizeInputs,
} from 'state/futures/selectors';
import { useAppSelector } from 'state/hooks';
import { computeNPFee } from 'utils/costCalculations';
import { formatDollars, formatPercent, zeroBN } from 'utils/formatters/number';

const MarketInfoBox: React.FC = () => {
const orderType = useAppSelector(selectOrderType);
const leverageSide = useAppSelector(selectLeverageSide);
const { nativeSize, nativeSizeDelta } = useAppSelector(selectTradeSizeInputs);
const { nativeSizeDelta } = useAppSelector(selectTradeSizeInputs);
const potentialTrade = useAppSelector(selectTradePreview);

const marketInfo = useAppSelector(selectMarketInfo);
Expand All @@ -41,26 +36,6 @@ const MarketInfoBox: React.FC = () => {
marketInfo?.minInitialMargin,
]);

const isNextPriceOrder = orderType === 'next price';

const positionSize = position?.position?.size ? wei(position?.position?.size) : zeroBN;
const orderDetails = useMemo(() => {
return {
newSize: nativeSize,
size: (positionSize ?? zeroBN).add(nativeSizeDelta).abs(),
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [leverageSide, positionSize]);

const { commitDeposit } = useMemo(() => computeNPFee(marketInfo, wei(orderDetails.newSize)), [
marketInfo,
orderDetails,
]);

const totalDeposit = useMemo(() => {
return (commitDeposit ?? zeroBN).add(marketInfo?.keeperDeposit ?? zeroBN);
}, [commitDeposit, marketInfo?.keeperDeposit]);

const getPotentialAvailableMargin = useCallback(
(trade: FuturesPotentialTradeDetails | null, marketMaxLeverage: Wei | undefined) => {
let inaccessible;
Expand Down Expand Up @@ -88,16 +63,8 @@ const MarketInfoBox: React.FC = () => {
potentialTrade,
marketInfo?.maxLeverage
);
return isNextPriceOrder
? potentialAvailableMargin?.sub(totalDeposit) ?? zeroBN
: potentialAvailableMargin;
}, [
potentialTrade,
marketInfo?.maxLeverage,
isNextPriceOrder,
totalDeposit,
getPotentialAvailableMargin,
]);
return potentialAvailableMargin;
}, [potentialTrade, marketInfo?.maxLeverage, getPotentialAvailableMargin]);

const previewTradeData = React.useMemo(() => {
const size = nativeSizeDelta.abs();
Expand Down
Loading

1 comment on commit c82bb2a

@vercel
Copy link

@vercel vercel bot commented on c82bb2a Dec 21, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

kwenta – ./

kwenta-git-main-kwenta.vercel.app
kwenta.io
kwenta-kwenta.vercel.app
dev.kwenta.io

Please sign in to comment.