From 04bb2498046cfe38d4bd9532bbc4d028fcef8c8c Mon Sep 17 00:00:00 2001 From: Finnian Jacobson-Schulte <140328381+finnian0826@users.noreply.github.com> Date: Wed, 2 Oct 2024 05:26:16 +1300 Subject: [PATCH] feat(earn): Add earn_supported_pools dynamic config (#6112) ### Description and use in getEarnPositions query. Opted to have the default be the empty list and have the legacy default live in hooks ([here](https://github.com/valora-inc/hooks/pull/598)). That way if we need to change the legacy default we can and there won't be BC issues in the wallet (can just change on hooks side without release, goes to all versions). Dynamic config: https://console.statsig.com/4plizaPmWwPL21ASV4QAO0/dynamic_configs/supported_earn_pools ### Test plan CI ### Related issues - Fixes ACT-1367 ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [X] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --- src/positions/saga.test.ts | 10 +++++++++- src/positions/saga.ts | 12 ++++++++++-- src/statsig/constants.ts | 7 +++++++ src/statsig/types.ts | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/positions/saga.test.ts b/src/positions/saga.test.ts index b5026896a3..8a978da9f4 100644 --- a/src/positions/saga.test.ts +++ b/src/positions/saga.test.ts @@ -40,7 +40,7 @@ import { triggerShortcutSuccess, } from 'src/positions/slice' import { Position } from 'src/positions/types' -import { getFeatureGate, getMultichainFeatures } from 'src/statsig' +import { getDynamicConfigParams, getFeatureGate, getMultichainFeatures } from 'src/statsig' import { NetworkId } from 'src/transactions/types' import Logger from 'src/utils/Logger' import { sendPreparedTransactions } from 'src/viem/saga' @@ -137,6 +137,10 @@ describe(fetchPositionsSaga, () => { jest.mocked(getMultichainFeatures).mockReturnValue({ showPositions: [NetworkId['celo-mainnet']], }) + jest.mocked(getDynamicConfigParams).mockReturnValue({ + supportedPools: ['arbitrum-sepolia:0x460b97bd498e1157530aeb3086301d5225b91216'], + supportedAppIds: ['aave'], + }) await expectSaga(fetchPositionsSaga) .provide([ [select(walletAddressSelector), mockAccount], @@ -161,6 +165,10 @@ describe(fetchPositionsSaga, () => { jest.mocked(getMultichainFeatures).mockReturnValue({ showPositions: [NetworkId['celo-mainnet']], }) + jest.mocked(getDynamicConfigParams).mockReturnValue({ + supportedPools: ['arbitrum-sepolia:0x460b97bd498e1157530aeb3086301d5225b91216'], + supportedAppIds: ['aave'], + }) await expectSaga(fetchPositionsSaga) .provide([ [select(walletAddressSelector), mockAccount], diff --git a/src/positions/saga.ts b/src/positions/saga.ts index 06b6e1b32c..a060e9b76b 100644 --- a/src/positions/saga.ts +++ b/src/positions/saga.ts @@ -36,8 +36,9 @@ import { import { Position, Shortcut } from 'src/positions/types' import { SentryTransactionHub } from 'src/sentry/SentryTransactionHub' import { SentryTransaction } from 'src/sentry/SentryTransactions' -import { getFeatureGate, getMultichainFeatures } from 'src/statsig' -import { StatsigFeatureGates } from 'src/statsig/types' +import { getDynamicConfigParams, getFeatureGate, getMultichainFeatures } from 'src/statsig' +import { DynamicConfigs } from 'src/statsig/constants' +import { StatsigDynamicConfigs, StatsigFeatureGates } from 'src/statsig/types' import { fetchTokenBalances } from 'src/tokens/slice' import Logger from 'src/utils/Logger' import { ensureError } from 'src/utils/ensureError' @@ -90,9 +91,16 @@ async function fetchPositions({ networkIds.forEach((networkId) => getPositionsUrl.searchParams.append('networkIds', networkId)) const getEarnPositionsUrl = getHooksApiFunctionUrl(hooksApiUrl, 'getEarnPositions') + const { supportedPools, supportedAppIds } = getDynamicConfigParams( + DynamicConfigs[StatsigDynamicConfigs.EARN_CONFIG] + ) networkIds.forEach((networkId) => getEarnPositionsUrl.searchParams.append('networkIds', networkId) ) + supportedPools.forEach((pool) => getEarnPositionsUrl.searchParams.append('supportedPools', pool)) + supportedAppIds.forEach((appId) => + getEarnPositionsUrl.searchParams.append('supportedAppIds', appId) + ) const options: RequestInit = { headers: { 'Accept-Language': language } } diff --git a/src/statsig/constants.ts b/src/statsig/constants.ts index d5d40d0c2d..03450b971a 100644 --- a/src/statsig/constants.ts +++ b/src/statsig/constants.ts @@ -127,6 +127,13 @@ export const DynamicConfigs = { }, }, }, + [StatsigDynamicConfigs.EARN_CONFIG]: { + configName: StatsigDynamicConfigs.EARN_CONFIG, + defaultValues: { + supportedPools: [] as string[], + supportedAppIds: [] as string[], + }, + }, } satisfies { [key in StatsigDynamicConfigs | StatsigMultiNetworkDynamicConfig]: { configName: key diff --git a/src/statsig/types.ts b/src/statsig/types.ts index b85df089a0..ef254ac271 100644 --- a/src/statsig/types.ts +++ b/src/statsig/types.ts @@ -8,6 +8,7 @@ export enum StatsigDynamicConfigs { NFT_CELEBRATION_CONFIG = 'nft_celebration_config', EARN_STABLECOIN_CONFIG = 'earn_stablecoin_config', APP_CONFIG = 'app_config', + EARN_CONFIG = 'earn_config', } // Separating into different enum from StatsigDynamicConfigs to allow for more strict typing