Skip to content

Commit

Permalink
v6.1.3
Browse files Browse the repository at this point in the history
v6.1.3
  • Loading branch information
platschi authored Feb 15, 2023
2 parents 4654486 + 6bcc162 commit 73dd231
Show file tree
Hide file tree
Showing 21 changed files with 382 additions and 305 deletions.
19 changes: 17 additions & 2 deletions components/Text/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ type BodyProps = {
fontSize?: number;
mono?: boolean;
color?: 'title' | 'value' | 'body';
inline?: boolean;
};

const Body: React.FC<BodyProps> = memo(
({ size = 'small', variant = 'regular', fontSize, mono, ...props }) => {
({ size = 'small', variant = 'regular', fontSize, mono, inline, ...props }) => {
return (
<StyledBody $size={size} $variant={variant} $fontSize={fontSize} $mono={mono} {...props} />
<StyledBody
$size={size}
$variant={variant}
$fontSize={fontSize}
$mono={mono}
$inline={inline}
{...props}
/>
);
}
);
Expand All @@ -23,6 +31,7 @@ const StyledBody = styled.p<{
$variant?: BodyProps['variant'];
$fontSize?: number;
$mono?: boolean;
$inline?: boolean;
}>`
line-height: 1.4;
margin: 0;
Expand Down Expand Up @@ -65,6 +74,12 @@ const StyledBody = styled.p<{
css`
font-size: ${props.$fontSize}px;
`}
${(props) =>
props.$inline &&
css`
display: inline;
`}
`;

export default Body;
12 changes: 0 additions & 12 deletions queries/futures/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ export type FuturesOpenInterest = {
};
};

export type MarginTransfer = {
timestamp: number;
account: string;
size: Wei;
txHash: string;
action: string;
amount: string;
isPositive: boolean;
market?: string;
asset?: FuturesMarketAsset;
};

export type Participant = {
username: string;
address: string;
Expand Down
96 changes: 0 additions & 96 deletions queries/futures/useGetFuturesMarginTransfers.ts

This file was deleted.

68 changes: 1 addition & 67 deletions queries/futures/utils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import { BigNumber } from '@ethersproject/bignumber';
import { ContractsMap, NetworkId } from '@synthetixio/contracts-interface';
import Wei, { wei } from '@synthetixio/wei';
import { utils } from 'ethers';

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 { FuturesMarketAsset } from 'sdk/types/futures';
import { formatDollars } from 'utils/formatters/number';

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

export const getFuturesEndpoint = (networkId: NetworkId): string => {
return FUTURES_ENDPOINTS[networkId] || FUTURES_ENDPOINTS[chain.optimism.id];
Expand Down Expand Up @@ -179,60 +170,3 @@ export const getReasonFromCode = (
return 'unknown';
}
};

export const mapMarginTransfers = (
marginTransfers: FuturesMarginTransferResult[]
): MarginTransfer[] => {
return marginTransfers?.map(
({
timestamp,
account,
market,
size,
asset,
txHash,
}: FuturesMarginTransferResult): MarginTransfer => {
const sizeWei = new Wei(size);
const cleanSize = sizeWei.div(ETH_UNIT).abs();
const isPositive = sizeWei.gt(0);
const amount = `${isPositive ? '+' : '-'}${formatDollars(cleanSize)}`;
const numTimestamp = wei(timestamp).toNumber();

return {
timestamp: numTimestamp,
account,
market,
size,
action: isPositive ? 'deposit' : 'withdraw',
amount,
isPositive,
asset: utils.parseBytes32String(asset) as FuturesMarketAsset,
txHash,
};
}
);
};

export const mapCrossMarginTransfers = (
marginTransfers: CrossMarginAccountTransferResult[]
): MarginTransfer[] => {
return marginTransfers?.map(
({ timestamp, account, size, txHash }: CrossMarginAccountTransferResult): MarginTransfer => {
const sizeWei = new Wei(size);
const cleanSize = sizeWei.div(ETH_UNIT).abs();
const isPositive = sizeWei.gt(0);
const amount = `${isPositive ? '+' : '-'}${formatDollars(cleanSize)}`;
const numTimestamp = wei(timestamp).toNumber();

return {
timestamp: numTimestamp,
account,
size,
action: isPositive ? 'deposit' : 'withdraw',
amount,
isPositive,
txHash,
};
}
);
};
39 changes: 39 additions & 0 deletions sdk/constants/futures.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { gql } from 'graphql-request';

import { FuturesMarketAsset, FuturesMarketConfig, FuturesMarketKey } from 'sdk/types/futures';

export const FUTURES_ENDPOINT_OP_MAINNET = `https://subgraph.satsuma-prod.com/${process.env.NEXT_PUBLIC_SATSUMA_API_KEY}/kwenta/optimism-perps/api`;
Expand Down Expand Up @@ -285,3 +287,40 @@ export const BPS_CONVERSION = 10000;
export const DEFAULT_DESIRED_TIMEDELTA = 0;

export const AGGREGATE_ASSET_KEY = '0x';

// subgraph fragments
export const ISOLATED_MARGIN_FRAGMENT = gql`
query userFuturesMarginTransfers($walletAddress: String!) {
futuresMarginTransfers(
where: { account: $walletAddress }
orderBy: timestamp
orderDirection: desc
first: 1000
) {
id
timestamp
account
market
size
asset
txHash
}
}
`;

export const CROSS_MARGIN_FRAGMENT = gql`
query userCrossMarginTransfers($walletAddress: String!) {
crossMarginAccountTransfers(
where: { abstractAccount: $walletAddress }
orderBy: timestamp
orderDirection: desc
first: 1000
) {
id
timestamp
account
size
txHash
}
}
`;
16 changes: 16 additions & 0 deletions sdk/queries/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
getFuturesPositions,
getFuturesTrades,
} from 'queries/futures/subgraph';
import { CROSS_MARGIN_FRAGMENT, ISOLATED_MARGIN_FRAGMENT } from 'sdk/constants/futures';
import { mapCrossMarginTransfers, mapMarginTransfers } from 'sdk/utils/futures';

export const queryAccountsFromSubgraph = async (
sdk: KwentaSDK,
Expand Down Expand Up @@ -138,3 +140,17 @@ export const queryPositionHistory = (sdk: KwentaSDK, account: string) => {
}
);
};

export const queryIsolatedMarginTransfers = async (sdk: KwentaSDK, account: string) => {
const response = await request(sdk.futures.futuresGqlEndpoint, ISOLATED_MARGIN_FRAGMENT, {
walletAddress: account,
});
return response ? mapMarginTransfers(response.futuresMarginTransfers) : [];
};

export const queryCrossMarginTransfers = async (sdk: KwentaSDK, account: string) => {
const response = await request(sdk.futures.futuresGqlEndpoint, CROSS_MARGIN_FRAGMENT, {
walletAddress: account,
});
return response ? mapCrossMarginTransfers(response.crossMarginAccountTransfers) : [];
};
21 changes: 20 additions & 1 deletion sdk/services/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import {
} from 'sdk/contracts/types';
import { IPerpsV2MarketConsolidated } from 'sdk/contracts/types/PerpsV2Market';
import { IPerpsV2MarketSettings } from 'sdk/contracts/types/PerpsV2MarketData';
import { queryCrossMarginAccounts, queryPositionHistory, queryTrades } from 'sdk/queries/futures';
import {
queryCrossMarginAccounts,
queryCrossMarginTransfers,
queryIsolatedMarginTransfers,
queryPositionHistory,
queryTrades,
} from 'sdk/queries/futures';
import { NetworkOverrideOptions } from 'sdk/types/common';
import {
CrossMarginOrderType,
Expand All @@ -40,6 +46,7 @@ import {
PositionDetail,
PositionSide,
ModifyPositionOptions,
MarginTransfer,
} from 'sdk/types/futures';
import { PricesMap } from 'sdk/types/prices';
import {
Expand Down Expand Up @@ -396,6 +403,18 @@ export default class FuturesService {
return response ? calculateVolumes(response) : {};
}

public async getIsolatedMarginTransfers(
walletAddress?: string | null
): Promise<MarginTransfer[]> {
const address = walletAddress ?? this.sdk.context.walletAddress;
return queryIsolatedMarginTransfers(this.sdk, address);
}

public async getCrossMarginTransfers(walletAddress?: string | null): Promise<MarginTransfer[]> {
const address = walletAddress ?? this.sdk.context.walletAddress;
return queryCrossMarginTransfers(this.sdk, address);
}

public async getCrossMarginAccounts(walletAddress?: string | null) {
const address = walletAddress ?? this.sdk.context.walletAddress;
return await queryCrossMarginAccounts(this.sdk, address);
Expand Down
10 changes: 10 additions & 0 deletions sdk/types/futures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,13 @@ export type FuturesTrade<T = Wei> = {
orderType: FuturesOrderTypeDisplay;
accountType: FuturesAccountType;
};

export type MarginTransfer = {
timestamp: number;
account: string;
size: number;
txHash: string;
action: string;
market?: string;
asset?: FuturesMarketAsset;
};
Loading

0 comments on commit 73dd231

Please sign in to comment.