-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from balancer/hook-support-afterRemove
Hook support after remove
- Loading branch information
Showing
13 changed files
with
590 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { HookBase } from './types'; | ||
|
||
export const defaultHook: HookBase = { | ||
shouldCallComputeDynamicSwapFee: false, | ||
shouldCallBeforeSwap: false, | ||
shouldCallAfterSwap: false, | ||
shouldCallBeforeAddLiquidity: false, | ||
shouldCallAfterAddLiquidity: false, | ||
shouldCallBeforeRemoveLiquidity: false, | ||
shouldCallAfterRemoveLiquidity: false, | ||
enableHookAdjustedAmounts: false, | ||
onBeforeAddLiquidity: () => { | ||
return false; | ||
}, | ||
onAfterAddLiquidity: () => { | ||
return { success: false, hookAdjustedAmountsInRaw: [] }; | ||
}, | ||
onBeforeRemoveLiquidity: () => { | ||
return false; | ||
}, | ||
onAfterRemoveLiquidity: () => { | ||
return { success: false, hookAdjustedAmountsOutRaw: [] }; | ||
}, | ||
onBeforeSwap: () => { | ||
return false; | ||
}, | ||
onAfterSwap: () => { | ||
return { success: false, hookAdjustedAmountCalculatedRaw: 0n }; | ||
}, | ||
onComputeDynamicSwapFee: () => { | ||
return { success: false, dynamicSwapFee: 0n }; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type HookStateExitFee = { | ||
removeLiquidityHookFeePercentage: bigint; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { AddKind, RemoveKind, SwapInput, SwapKind } from '@/vault/types'; | ||
import { HookStateExitFee } from './exitFeeHook'; | ||
|
||
export type HookState = HookStateExitFee; | ||
|
||
export type AfterSwapParams = { | ||
kind: SwapKind; | ||
tokenIn: string; | ||
tokenOut: string; | ||
amountInScaled18: bigint; | ||
amountOutScaled18: bigint; | ||
tokenInBalanceScaled18: bigint; | ||
tokenOutBalanceScaled18: bigint; | ||
amountCalculatedScaled18: bigint; | ||
amountCalculatedRaw: bigint; | ||
router: string; | ||
pool: string; | ||
}; | ||
|
||
export interface HookBase { | ||
shouldCallComputeDynamicSwapFee: boolean; | ||
shouldCallBeforeSwap: boolean; | ||
shouldCallAfterSwap: boolean; | ||
shouldCallBeforeAddLiquidity: boolean; | ||
shouldCallAfterAddLiquidity: boolean; | ||
shouldCallBeforeRemoveLiquidity: boolean; | ||
shouldCallAfterRemoveLiquidity: boolean; | ||
enableHookAdjustedAmounts: boolean; | ||
|
||
onBeforeAddLiquidity( | ||
router: string, | ||
pool: string, | ||
kind: AddKind, | ||
maxAmountsInScaled18: bigint[], | ||
minBptAmountOut: bigint, | ||
balancesScaled18: bigint[], | ||
): boolean; | ||
onAfterAddLiquidity( | ||
router: string, | ||
pool: string, | ||
kind: AddKind, | ||
amountsInScaled18: bigint[], | ||
amountsInRaw: bigint[], | ||
bptAmountOut: bigint, | ||
balancesScaled18: bigint[], | ||
): { success: boolean; hookAdjustedAmountsInRaw: bigint[] }; | ||
onBeforeRemoveLiquidity( | ||
router: string, | ||
pool: string, | ||
kind: RemoveKind, | ||
maxBptAmountIn: bigint, | ||
minAmountsOutScaled18: bigint[], | ||
balancesScaled18: bigint[], | ||
): boolean; | ||
onAfterRemoveLiquidity( | ||
kind: RemoveKind, | ||
bptAmountIn: bigint, | ||
amountsOutScaled18: bigint[], | ||
amountsOutRaw: bigint[], | ||
balancesScaled18: bigint[], | ||
hookState: HookState | unknown, | ||
): { success: boolean; hookAdjustedAmountsOutRaw: bigint[] }; | ||
onBeforeSwap(params: SwapInput, poolAddress: string): boolean; | ||
onAfterSwap(params: AfterSwapParams): { | ||
success: boolean; | ||
hookAdjustedAmountCalculatedRaw: bigint; | ||
}; | ||
onComputeDynamicSwapFee( | ||
params: SwapInput, | ||
poolAddress: string, | ||
staticSwapFeePercentage: bigint, | ||
): { success: boolean; dynamicSwapFee: bigint }; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type HookClassConstructor = new (..._args: any[]) => HookBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,9 @@ | ||
import { PoolState } from '@/vault/types'; | ||
|
||
type PoolType = 'Stable'; | ||
|
||
export type StableMutable = { | ||
swapFee: bigint; | ||
balancesLiveScaled18: bigint[]; | ||
tokenRates: bigint[]; | ||
totalSupply: bigint; | ||
amp: bigint; | ||
}; | ||
|
||
export type StableImmutable = { | ||
tokens: string[]; | ||
scalingFactors: bigint[]; | ||
}; | ||
|
||
export type StableState = { poolType: PoolType } & StableImmutable & | ||
StableMutable; | ||
export type StableState = PoolState & { poolType: PoolType } & StableMutable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.