Skip to content

Commit

Permalink
feat(earn): Add earn_supported_pools dynamic config (#6112)
Browse files Browse the repository at this point in the history
### Description

and use in getEarnPositions query. Opted to have the default be the
empty list and have the legacy default live in hooks
([here](valora-inc/hooks#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)
  • Loading branch information
finnian0826 authored Oct 1, 2024
1 parent ec1fbf8 commit 04bb249
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/positions/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand Down
12 changes: 10 additions & 2 deletions src/positions/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 } }

Expand Down
7 changes: 7 additions & 0 deletions src/statsig/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/statsig/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 04bb249

Please sign in to comment.