Skip to content

Conversation

@brunoguerios
Copy link
Member

@brunoguerios brunoguerios commented Dec 3, 2025

Closes #134

@brunoguerios brunoguerios self-assigned this Dec 3, 2025
Comment on lines +209 to +213
rate_rounded_up = _compute_rate_round_up(token_rates[index_out])
amount_given_scaled_18 = _to_scaled_18_apply_rate_round_up(
amount_given_raw,
scaling_factors[index_out],
token_rates[index_out],
rate_rounded_up,
Copy link
Member Author

Choose a reason for hiding this comment

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

New tests highlighted some math issues that I decided to fix within this PR - this is one example.

),
pool_state=cast(PoolState, map_pool_state(pool_with_ints)),
pool_state=cast(PoolState, pool_state),
hook_state=hook_state,
Copy link
Member Author

Choose a reason for hiding this comment

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

Hook state was not being taken into account - this is now fixed on all implementations (python, rust and TS)

Comment on lines 4 to 27
export const HOOK_CONFIG: Record<number, Record<string, HookType>> = {
// Sepolia
11155111: {
'0xbb1761af481364a6bd7fdbdb8cfa23abd85f0263': 'FEE_TAKING',
'0xea672a54f0aa38fc5f0a1a481467bebfe3c71046': 'EXIT_FEE',
'0x1adc55adb4caae71abb4c33f606493f4114d2091': 'STABLE_SURGE',
'0xc0cbcdd6b823a4f22aa6bbdde44c17e754266aef': 'STABLE_SURGE',
'0x30ce53fa38a1399f0ca158b5c38362c80e423ba9': 'STABLE_SURGE',
'0x18b10fe9ec4815c31c4ab04fa6f91dce0695132f': 'MEV_TAX',
'0xec9578e79d412537095501584284b092d2f6b9f7': 'MEV_TAX',
},
// Base
8453: {
'0xb2007b8b7e0260042517f635cfd8e6dd2dd7f007': 'STABLE_SURGE',
'0xdb8d758bcb971e482b2c45f7f8a7740283a1bd3a': 'STABLE_SURGE',
'0x7a2535f5fb47b8e44c02ef5d9990588313fe8f05': 'MEV_TAX',
},
// Mainnet
1: {
'0xb18fa0cb5de8cecb8899aae6e38b1b7ed77885da': 'STABLE_SURGE',
'0xbdbadc891bb95dee80ebc491699228ef0f7d6ff1': 'STABLE_SURGE',
'0x1bca39b01f451b0a05d7030e6e6981a73b716b1c': 'MEV_TAX',
},
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Addresses like these are usually stored within the SDK, but not sure if we should move it there. I'm keeping it here for simplicity for now.
Currently these addresses are duplicated here and in the backend repo.
If we decide that at some point it's interesting to have a single source of truth for them, we can move them around.

Copy link
Member

Choose a reason for hiding this comment

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

I think its fine to keep here for now.

Comment on lines +91 to +93
"balancesLiveScaled18": [
"311845355307990821859",
"409096377821670037730"
Copy link
Member Author

Choose a reason for hiding this comment

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

There is one integration test failing on all implementations where the root cause is that getCurrentLiveBalances applies a round down to calculate live amounts, while add liquidity flow applies a round up.
This leads to a off-by-1 error that is not related to maths, but rather a diff between the getter and the implementation for add liquidity.
We could fetch raw balances and attempt to calculate live balances, but that isn't straightforward and it would have a rather significant impact in complexity, required inputs (e.g. yieldFee), etc..
Sharing it here so we can discuss on how to move forward.
I'd say that for most usage, this off-by-1 error in the comparison between on-chain and off-chain is negligible, but it's open for discussion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Juani said this is not an issue for his use case, so I'd say we should accept the off-by-1 error and leave as is. I'll relax the test assertion

Copy link
Member

Choose a reason for hiding this comment

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

Cool. Can you make sure to comment with that info in the test please.

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✅

Copy link
Member

Choose a reason for hiding this comment

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

Seems like this is only used as part of testing? If that's the case would probably be better placed in the test/utils? (Same for other languages too I think).

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✅

Copy link
Member

Choose a reason for hiding this comment

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

Is rust missing the hook mapping?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll extract to a helper file. It's currently implemented within read_test_data.

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✅

import type { Address } from 'viem';
import type { HookType } from './types';

export const HOOK_CONFIG: Record<number, Record<string, HookType>> = {
Copy link
Member

Choose a reason for hiding this comment

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

What about changing it to Record<Address, HookType> to avoid mistakes?

Copy link
Member Author

Choose a reason for hiding this comment

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

done ✅

@@ -0,0 +1,19 @@
import type { Address } from 'viem';

export type HookType = 'FEE_TAKING' | 'EXIT_FEE' | 'STABLE_SURGE' | 'MEV_TAX' | 'UNKNOWN';
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to hooks/config.ts? Thinking about the process of adding new hooks it would make it easier to remember what to add where.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done ✅

Copy link
Member

@johngrantuk johngrantuk left a comment

Choose a reason for hiding this comment

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

Few small changes requested but LGTM. Would be good to get tests passing before releasing.

Copy link
Member

@johngrantuk johngrantuk left a comment

Choose a reason for hiding this comment

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

LGTM!

@brunoguerios brunoguerios merged commit e6b31dc into main Dec 15, 2025
3 checks passed
@brunoguerios brunoguerios deleted the hook-test-data branch December 15, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hooks support to integrations tests

3 participants