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

SOR - Update StableSurge hook support #1582

Merged
merged 8 commits into from
Feb 11, 2025
Merged

Conversation

brunoguerios
Copy link
Member

Close #1478

Copy link

changeset-bot bot commented Feb 7, 2025

🦋 Changeset detected

Latest commit: 7d26630

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
backend Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -38,7 +38,7 @@ export const syncHookData = async (
// Get hooks data
const data = await fetchHookData(viemClient, hookData.address, hookType, pool.address);

const name = `${hookType.charAt(0).toUpperCase()}${hookType.slice(1)}`;
const name = `${hookType.charAt(0).toUpperCase()}${hookType.slice(1, -4)}`;
Copy link
Member Author

@brunoguerios brunoguerios Feb 7, 2025

Choose a reason for hiding this comment

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

Concrete example:

  • Hook name on API -> StableSurgeHook
  • Hook name as balancer maths expect -> StableSurge

As mentioned on slack - I'd like feedback on this change.
Is it ok to update hook names to remove Hook suffix on DB?
Or should I move that workaround to inside SOR logic?

@@ -107,6 +107,7 @@ export function getHookState(pool: any): HookState | undefined {
amp: parseUnits(pool.typeData.amp, 3),
// 18 decimal precision.
surgeThresholdPercentage: parseEther(pool.hook.dynamicData.surgeThresholdPercentage),
maxSurgeFeePercentage: parseEther(pool.hook.dynamicData.maxSurgeFeePercentage),
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this was added at a later stage and was not initially part of the contracts. Was added in maths here: balancer/balancer-maths@eeff3ef.

@@ -32,6 +32,13 @@ export async function sorGetPathsWithPools(
const basePools: BasePool[] = [];

for (const prismaPool of prismaPools) {
// typeguard
if (prismaPool.protocolVersion === 3) {
if (!isLiquidityManagement(prismaPool.liquidityManagement)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving the typeguard here seems to be more elegant as it just does not consider the pool for route building and simply continues.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the main problem was that it was throwing an error if LiquidityManagement wasn't properly set.
This means that the whole SOR will break with a single corrupted pool in the DB.
Moving here allows us to simply skip that pool and later investigate why it doesn't have that attribute properly set

useProtocolVersion,
// poolIds: ['0x10a04efba5b880e169920fd4348527c64fb29d4d'], // boosted
poolIds: ['0x9b677c72a1160e1e03fe542bfd2b0f373fa94a8c'], // boosted
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a pool with StableSurge.

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 usually add this when I want to make an isolated test.
Removing this will open the SOR to build paths with all Sepolia pools and since some were not properly balanced, results were a bit off.

…e-surge

# Conflicts:
#	modules/actions/pool/v3/sync-hook-data.ts
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, will leave Franz to give any final opinions/requests on naming.

@brunoguerios
Copy link
Member Author

I pushed an update that handles the recently added hook type instead of having to parse hook name.

Copy link
Contributor

@mkflow27 mkflow27 left a comment

Choose a reason for hiding this comment

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

lgtm, will leave it for franz to give final opinions

@@ -77,41 +79,53 @@ export function getOutputAmount(paths: PathWithAmount[]): TokenAmount {
return amounts.reduce((a, b) => a.add(b));
}

export function getHookState(pool: any): HookState | undefined {
if (pool.hook === undefined || pool.hook === null) {
export function getHookState(pool: PrismaPoolAndHookWithDynamic): HookState | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great change. I recall running into build issues when trying it. But it seems like back then I was not aware of the existing HookData type, which would have allowed me to assign the pool the PrismaPoolAndHookWithDynamic type (but still stick to using the name). The recently added GqlHookType by franz is a great addition.

tokens: pool.tokens.map((token: { address: string }) => token.address),
// ExitFeeHook will always have dynamicData as part of the API response
removeLiquidityHookFeePercentage: parseEther(dynamicData.removeLiquidityFeePercentage),
hookType: 'ExitFee',
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about hard coding the hookType back then as well. What would be the advantage of hardcoding it here compared to forwarding the hookData.name?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just FYI, hook.name is being deprecated in the favor of hookType

Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need this new hookType that is returned here for the Balancer maths repo?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's how Balancer Maths knows which hook is being used. This is the mapper I said I'd add to decouple hook type from API vs hook type from balancer maths.

Copy link
Member Author

Choose a reason for hiding this comment

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

Answering @mkflow27 - the advantage of rewriting the hook type here instead of forwarding is that we decouple how they are declared in the api vs in Balancer Maths. If we simply forwarded what was specified in the api, we add the overhead of having to sync and reach consensus on how each hook type is handled in both codebases.
Since we always need to add code to support new hook types on the SOR, adding another attribute is trivial.

@franzns franzns merged commit 67cbe5a into v3-canary Feb 11, 2025
1 check passed
@franzns franzns deleted the sor-update-stable-surge branch February 11, 2025 13:36
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.

SOR - Add support for StableSurge hook
5 participants