Skip to content

Commit

Permalink
v6.2.1
Browse files Browse the repository at this point in the history
v6.2.1
  • Loading branch information
platschi authored Mar 6, 2023
2 parents dbac62e + 636243e commit 240e3d6
Show file tree
Hide file tree
Showing 49 changed files with 534 additions and 366 deletions.
7 changes: 4 additions & 3 deletions components/Badge/MarketBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, memo } from 'react';
import React, { FC, memo, ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';

Expand All @@ -14,6 +14,7 @@ type MarketBadgeProps = {
currencyKey: FuturesMarketAsset | null;
isFuturesMarketClosed: boolean;
futuresClosureReason?: FuturesClosureReason;
fallbackComponent?: ReactElement;
};

type TransitionBadgeProps = {
Expand All @@ -31,7 +32,7 @@ export const TransitionBadge: FC<TransitionBadgeProps> = memo(({ isOpen }) => {
});

export const MarketBadge: FC<MarketBadgeProps> = memo(
({ currencyKey, isFuturesMarketClosed, futuresClosureReason }) => {
({ currencyKey, isFuturesMarketClosed, futuresClosureReason, fallbackComponent }) => {
const { t } = useTranslation();
const isOpen = marketIsOpen((currencyKey as CurrencyKey) ?? null);

Expand All @@ -54,7 +55,7 @@ export const MarketBadge: FC<MarketBadgeProps> = memo(
return <TransitionBadge isOpen={isOpen} />;
}

return null;
return fallbackComponent ? fallbackComponent : null;
}
);

Expand Down
33 changes: 30 additions & 3 deletions components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export type ButtonVariant =
| 'danger'
| 'text'
| 'select'
| 'yellow';
| 'yellow'
| 'long'
| 'short';

type BaseButtonProps = {
$size: 'small' | 'medium' | 'large';
Expand All @@ -29,7 +31,6 @@ type BaseButtonProps = {
};

export const border = css`
box-shadow: ${(props) => props.theme.colors.selectedTheme.button.shadow};
background: ${(props) => props.theme.colors.selectedTheme.button.background};
border: none;
Expand Down Expand Up @@ -107,7 +108,6 @@ const BaseButton = styled.button<BaseButtonProps>`
css`
background: ${props.theme.colors.selectedTheme.button.fill};
border: ${props.theme.colors.selectedTheme.border};
box-shadow: none;
&:hover {
background: ${props.theme.colors.selectedTheme.button.fillHover};
}
Expand All @@ -116,6 +116,33 @@ const BaseButton = styled.button<BaseButtonProps>`
}
`}
${(props) =>
props.$variant === 'long' &&
css`
color: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.long.active.color};
background: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.long.active.background};
&:hover {
background: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.long.hover.background};
}
`}
${(props) =>
props.$variant === 'short' &&
css`
color: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.short.active.color};
background: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.short.active.background};
&:hover {
background: ${(props) =>
props.theme.colors.selectedTheme.newTheme.button.position.short.hover.background};
}
`}
${(props) =>
props.$variant === 'yellow' &&
css`
Expand Down
8 changes: 4 additions & 4 deletions constants/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export const EXTERNAL_LINKS = {
FeeReclamation: 'https://docs.kwenta.io/resources/fee-reclamation',
HowToTrade: 'https://docs.kwenta.io/products/futures',
Governance:
'https://app.radicle.xyz/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/1.md',
'https://kwenta-gov.on.fleek.co/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/1.md',
DaoRoles:
'https://app.radicle.xyz/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/2.md',
'https://kwenta-gov.on.fleek.co/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/2.md',
HowToUse: 'https://docs.kwenta.io/onboard/how-to-start-using-kwenta',
Perpetuals: 'https://docs.kwenta.io/products/futures',
Spot: 'https://docs.kwenta.io/products/swaps ',
DevDao: 'https://docs.kwenta.io/dao/contribute/devdao-contribute',
MarketingDao:
'https://app.radicle.xyz/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/2.md#marketingdao-grants-council-trial',
'https://kwenta-gov.on.fleek.co/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master/sections/2.md#marketingdao-grants-council-trial',
Faq: 'https://docs.kwenta.io/resources/faq',
CrossMarginFaq: 'https://docs.kwenta.io/products/futures/cross-margin-accounts',
Staking: 'https://docs.kwenta.io/using-kwenta/staking-kwenta',
Expand All @@ -64,7 +64,7 @@ export const EXTERNAL_LINKS = {
},
Governance: {
Kips:
'https://app.radicle.xyz/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master',
'https://kwenta-gov.on.fleek.co/seeds/maple.radicle.garden/rad:git:hnrkq1oex148yz4zi9tm7spfnjaryyuc93yay/tree/master',
Vote: 'https://snapshot.org/#/kwenta.eth',
},
Competition: {
Expand Down
63 changes: 0 additions & 63 deletions queries/futures/constants.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,3 @@
import { utils as ethersUtils } from 'ethers';
import { gql } from 'graphql-request';

import { chain } from 'containers/Connector/config';

export const FUTURES_ENDPOINT_OP_MAINNET = `https://subgraph.satsuma-prod.com/${process.env.NEXT_PUBLIC_SATSUMA_API_KEY}/kwenta/optimism-perps/api`;

export const FUTURES_ENDPOINT_OP_GOERLI =
'https://api.thegraph.com/subgraphs/name/kwenta/optimism-goerli-perps';

export const FUTURES_ENDPOINTS = {
[chain.optimism.id]: FUTURES_ENDPOINT_OP_MAINNET,
[chain.optimismGoerli.id]: FUTURES_ENDPOINT_OP_GOERLI,
};

export const MAIN_ENDPOINT_MAINNET = `https://gateway.thegraph.com/api/${process.env.NEXT_PUBLIC_THEGRAPH_API_KEY}/subgraphs/id/HLy7PdmPJuVGjjmPNz1vW5RCCRpqzRWony2fSn7UKpf9`;

export const MAIN_ENDPOINT_OP_MAINNET = `https://subgraph.satsuma-prod.com/${process.env.NEXT_PUBLIC_SATSUMA_API_KEY}/kwenta/optimism-main/api`;

export const MAIN_ENDPOINT_OP_GOERLI =
'https://api.thegraph.com/subgraphs/name/kwenta/optimism-goerli-main';

export const MAIN_ENDPOINTS = {
[chain.mainnet.id]: MAIN_ENDPOINT_MAINNET,
[chain.optimism.id]: MAIN_ENDPOINT_OP_MAINNET,
[chain.optimismGoerli.id]: MAIN_ENDPOINT_OP_GOERLI,
};

export const DAY_PERIOD = 24;

export const SECONDS_PER_DAY = 24 * 60 * 60;

export const FUTURES_POSITION_FRAGMENT = gql`
fragment FuturesPositionFragment on FuturesPosition {
id
abstractAccount
openTimestamp
closeTimestamp
lastTxHash
timestamp
account
market
asset
initialMargin
margin
size
feesPaid
totalDeposits
netTransfers
netFunding
isOpen
isLiquidated
entryPrice
exitPrice
avgEntryPrice
totalVolume
pnl
pnlWithFeesPaid
trades
}
`;
export const KWENTA_TRACKING_CODE = ethersUtils.formatBytes32String('KWENTA');

export const AGGREGATE_ASSET_KEY = '0x';

export const ORDER_PREVIEW_ERRORS = { insufficient_margin: 'Insufficient free margin' };
Expand Down
4 changes: 2 additions & 2 deletions queries/futures/useGetFuturesCumulativeStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import QUERY_KEYS from 'constants/queryKeys';
import ROUTES from 'constants/routes';
import Connector from 'containers/Connector';
import useIsL2 from 'hooks/useIsL2';
import { FUTURES_ENDPOINT_OP_MAINNET } from 'sdk/constants/futures';
import { getFuturesEndpoint } from 'sdk/utils/futures';
import logError from 'utils/logError';

import { FUTURES_ENDPOINT_OP_MAINNET } from './constants';
import { FuturesCumulativeStats } from './types';
import { getFuturesEndpoint } from './utils';

const useGetFuturesCumulativeStats = (options?: UseQueryOptions<FuturesCumulativeStats | null>) => {
const { network } = Connector.useContainer();
Expand Down
2 changes: 1 addition & 1 deletion queries/futures/useGetFuturesTradersStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { NetworkId } from '@synthetixio/contracts-interface';
import { useQuery } from 'react-query';

import { chain } from 'containers/Connector/config';
import { getFuturesEndpoint } from 'sdk/utils/futures';
import { useAppSelector } from 'state/hooks';
import { selectMinTimestamp } from 'state/stats/selectors';
import logError from 'utils/logError';

import { getFuturesPositions } from './subgraph';
import { getFuturesEndpoint } from './utils';

type TradersStatMap = Record<
string,
Expand Down
3 changes: 1 addition & 2 deletions queries/futures/useGetFuturesTrades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import QUERY_KEYS from 'constants/queryKeys';
import Connector from 'containers/Connector';
import { notNill } from 'queries/synths/utils';
import { FuturesTrade } from 'sdk/types/futures';
import { mapTrades } from 'sdk/utils/futures';
import { getFuturesEndpoint, mapTrades } from 'sdk/utils/futures';
import logError from 'utils/logError';

import { getFuturesTrades } from './subgraph';
import { getFuturesEndpoint } from './utils';

const useGetFuturesTrades = (
currencyKey: string | undefined,
Expand Down
4 changes: 2 additions & 2 deletions queries/futures/useGetStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ETH_UNIT } from 'constants/network';
import QUERY_KEYS from 'constants/queryKeys';
import Connector from 'containers/Connector';
import useIsL2 from 'hooks/useIsL2';
import { FUTURES_ENDPOINT_OP_MAINNET } from 'sdk/constants/futures';
import { getFuturesEndpoint } from 'sdk/utils/futures';
import { truncateAddress } from 'utils/formatters/string';
import logError from 'utils/logError';

import { FUTURES_ENDPOINT_OP_MAINNET } from './constants';
import { getFuturesStats } from './subgraph';
import { AccountStat, FuturesStat } from './types';
import { getFuturesEndpoint } from './utils';

const useGetStats = (homepage?: boolean, options?: UseQueryOptions<any>) => {
const { network } = Connector.useContainer();
Expand Down
2 changes: 1 addition & 1 deletion queries/futures/useGetStatsVolumes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { useQuery } from 'react-query';

import { chain } from 'containers/Connector/config';
import { PERIOD_IN_SECONDS } from 'sdk/constants/period';
import { getFuturesEndpoint } from 'sdk/utils/futures';
import { useAppSelector } from 'state/hooks';
import { selectMinTimestamp } from 'state/stats/selectors';
import { weiFromWei } from 'utils/formatters/number';
import logError from 'utils/logError';

import { AGGREGATE_ASSET_KEY } from './constants';
import { getFuturesAggregateStats } from './subgraph';
import { getFuturesEndpoint } from './utils';

type VolumeStat = {
date: string;
Expand Down
2 changes: 1 addition & 1 deletion queries/futures/useLeaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useQuery, UseQueryOptions } from 'react-query';

import QUERY_KEYS from 'constants/queryKeys';
import Connector from 'containers/Connector';
import { getFuturesEndpoint } from 'sdk/utils/futures';
import { weiFromWei } from 'utils/formatters/number';
import { truncateAddress } from 'utils/formatters/string';
import logError from 'utils/logError';

import { AccountStat, FuturesStat } from './types';
import { getFuturesEndpoint } from './utils';

const mapStat = (stat: FuturesStat, i: number) => ({
...stat,
Expand Down
62 changes: 3 additions & 59 deletions queries/futures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { BigNumber } from '@ethersproject/bignumber';
import { ContractsMap, NetworkId } from '@synthetixio/contracts-interface';
import Wei, { wei } from '@synthetixio/wei';
import { ContractsMap } from '@synthetixio/contracts-interface';
import { wei } from '@synthetixio/wei';

import { ETH_UNIT } from 'constants/network';
import { chain } from 'containers/Connector/config';
import { MarketClosureReason } from 'hooks/useMarketClosed';
import { SynthsTrades, SynthsVolumes } from 'queries/synths/type';

import { SECONDS_PER_DAY, FUTURES_ENDPOINTS, MAIN_ENDPOINTS } from './constants';
import { FuturesOpenInterest, FuturesOneMinuteStat, FundingRateUpdate } from './types';

export const getFuturesEndpoint = (networkId: NetworkId): string => {
return FUTURES_ENDPOINTS[networkId] || FUTURES_ENDPOINTS[chain.optimism.id];
};

export const getMainEndpoint = (networkId: NetworkId): string => {
return MAIN_ENDPOINTS[networkId] || MAIN_ENDPOINTS[chain.optimism.id];
};
import { FuturesOpenInterest, FuturesOneMinuteStat } from './types';

export const getFuturesMarketContract = (asset: string | null, contracts: ContractsMap) => {
if (!asset) throw new Error(`Asset needs to be specified`);
Expand Down Expand Up @@ -105,52 +95,6 @@ export const calculateDailyTradeStats = (futuresTrades: FuturesOneMinuteStat[])
);
};

export const calculateFundingRate = (
minTimestamp: number,
periodLength: number,
fundingRates: FundingRateUpdate[],
assetPrice: Wei,
currentFundingRate: Wei
): Wei | null => {
const numUpdates = fundingRates.length;
if (numUpdates < 2) return null;

// variables to keep track
let fundingPaid = wei(0);
let timeTotal = 0;
let lastTimestamp = minTimestamp;

// iterate through funding updates
for (let ind = 0; ind < numUpdates - 1; ind++) {
const minFunding = fundingRates[ind];
const maxFunding = fundingRates[ind + 1];

const fundingStart = new Wei(minFunding.funding, 18, true);
const fundingEnd = new Wei(maxFunding.funding, 18, true);

const fundingDiff = fundingStart.sub(fundingEnd);
const timeDiff = maxFunding.timestamp - Math.max(minFunding.timestamp, lastTimestamp);
const timeMax = maxFunding.timestamp - minFunding.timestamp;

if (timeMax > 0) {
fundingPaid = fundingPaid.add(fundingDiff.mul(timeDiff).div(timeMax));
timeTotal += timeDiff;
}
lastTimestamp = maxFunding.timestamp;
}

// add funding from current rate
const timeLeft = Math.max(periodLength - timeTotal, 0);
if (timeLeft > 0) {
fundingPaid = fundingPaid.add(
wei(currentFundingRate).mul(timeLeft).div(SECONDS_PER_DAY).mul(assetPrice)
);
}

const fundingRate = fundingPaid.div(assetPrice);
return fundingRate;
};

export const getReasonFromCode = (
reasonCode?: BigNumber
): MarketClosureReason | 'unknown' | null => {
Expand Down
9 changes: 6 additions & 3 deletions queries/staking/useGetFuturesFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { useQuery, UseQueryOptions } from 'react-query';
import { DEFAULT_NUMBER_OF_FUTURES_FEE } from 'constants/defaults';
import QUERY_KEYS from 'constants/queryKeys';
import useIsL2 from 'hooks/useIsL2';
import { FUTURES_ENDPOINT_OP_MAINNET } from 'queries/futures/constants';
import { getFuturesAggregateStats } from 'queries/futures/subgraph';
import { AGGREGATE_ASSET_KEY, FUTURES_ENDPOINT_OP_MAINNET } from 'sdk/constants/futures';
import { SECONDS_PER_DAY } from 'sdk/constants/period';

const useGetFuturesFee = (
start: number,
Expand All @@ -21,15 +22,17 @@ const useGetFuturesFee = (
{
first: DEFAULT_NUMBER_OF_FUTURES_FEE,
where: {
timestamp_gt: start,
asset: AGGREGATE_ASSET_KEY,
period: SECONDS_PER_DAY,
timestamp_gte: start,
timestamp_lt: end,
},
orderDirection: 'desc',
orderBy: 'timestamp',
},
{
timestamp: true,
feesSynthetix: true,
feesKwenta: true,
}
);
return response;
Expand Down
2 changes: 1 addition & 1 deletion queries/staking/useGetFuturesFeeForAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useQuery, UseQueryOptions } from 'react-query';

import { DEFAULT_NUMBER_OF_FUTURES_FEE } from 'constants/defaults';
import QUERY_KEYS from 'constants/queryKeys';
import { FUTURES_ENDPOINT_OP_MAINNET } from 'queries/futures/constants';
import { getFuturesTrades } from 'queries/futures/subgraph';
import { FUTURES_ENDPOINT_OP_MAINNET } from 'sdk/constants/futures';

const useGetFuturesFeeForAccount = (
account: string,
Expand Down
Loading

0 comments on commit 240e3d6

Please sign in to comment.