Skip to content

Commit

Permalink
v5.3.10
Browse files Browse the repository at this point in the history
v5.3.10
  • Loading branch information
platschi authored Jan 18, 2023
2 parents 93b2700 + 5babcaa commit 52b3fde
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
36 changes: 22 additions & 14 deletions state/futures/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import {
selectMarketAssetRate,
selectMarketInfo,
selectMarketKey,
selectMarkets,
selectOrderType,
selectPosition,
selectTradeSizeInputs,
Expand All @@ -99,20 +100,27 @@ import {
ModifyIsolatedPositionInputs,
} from './types';

export const fetchMarkets = createAsyncThunk<
{ markets: FuturesMarket<string>[]; fundingRates: FundingRateSerialized[] },
void,
ThunkConfig
>('futures/fetchMarkets', async (_, { extra: { sdk } }) => {
const markets = await sdk.futures.getMarkets();
const serializedMarkets = serializeMarkets(markets);
const averageFundingRates = await sdk.futures.getAverageFundingRates(markets, Period.ONE_HOUR);
const seriailizedRates = averageFundingRates.map((r) => ({
...r,
fundingRate: r.fundingRate ? r.fundingRate.toString() : null,
}));
return { markets: serializedMarkets, fundingRates: seriailizedRates };
});
export const fetchMarkets = createAsyncThunk<FuturesMarket<string>[], void, ThunkConfig>(
'futures/fetchMarkets',
async (_, { extra: { sdk } }) => {
const markets = await sdk.futures.getMarkets();
const serializedMarkets = serializeMarkets(markets);
return serializedMarkets;
}
);

export const fetchFundingRates = createAsyncThunk<FundingRateSerialized[], void, ThunkConfig>(
'futures/fetchFundingRates',
async (_, { getState, extra: { sdk } }) => {
const markets = selectMarkets(getState());
const averageFundingRates = await sdk.futures.getAverageFundingRates(markets, Period.ONE_HOUR);
const seriailizedRates = averageFundingRates.map((r) => ({
...r,
fundingRate: r.fundingRate ? r.fundingRate.toString() : null,
}));
return seriailizedRates;
}
);

export const fetchCrossMarginBalanceInfo = createAsyncThunk<
CrossMarginBalanceInfo<string>,
Expand Down
7 changes: 7 additions & 0 deletions state/futures/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { selectNetwork, selectWallet } from 'state/wallet/selectors';
import {
fetchCrossMarginAccountData,
fetchCrossMarginSettings,
fetchFundingRates,
fetchIsolatedMarginAccountData,
fetchMarkets,
fetchOpenOrders,
Expand Down Expand Up @@ -52,6 +53,12 @@ export const usePollDashboardFuturesData = () => {
const crossMarginAddress = useAppSelector(selectCrossMarginAccount);

usePollAction('fetchMarkets', fetchMarkets, { intervalTime: 60000, dependencies: [networkId] });
usePollAction('fetchFundingRates', fetchFundingRates, {
intervalTime: 60000,
disabled: markets.length === 0,
dependencies: [networkId, markets.length],
});

usePollAction('fetchIsolatedMarginAccountData', fetchIsolatedMarginAccountData, {
intervalTime: 30000,
dependencies: [wallet, markets.length, networkId],
Expand Down
20 changes: 18 additions & 2 deletions state/futures/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
fetchIsolatedMarginTradePreview,
fetchCrossMarginTradePreview,
fetchKeeperEthBalance,
fetchFundingRates,
} from './actions';
import {
CrossMarginTradeFees,
Expand Down Expand Up @@ -85,6 +86,7 @@ const initialState: FuturesState = {
crossMarginSettings: DEFAULT_QUERY_STATUS,
isolatedTradePreview: DEFAULT_QUERY_STATUS,
crossMarginTradePreview: DEFAULT_QUERY_STATUS,
fetchFundingRates: DEFAULT_QUERY_STATUS,
},
transaction: undefined,
transactionEstimations: {} as TransactionEstimations,
Expand Down Expand Up @@ -278,8 +280,7 @@ const futuresSlice = createSlice({
});
builder.addCase(fetchMarkets.fulfilled, (futuresState, action) => {
futuresState.queryStatuses.markets = SUCCESS_STATUS;
futuresState.markets = action.payload.markets;
futuresState.fundingRates = action.payload.fundingRates;
futuresState.markets = action.payload;
});
builder.addCase(fetchMarkets.rejected, (futuresState) => {
futuresState.queryStatuses.markets = {
Expand Down Expand Up @@ -429,6 +430,21 @@ const futuresSlice = createSlice({
builder.addCase(fetchKeeperEthBalance.fulfilled, (futuresState, action) => {
futuresState.crossMargin.balanceInfo.keeperEthBal = action.payload;
});

// Fetch funding rates
builder.addCase(fetchFundingRates.pending, (futuresState) => {
futuresState.queryStatuses.fetchFundingRates = LOADING_STATUS;
});
builder.addCase(fetchFundingRates.fulfilled, (futuresState, action) => {
futuresState.queryStatuses.fetchFundingRates = SUCCESS_STATUS;
futuresState.fundingRates = action.payload;
});
builder.addCase(fetchFundingRates.rejected, (futuresState) => {
futuresState.queryStatuses.fetchFundingRates = {
status: FetchStatus.Error,
error: 'Failed to fetch funding rates',
};
});
},
});

Expand Down
1 change: 1 addition & 0 deletions state/futures/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type FundingRate<T = Wei> = {

export type FuturesQueryStatuses = {
markets: QueryStatus;
fetchFundingRates: QueryStatus;
crossMarginBalanceInfo: QueryStatus;
dailyVolumes: QueryStatus;
crossMarginPositions: QueryStatus;
Expand Down

1 comment on commit 52b3fde

@vercel
Copy link

@vercel vercel bot commented on 52b3fde Jan 18, 2023

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
dev.kwenta.io
kwenta-kwenta.vercel.app

Please sign in to comment.