Skip to content

Commit

Permalink
Merge branch 'main' into ack-change
Browse files Browse the repository at this point in the history
  • Loading branch information
rosepuppy committed Jul 22, 2024
2 parents f56fbfa + 1f07a21 commit 64c46ac
Show file tree
Hide file tree
Showing 30 changed files with 215 additions and 146 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
"@cosmjs/proto-signing": "^0.32.1",
"@cosmjs/stargate": "^0.32.1",
"@cosmjs/tendermint-rpc": "^0.32.1",
"@dydxprotocol/v4-abacus": "1.8.46",
"@dydxprotocol/v4-abacus": "1.8.54",
"@dydxprotocol/v4-client-js": "^1.1.27",
"@dydxprotocol/v4-localization": "^1.1.158",
"@dydxprotocol/v4-localization": "^1.1.159",
"@ethersproject/providers": "^5.7.2",
"@hugocxl/react-to-image": "^0.0.9",
"@js-joda/core": "^5.5.3",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions public/configs/v1/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
"exchangeStats": "https://app.mode.com/dydx_eng/reports/58822121650d?secret_key=391d9214fe6aefec35b7d35c",
"initialMarginFractionLearnMore": "https://docs.dydx.exchange/governance/functionalities#liquidity-tiers",
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
"fetAgixMarketWindDownProposal": "https://www.mintscan.io/dydx/proposals/61",
"contractLossMechanismLearnMore": "https://help.dydx.trade/en/articles/166973-contract-loss-mechanisms-on-dydx-chain",
"isolatedMarginLearnMore": "https://help.dydx.trade/en/articles/172975-isolated-margin",
"mintscanValidatorsLearnMore": "https://www.mintscan.io/dydx/validators",
"protocolStaking": "https://protocolstaking.info/",
"stakingAndClaimingRewardsLearnMore": "https://help.dydx.trade/en/articles/178571-staking-and-unstaking-dydx-and-claiming-staking-rewards"
"stakingAndClaimingRewardsLearnMore": "https://help.dydx.trade/en/articles/178571-staking-and-unstaking-dydx-and-claiming-staking-rewards",
"rndrParamProposal": "https://www.mintscan.io/dydx/proposals/61"
},
"dydx-testnet-4": {
"tos": "https://dydx.exchange/v4-terms",
Expand Down Expand Up @@ -113,12 +113,12 @@
"exchangeStats": "https://app.mode.com/dydx_eng/reports/58822121650d?secret_key=391d9214fe6aefec35b7d35c",
"initialMarginFractionLearnMore": "https://docs.dydx.exchange/governance/functionalities#liquidity-tiers",
"equityTiersLearnMore": "https://help.dydx.trade/en/articles/171918-equity-tiers-and-rate-limits",
"fetAgixMarketWindDownProposal": "https://www.mintscan.io/dydx/proposals/61",
"contractLossMechanismLearnMore": "https://help.dydx.trade/en/articles/166973-contract-loss-mechanisms-on-dydx-chain",
"isolatedMarginLearnMore": "https://help.dydx.trade/en/articles/172975-isolated-margin",
"mintscanValidatorsLearnMore": "https://www.mintscan.io/dydx/validators",
"protocolStaking": "https://protocolstaking.info/",
"stakingAndClaimingRewardsLearnMore": "https://help.dydx.trade/en/articles/178571-staking-and-unstaking-dydx-and-claiming-staking-rewards"
"stakingAndClaimingRewardsLearnMore": "https://help.dydx.trade/en/articles/178571-staking-and-unstaking-dydx-and-claiming-staking-rewards",
"rndrParamProposal": "https://www.mintscan.io/dydx/proposals/61"
},
"[mainnet chain id]": {
"tos": "[HTTP link to TOS]",
Expand Down Expand Up @@ -147,7 +147,6 @@
"exchangeStats": "[HTTP link to exchange stats, can be null]",
"initialMarginFractionLearnMore": "[HTTP link to governance functionalities liquidity tiers, can be null]",
"equityTiersLearnMore": "[HTTP link to equity tiers learn more, can be null]",
"fetAgixMarketWindDownProposal": "[HTTP link to mintscan proposal]",
"contractLossMechanismLearnMore": "[HTTP link to documentation on contract loss mechanisms]",
"isolatedMarginLearnMore": "[HTTP link to documentation on isolated margin]",
"mintscanValidatorsLearnMore": "[HTTP link to mintscan info on validators]",
Expand Down
38 changes: 34 additions & 4 deletions src/components/Table/AssetTableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,69 @@
import styled from 'styled-components';

import type { Asset } from '@/constants/abacus';
import type { Asset, MarketConfigs } from '@/constants/abacus';

import breakpoints from '@/styles/breakpoints';
import { layoutMixins } from '@/styles/layoutMixins';

import { AssetIcon } from '@/components/AssetIcon';
import { Tag } from '@/components/Tag';

import { calculateMarketMaxLeverage } from '@/lib/marketsHelpers';
import { orEmptyRecord } from '@/lib/typeUtils';

import { Output, OutputType } from '../Output';
import { TableCell } from './TableCell';

interface AssetTableCellProps {
asset?: Pick<Asset, 'name' | 'id'>;
configs:
| Pick<MarketConfigs, 'effectiveInitialMarginFraction' | 'initialMarginFraction'>
| null
| undefined;
className?: string;
stacked?: boolean;
}

export const AssetTableCell = (props: AssetTableCellProps) => {
const { asset, stacked, className } = props;
const { asset, stacked, configs, className } = props;
const { initialMarginFraction, effectiveInitialMarginFraction } = orEmptyRecord(configs);

const maxLeverage =
configs != null ? (
<Output
type={OutputType.Multiple}
value={calculateMarketMaxLeverage({
effectiveInitialMarginFraction,
initialMarginFraction,
})}
fractionDigits={0}
/>
) : undefined;
return (
<TableCell className={className} slotLeft={<$AssetIcon stacked={stacked} symbol={asset?.id} />}>
<$TableCellContent stacked={stacked}>
<$Asset stacked={stacked}>{asset?.name}</$Asset>
{stacked ? <$AssetID>{asset?.id}</$AssetID> : <Tag>{asset?.id}</Tag>}
<$AssetAndTag>
<$Asset stacked={stacked}>{asset?.name}</$Asset>
<Tag>{maxLeverage}</Tag>
</$AssetAndTag>
{stacked ? <$AssetID>{asset?.id}</$AssetID> : undefined}
</$TableCellContent>
</TableCell>
);
};

const $TableCellContent = styled.div<{ stacked?: boolean }>`
gap: ${({ stacked }) => (stacked ? '0.125rem' : '0.75rem')};
display: flex;
flex-direction: ${({ stacked }) => (stacked ? 'column' : 'row')};
align-items: ${({ stacked }) => (stacked ? 'flex-start' : 'center')};
`;

const $AssetAndTag = styled.div`
${layoutMixins.row}
gap: 0.5rem;
`;

const $AssetIcon = styled(AssetIcon)<{ stacked?: boolean }>`
font-size: ${({ stacked }) => (stacked ? '1.5rem' : '2rem')};
Expand Down
1 change: 1 addition & 0 deletions src/constants/abacus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type MarketOrderbookGrouping = Abacus.exchange.dydx.abacus.output.MarketO
export type MarketTrade = Abacus.exchange.dydx.abacus.output.MarketTrade;
export type OrderbookLine = Abacus.exchange.dydx.abacus.output.OrderbookLine;
export type PerpetualMarket = Abacus.exchange.dydx.abacus.output.PerpetualMarket;
export type MarketConfigs = Abacus.exchange.dydx.abacus.output.MarketConfigs;
export type MarketHistoricalFunding = Abacus.exchange.dydx.abacus.output.MarketHistoricalFunding;
export const PerpetualMarketType = Abacus.exchange.dydx.abacus.output.PerpetualMarketType;

Expand Down
5 changes: 5 additions & 0 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SupportedLocales } from './localization';
import type { DydxNetwork } from './networks';
import { TransferNotificationTypes } from './notifications';
import type { TradeTypes } from './trade';
import { TradeToggleSizeInput } from './trade';
import type { DydxAddress, EvmAddress, WalletConnectionType, WalletType } from './wallets';

export type AnalyticsEventTrackMeta<T extends AnalyticsEventTypes> = {
Expand Down Expand Up @@ -197,6 +198,10 @@ export const AnalyticsEvents = unionize(
TradeOrderTypeSelected: ofType<{
type: TradeTypes;
}>(),
TradeAmountToggleClick: ofType<{
newInput: TradeToggleSizeInput;
market: string;
}>(),
TradePlaceOrder: ofType<
HumanReadablePlaceOrderPayload & {
isClosePosition: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/constants/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export const INCENTIVES_DISTRIBUTED_NOTIFICATION_ID =
export enum MarketWindDownNotificationIds {
MarketWindDownFetAgix = 'market-wind-down-fet-agix',
MarketWindDownProposalFetAgix = 'market-wind-down-proposal-fet-agix',
MarketUpdateProposalRndr = 'market-update-proposal-rndr',
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/constants/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export enum NumberSign {

// Deposit/Withdraw
export const MAX_CCTP_TRANSFER_AMOUNT = 1_000_000;
export const MIN_CCTP_TRANSFER_AMOUNT = 10;
export const MIN_CCTP_TRANSFER_AMOUNT = 11;
export const MAX_PRICE_IMPACT = 0.02; // 2%
export const DEFAULT_GAS_LIMIT = 160000;
2 changes: 2 additions & 0 deletions src/constants/trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export enum TradeSizeInput {
Usdc = 'size.usdcSize',
}

export type TradeToggleSizeInput = TradeSizeInput.Size | TradeSizeInput.Usdc;

export enum TradeBoxKeys {
LimitPrice = 'price.limitPrice',
TrailingPercent = 'price.trailingPercent',
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/Orderbook/useOrderbookValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { getCurrentMarketOrderbook } from '@/state/perpetualsSelectors';

import { MustBigNumber } from '@/lib/numbers';
import { safeAssign } from '@/lib/objectHelpers';
import { orEmptyObj } from '@/lib/typeUtils';
import { orEmptyRecord } from '@/lib/typeUtils';

export const useCalculateOrderbookData = ({ maxRowsPerSide }: { maxRowsPerSide: number }) => {
const orderbook = useAppSelector(getCurrentMarketOrderbook, shallowEqual);

const subaccountOrderSizeBySideAndPrice = orEmptyObj(
const subaccountOrderSizeBySideAndPrice = orEmptyRecord(
useAppSelector(getSubaccountOrderSizeBySideAndOrderbookLevel, shallowEqual)
);

Expand Down
10 changes: 6 additions & 4 deletions src/hooks/useMarketsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getPerpetualMarkets, getPerpetualMarketsClobIds } from '@/state/perpetu
import { isTruthy } from '@/lib/isTruthy';
import { objectKeys, safeAssign } from '@/lib/objectHelpers';
import { matchesSearchFilter } from '@/lib/search';
import { orEmptyObj } from '@/lib/typeUtils';
import { orEmptyRecord } from '@/lib/typeUtils';

const filterFunctions = {
[MarketFilters.ALL]: () => true,
Expand Down Expand Up @@ -60,9 +60,11 @@ export const useMarketsData = (
filteredMarkets: MarketData[];
marketFilters: MarketFilters[];
} => {
const allPerpetualMarkets = orEmptyObj(useAppSelector(getPerpetualMarkets, shallowEqual));
const allPerpetualClobIds = orEmptyObj(useAppSelector(getPerpetualMarketsClobIds, shallowEqual));
const allAssets = orEmptyObj(useAppSelector(getAssets, shallowEqual));
const allPerpetualMarkets = orEmptyRecord(useAppSelector(getPerpetualMarkets, shallowEqual));
const allPerpetualClobIds = orEmptyRecord(
useAppSelector(getPerpetualMarketsClobIds, shallowEqual)
);
const allAssets = orEmptyRecord(useAppSelector(getAssets, shallowEqual));
const sevenDaysSparklineData = usePerpetualMarketSparklines();

const markets = useMemo(() => {
Expand Down
67 changes: 14 additions & 53 deletions src/hooks/useNotificationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { useLocalNotifications } from '@/hooks/useLocalNotifications';
import { AssetIcon } from '@/components/AssetIcon';
import { Icon, IconName } from '@/components/Icon';
import { Link } from '@/components/Link';
import { Output, OutputType } from '@/components/Output';
// eslint-disable-next-line import/no-cycle
import { BlockRewardNotification } from '@/views/notifications/BlockRewardNotification';
import { IncentiveSeasonDistributionNotification } from '@/views/notifications/IncentiveSeasonDistributionNotification';
Expand Down Expand Up @@ -466,77 +465,43 @@ export const notificationTypes: NotificationTypeConfig[] = [
useTrigger: ({ trigger }) => {
const stringGetter = useStringGetter();

const { fetAgixMarketWindDownProposal, contractLossMechanismLearnMore } = useURLConfigs();
const { rndrParamProposal } = useURLConfigs();

const marketWindDownProposalExpirationDate = '2024-06-11T16:53:00';
const marketWindDownDate = marketWindDownProposalExpirationDate;
const marketWindDownExpirationDate = '2024-07-11T16:53:00'; // 30 days after wind down
const currentDate = new Date();

const outputDate = <$Output type={OutputType.DateTime} value={marketWindDownDate} />;
const RNDNProposalTriggerDate = new Date('2024-07-20T22:00:00.000Z');
const RNDNProposalExpireDate = new Date('2024-08-20T22:00:00.000Z');

const firstMarket = 'FET-USD';
const secondMarket = 'AGIX-USD';

useEffect(() => {
if (currentDate <= new Date(marketWindDownProposalExpirationDate)) {
trigger(MarketWindDownNotificationIds.MarketWindDownProposalFetAgix, {
title: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN_PROPOSAL.TITLE',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
},
}),
body: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN_PROPOSAL.BODY',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
DATE: outputDate,
HERE_LINK: (
<Link href={fetAgixMarketWindDownProposal} isAccent isInline>
{stringGetter({ key: STRING_KEYS.HERE })}
</Link>
),
},
}),
toastSensitivity: 'foreground',
groupKey: MarketWindDownNotificationIds.MarketWindDownProposalFetAgix,
});
}
}, [stringGetter]);
const RNDRMarket = 'RNDR-USD';

useEffect(() => {
if (
currentDate >= new Date(marketWindDownDate) &&
currentDate <= new Date(marketWindDownExpirationDate)
rndrParamProposal &&
currentDate >= RNDNProposalTriggerDate &&
currentDate <= RNDNProposalExpireDate
) {
trigger(
MarketWindDownNotificationIds.MarketWindDownFetAgix,
MarketWindDownNotificationIds.MarketUpdateProposalRndr,
{
title: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN.TITLE',
key: 'NOTIFICATIONS.MARKET_PARAM_UPDATE.TITLE',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
MARKET: RNDRMarket,
},
}),
body: stringGetter({
key: 'NOTIFICATIONS.TWO_MARKET_WIND_DOWN.BODY',
key: 'NOTIFICATIONS.MARKET_PARAM_UPDATE.BODY',
params: {
MARKET_1: firstMarket,
MARKET_2: secondMarket,
DATE: outputDate,
MARKET: RNDRMarket,
HERE_LINK: (
<Link href={contractLossMechanismLearnMore} isAccent isInline>
<Link href={rndrParamProposal} isAccent isInline>
{stringGetter({ key: STRING_KEYS.HERE })}
</Link>
),
},
}),
toastSensitivity: 'foreground',
groupKey: MarketWindDownNotificationIds.MarketWindDownFetAgix,
groupKey: MarketWindDownNotificationIds.MarketUpdateProposalRndr,
},
[]
);
Expand Down Expand Up @@ -708,7 +673,3 @@ const $Icon = styled.img`
const $WarningIcon = styled(Icon)`
color: var(--color-warning);
`;

const $Output = styled(Output)`
display: inline-block;
`;
4 changes: 2 additions & 2 deletions src/hooks/usePerpetualMarketsStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { shallowEqual } from 'react-redux';
import { useAppSelector } from '@/state/appTypes';
import { getPerpetualMarkets } from '@/state/perpetualsSelectors';

import { isPresent, orEmptyObj } from '@/lib/typeUtils';
import { isPresent, orEmptyRecord } from '@/lib/typeUtils';

const FEE_ESTIMATION_MULTIPLIER = 0.0002; // 2bps

export const usePerpetualMarketsStats = () => {
const perpetualMarkets = orEmptyObj(useAppSelector(getPerpetualMarkets, shallowEqual));
const perpetualMarkets = orEmptyRecord(useAppSelector(getPerpetualMarkets, shallowEqual));

const markets = useMemo(
() => Object.values(perpetualMarkets).filter(isPresent),
Expand Down
Loading

0 comments on commit 64c46ac

Please sign in to comment.