Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sltp): update sltp/sltplimit to be flagged behind env.json instead of url params + enable sltp in all environments #467

Merged
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
"@cosmjs/proto-signing": "^0.32.1",
"@cosmjs/stargate": "^0.32.1",
"@cosmjs/tendermint-rpc": "^0.32.1",
"@dydxprotocol/v4-abacus": "^1.6.48",
"@dydxprotocol/v4-abacus": "^1.6.50",
"@dydxprotocol/v4-client-js": "^1.1.7",
"@dydxprotocol/v4-localization": "^1.1.71",
"@dydxprotocol/v4-localization": "^1.1.74",
"@ethersproject/providers": "^5.7.2",
"@js-joda/core": "^5.5.3",
"@privy-io/react-auth": "^1.59.7",
Expand Down
22 changes: 8 additions & 14 deletions pnpm-lock.yaml

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

64 changes: 47 additions & 17 deletions public/configs/v1/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-dev-2": {
Expand Down Expand Up @@ -300,7 +302,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-dev-4": {
Expand Down Expand Up @@ -330,7 +334,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-dev-5": {
Expand Down Expand Up @@ -359,7 +365,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-staging": {
Expand Down Expand Up @@ -389,7 +397,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-staging-forced-update": {
Expand Down Expand Up @@ -426,7 +436,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-staging-west": {
Expand Down Expand Up @@ -456,7 +468,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet": {
Expand Down Expand Up @@ -490,7 +504,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-dydx": {
Expand Down Expand Up @@ -519,7 +535,9 @@
"reduceOnlySupported": true,
"usePessimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-nodefleet": {
Expand Down Expand Up @@ -549,7 +567,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-kingnodes": {
Expand Down Expand Up @@ -578,7 +598,9 @@
"reduceOnlySupported": true,
"usePessimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-liquify": {
Expand Down Expand Up @@ -608,7 +630,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-polkachu": {
Expand Down Expand Up @@ -638,7 +662,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-testnet-bware": {
Expand Down Expand Up @@ -668,7 +694,9 @@
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
},
"dydxprotocol-mainnet": {
Expand All @@ -695,10 +723,12 @@
},
"featureFlags": {
"reduceOnlySupported": true,
"usePessimisticCollateralCheck": true,
"useOptimisticCollateralCheck": false,
"usePessimisticCollateralCheck": false,
"useOptimisticCollateralCheck": true,
"withdrawalSafetyEnabled": true,
"CCTPWithdrawalOnly": true
"CCTPWithdrawalOnly": true,
"isSlTpEnabled": true,
"isSlTpLimitOrdersEnabled": false
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useEnvFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface EnvironmentFeatures {
reduceOnlySupported: boolean;
withdrawalSafetyEnabled: boolean;
CCTPWithdrawalOnly: boolean;
isSlTpEnabled: boolean;
isSlTpLimitOrdersEnabled: boolean;
}

export const useEnvFeatures = (): EnvironmentFeatures => {
Expand Down
10 changes: 4 additions & 6 deletions src/lib/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import { IconName } from '@/components/Icon';
import { convertAbacusOrderSide } from '@/lib/abacus/conversions';
import { MustBigNumber } from '@/lib/numbers';

import { testFlags } from './testFlags';

export const getStatusIconInfo = ({
status,
totalFilled,
Expand Down Expand Up @@ -95,15 +93,15 @@ export const isLimitOrderType = (type?: AbacusOrderTypes) =>
({ ordinal }) => ordinal === type.ordinal
);

export const isStopLossOrder = (order: SubaccountOrder) => {
const validOrderTypes = testFlags.enableConditionalLimitOrders
export const isStopLossOrder = (order: SubaccountOrder, isSlTpLimitOrdersEnabled: boolean) => {
const validOrderTypes = isSlTpLimitOrdersEnabled
? [AbacusOrderType.stopLimit, AbacusOrderType.stopMarket]
: [AbacusOrderType.stopMarket];
return validOrderTypes.some(({ ordinal }) => ordinal === order.type.ordinal) && order.reduceOnly;
};

export const isTakeProfitOrder = (order: SubaccountOrder) => {
const validOrderTypes = testFlags.enableConditionalLimitOrders
export const isTakeProfitOrder = (order: SubaccountOrder, isSlTpLimitOrdersEnabled: boolean) => {
const validOrderTypes = isSlTpLimitOrdersEnabled
? [AbacusOrderType.takeProfitLimit, AbacusOrderType.takeProfitMarket]
: [AbacusOrderType.takeProfitMarket];
return validOrderTypes.some(({ ordinal }) => ordinal === order.type.ordinal) && order.reduceOnly;
Expand Down
8 changes: 0 additions & 8 deletions src/lib/testFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ class TestFlags {
return this.queryParams.address;
}

get configureSlTpFromPositionsTable() {
return !!this.queryParams.sltp;
}

get enableConditionalLimitOrders() {
return !!this.queryParams.sltplimit;
}

get isolatedMargin() {
return !!this.queryParams.isolatedmargin;
}
Expand Down
10 changes: 6 additions & 4 deletions src/state/accountCalculators.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createSelector } from 'reselect';

import { OnboardingState, OnboardingSteps } from '@/constants/account';
import { type DydxNetwork } from '@/constants/networks';
import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';

import {
getOnboardingGuards,
getOnboardingState,
getSubaccountId,
getUncommittedOrderClientIds,
} from '@/state/accountSelectors';

import { testFlags } from '@/lib/testFlags';
import { getSelectedNetwork } from '@/state/appSelectors';

export const calculateOnboardingStep = createSelector(
[getOnboardingState, getOnboardingGuards],
Expand Down Expand Up @@ -91,8 +92,9 @@ export const calculateIsAccountLoading = createSelector(
* @description calculate whether positions table should render triggers column
*/
export const calculateShouldRenderTriggersInPositionsTable = createSelector(
[calculateIsAccountViewOnly],
(isAccountViewOnly: boolean) => !isAccountViewOnly && testFlags.configureSlTpFromPositionsTable
[calculateIsAccountViewOnly, getSelectedNetwork],
(isAccountViewOnly: boolean, selectedNetwork: DydxNetwork) =>
!isAccountViewOnly && ENVIRONMENT_CONFIG_MAP[selectedNetwork].featureFlags.isSlTpEnabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

couldn't directly call useEnvFeatures() here due to a circular dep 🤔 Even when I tried directly importing the file, got build issues on vercel (but not locally). Given this is a temp flag, inclined to leave this like this for now rather than digging in further
Screenshot 2024-04-29 at 10 28 00 AM

);

/**
Expand Down
55 changes: 31 additions & 24 deletions src/state/accountSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,32 +179,39 @@ export const getMarketSubaccountOpenOrders = (
* @param state
* @returns list of conditional orders that have not been filled or cancelled for all subaccount positions
*/
export const getSubaccountConditionalOrders = createSelector(
[getMarketSubaccountOpenOrders, getOpenPositions],
(openOrdersByMarketId, positions) => {
const stopLossOrders: SubaccountOrder[] = [];
const takeProfitOrders: SubaccountOrder[] = [];

positions?.forEach((position) => {
const orderSideForConditionalOrder =
position?.side?.current === AbacusPositionSide.LONG
? AbacusOrderSide.sell
: AbacusOrderSide.buy;

const conditionalOrders = openOrdersByMarketId[position.id];

conditionalOrders?.forEach((order: SubaccountOrder) => {
if (order.side === orderSideForConditionalOrder && isStopLossOrder(order)) {
stopLossOrders.push(order);
} else if (order.side === orderSideForConditionalOrder && isTakeProfitOrder(order)) {
takeProfitOrders.push(order);
}
export const getSubaccountConditionalOrders = (isSlTpLimitOrdersEnabled: boolean) =>
createSelector(
[getMarketSubaccountOpenOrders, getOpenPositions],
(openOrdersByMarketId, positions) => {
const stopLossOrders: SubaccountOrder[] = [];
const takeProfitOrders: SubaccountOrder[] = [];

positions?.forEach((position) => {
const orderSideForConditionalOrder =
position?.side?.current === AbacusPositionSide.LONG
? AbacusOrderSide.sell
: AbacusOrderSide.buy;

const conditionalOrders = openOrdersByMarketId[position.id];

conditionalOrders?.forEach((order: SubaccountOrder) => {
if (
order.side === orderSideForConditionalOrder &&
isStopLossOrder(order, isSlTpLimitOrdersEnabled)
) {
stopLossOrders.push(order);
} else if (
order.side === orderSideForConditionalOrder &&
isTakeProfitOrder(order, isSlTpLimitOrdersEnabled)
) {
takeProfitOrders.push(order);
}
});
});
});

return { stopLossOrders, takeProfitOrders };
}
);
return { stopLossOrders, takeProfitOrders };
}
);

/**
* @param state
Expand Down
Loading
Loading