Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/handlers/get-unimind/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
reason: 'both_tokens_on_unimind_list'
}, 'Trade assigned to treatment group (both tokens on Unimind list)');
} else {
// Either one or both tokens NOT on list: apply sampling (2/3 Unimind, 1/3 control)
// Either one or both tokens NOT on list: apply sampling
if (!unimindTradeFilter(quoteMetadata.quoteId)) {
// Assigned to control group (1/3)
// Assigned to control group (Default parameters)
log.info({
quoteId: quoteMetadata.quoteId,
swapper,
Expand All @@ -93,7 +93,7 @@
}
}

// Assigned to treatment group (2/3)
// Assigned to treatment group (Unimind)
log.info({
quoteId: quoteMetadata.quoteId,
swapper,
Expand Down Expand Up @@ -231,7 +231,7 @@
}
}

export function calculateParameters(strategy: IUnimindAlgorithm<PriceImpactIntrinsicParameters>, unimindParameters: UnimindParameters, extrinsicValues: QuoteMetadata, log?: any): UnimindResponse {

Check warning on line 234 in lib/handlers/get-unimind/handler.ts

View workflow job for this annotation

GitHub Actions / lint-and-test

Unexpected any. Specify a different type
const intrinsicValues = JSON.parse(unimindParameters.intrinsicValues)

// Guardrail 1: Disallow negative lambda2 values
Expand Down
2 changes: 1 addition & 1 deletion lib/util/unimind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UnimindStatistics } from '../crons/unimind-algorithm'
import { QuoteMetadata } from '../repositories/quote-metadata-repository'
import { UnimindParameters } from '../repositories/unimind-parameters-repository'

export const UNIMIND_TRADE_SAMPLE_PERCENT = 66
export const UNIMIND_TRADE_SAMPLE_PERCENT = 100

export function unimindTradeFilter(quoteId: string): boolean {
// Hash the quoteId for deterministic, consistent sampling
Expand Down
24 changes: 19 additions & 5 deletions test/unit/handlers/get-unimind/get-unimind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { ChainId } from '@uniswap/sdk-core'
import { V4BaseActionsParser } from '@uniswap/v4-sdk'
import { UR_EXECUTE_WITH_DEADLINE_SELECTOR, UR_FUNCTION_SIGNATURES } from '../../../../lib/handlers/constants'
import { PriceImpactStrategy } from '../../../../lib/unimind/priceImpactStrategy'
import { unimindTradeFilter } from '../../../../lib/util/unimind'

jest.mock('../../../../lib/util/unimind', () => ({
...jest.requireActual('../../../../lib/util/unimind'),
unimindTradeFilter: jest.fn(),
}))

const SAMPLE_ROUTE = {
quote: "1234",
Expand Down Expand Up @@ -59,6 +65,8 @@ describe('Testing get unimind handler', () => {

beforeEach(() => {
jest.clearAllMocks()
const mockFilter = unimindTradeFilter as jest.Mock
mockFilter.mockReturnValue(true)
})

it('Testing correct request and response', async () => {
Expand Down Expand Up @@ -577,8 +585,10 @@ describe('Testing get unimind handler', () => {
const NOT_ON_LIST_PAIR = '0x0000000000000000000000000000000000000000-0x1111111111111111111111111111111111111111-123'

it('Both tokens on list → always uses Unimind (no sampling)', async () => {
const mockFilter = unimindTradeFilter as jest.Mock
mockFilter.mockReturnValue(false) // Should not matter - tokens on list bypass filter
const quoteMetadata = {
quoteId: 'test-on-list-quote', // Any quoteId should work for tokens on list
quoteId: 'test-quote-id',
pair: SAMPLE_SUPPORTED_UNIMIND_PAIR,
referencePrice: '4221.21',
priceImpact: 0.01,
Expand Down Expand Up @@ -631,9 +641,11 @@ describe('Testing get unimind handler', () => {
)
})

it('Not on list + passes filter (66%) → uses Unimind', async () => {
it('Not on list + passes filter → uses Unimind', async () => {
const mockFilter = unimindTradeFilter as jest.Mock
mockFilter.mockReturnValue(true)
const quoteMetadata = {
quoteId: 'test-quote-0', // This quoteId passes unimindTradeFilter
quoteId: 'test-quote-id',
pair: NOT_ON_LIST_PAIR,
referencePrice: '4221.21',
priceImpact: 0.01,
Expand Down Expand Up @@ -686,9 +698,11 @@ describe('Testing get unimind handler', () => {
)
})

it('Not on list + fails filter (34%) → uses PUBLIC_STATIC_PARAMETERS', async () => {
it('Not on list + fails filter → uses PUBLIC_STATIC_PARAMETERS', async () => {
const mockFilter = unimindTradeFilter as jest.Mock
mockFilter.mockReturnValue(false)
const quoteMetadata = {
quoteId: 'test-quote-fail-filter', // This should fail the filter
quoteId: 'test-quote-id',
pair: NOT_ON_LIST_PAIR,
referencePrice: '4221.21',
priceImpact: 0.01,
Expand Down
Loading