Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
4765f6e
transfer hook to public repo
bulkcade Jul 21, 2025
05fb086
tidy up
bulkcade Jul 21, 2025
ae1aeab
hook progress
bulkcade Jul 21, 2025
599ee2f
tidy up
bulkcade Jul 21, 2025
6a964de
multitoken progress
bulkcade Aug 4, 2025
266b508
initial storage access optimisation
bulkcade Aug 4, 2025
6567317
remove not longer used storage contract
bulkcade Aug 4, 2025
d401d37
latest iteration of multitoken with efficiency improvements
bulkcade Aug 4, 2025
f3a129e
add readme and test stubs
bulkcade Aug 4, 2025
577a99f
Merge branch 'E2E-upgrades' into hyperliquid-surge-hook
bulkcade Aug 4, 2025
43b6d39
Merge branch 'E2E-upgrades' into hyperliquid-surge-hook
bulkcade Aug 5, 2025
c2b3909
remove owner and add new fee ownership model
bulkcade Aug 5, 2025
d6e0915
port over initial changes for new hooks and stack too deep refactorings
bulkcade Aug 5, 2025
3d94075
refactor for efficiency
bulkcade Aug 5, 2025
623efd1
add more event logging for new hooks
bulkcade Aug 5, 2025
67e085a
interface progress
bulkcade Aug 5, 2025
a37ab25
add a new deviation cap for greater flexibility
bulkcade Aug 5, 2025
ee0d367
interface
bulkcade Aug 5, 2025
b3819f4
latest md
bulkcade Aug 5, 2025
c17f12b
progress with tests and redoing the readme
bulkcade Aug 6, 2025
28eaa80
bidirectional fees and test changes for that
bulkcade Aug 11, 2025
e426364
formatting
bulkcade Aug 12, 2025
e7d42d0
strip usd logic
bulkcade Aug 12, 2025
576db56
refactor fee calc into a pure function
bulkcade Aug 12, 2025
90720f5
interfaces and formatting
bulkcade Aug 12, 2025
b2176e7
change fee logic to be deviation based
bulkcade Aug 12, 2025
cd3b9cc
bugfix
bulkcade Aug 12, 2025
1bbd43e
changes to how defaults are constructed some formatting changes, test…
bulkcade Aug 12, 2025
98b88d8
test progress
bulkcade Aug 13, 2025
b026892
formatting and test changes
bulkcade Aug 14, 2025
e71e621
fix to admin
bulkcade Aug 14, 2025
f641f73
fix tests
bulkcade Aug 14, 2025
0fcdacb
Merge remote-tracking branch 'origin/main' into hyperliquid-surge-hook
bulkcade Aug 14, 2025
e41ea91
remove out.txt
bulkcade Aug 14, 2025
d9400b6
onAfter are view functions
bulkcade Aug 14, 2025
aa850f7
some tidy up with vault mocks and view overide
bulkcade Aug 14, 2025
963a78f
reinstate bad removal of length setting
bulkcade Aug 14, 2025
8b39d13
remove unused event
bulkcade Aug 14, 2025
2dfe95b
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
6c11d51
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
67d56ef
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
eafee32
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
789bf57
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
f906209
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
f91ac91
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
85c2774
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
67cc523
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
a6fe14a
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
a906259
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
fc483e7
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
32329f7
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
9d0c5fc
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
946db11
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 14, 2025
25b0f42
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 15, 2025
6e3cda4
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 15, 2025
63b78b4
reinstate public
bulkcade Aug 15, 2025
b65aa3c
remove readme
bulkcade Aug 15, 2025
640ee3b
Update pkg/pool-hooks/contracts/hooks-quantamm/HyperSurgeHook.sol
bulkcade Aug 18, 2025
38b9292
PR changes progress
bulkcade Aug 18, 2025
53aa601
standardisee naming
bulkcade Aug 18, 2025
2c37c7e
prettier solidity formatting
bulkcade Aug 18, 2025
faefa0f
comment tidy up
bulkcade Aug 18, 2025
1166107
change to token Id
bulkcade Aug 18, 2025
c266df5
use standalone utils token info struct
bulkcade Aug 19, 2025
bec260d
new deviation before and tests
bulkcade Aug 20, 2025
22ac103
new tests
bulkcade Aug 20, 2025
d099691
readme
bulkcade Aug 21, 2025
ce03896
licence
bulkcade Aug 25, 2025
4df355c
some more readme detail
bulkcade Aug 26, 2025
0210e29
slither and code coverage changes and tests
bulkcade Aug 30, 2025
245becb
getnumtoken test
bulkcade Aug 30, 2025
4503945
additional tests
bulkcade Sep 1, 2025
369d387
formatting
bulkcade Sep 1, 2025
38a80be
change for shared precompile to throw on price 0 and tests
bulkcade Sep 2, 2025
2bd7d89
clean up and corrections given 0 price revert change
bulkcade Sep 2, 2025
fd59f58
remove paths not possible anymore, add test coverage
bulkcade Sep 2, 2025
2d1e9bf
verify the very defensive 0 check with a test
bulkcade Sep 2, 2025
42d7159
restore toml
bulkcade Sep 2, 2025
33c3d02
Lint
joaobrunoah Sep 11, 2025
51a467d
Fix tests with forge using contracts compiled with hardhat
joaobrunoah Sep 12, 2025
90caadc
Fix percentage setters
joaobrunoah Sep 12, 2025
955a3dc
Fix setters
joaobrunoah Sep 12, 2025
c1aeb77
Remove unnecessary structs for Add/Remove liquidity hooks
joaobrunoah Sep 12, 2025
dba482a
Improve function names
joaobrunoah Sep 12, 2025
1a69991
Refactor computeSurgeFee to remove locals struct
joaobrunoah Sep 12, 2025
2a7f724
Fix stack-too-deep
joaobrunoah Sep 13, 2025
78b058d
Fix tests - WIP
joaobrunoah Sep 13, 2025
d149b2c
Fix tests - WIP
joaobrunoah Sep 13, 2025
d9a181b
Fix test - WIP
joaobrunoah Sep 15, 2025
4b03180
Fix tests - WIP
joaobrunoah Sep 15, 2025
2aec7a9
Fix tests - WIP
joaobrunoah Sep 15, 2025
143d095
Fix tests - WIP
joaobrunoah Sep 15, 2025
3b65432
Fix tests - WIP
joaobrunoah Sep 15, 2025
998acef
Fix HyperSurgeFee tests
joaobrunoah Sep 15, 2025
4278aed
Clean test file
joaobrunoah Sep 15, 2025
5ce5a52
Fix tests
joaobrunoah Sep 16, 2025
25eb6bf
Fix stack-too-deep
joaobrunoah Sep 16, 2025
d43a44a
Fix stack-too-deep
joaobrunoah Sep 16, 2025
124b896
Fix test
joaobrunoah Sep 16, 2025
a20dbc4
Fix HyperSurgeMaxDeviation file
joaobrunoah Sep 16, 2025
18121e7
Fix test
joaobrunoah Sep 16, 2025
ae9110a
Remove check of token length (it's already checked in the vault)
joaobrunoah Sep 16, 2025
adebde4
Remove unnecessary struct
joaobrunoah Sep 16, 2025
4de2a3e
Fix function comments
joaobrunoah Sep 16, 2025
076677a
Fix PR comments
joaobrunoah Sep 16, 2025
d484ddc
Fix natspec
joaobrunoah Sep 16, 2025
4d5b999
Merge pull request #64 from QuantAMMProtocol/hyperliquid-surge-hook
bulkcade Sep 22, 2025
82e410c
Merge pull request #65 from joaobrunoah/hyperliquid-surge-hook-review
bulkcade Sep 22, 2025
da20768
Merge pull request #66 from QuantAMMProtocol/hyperliquid-surge-hook
bulkcade Sep 22, 2025
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
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"options": {
"singleQuote": false,
"tabWidth": 4,
"compiler": "0.8.24"
"compiler": "0.8.26"
}
},
{
Expand Down
208 changes: 208 additions & 0 deletions pkg/interfaces/contracts/pool-hooks/IHyperSurgeHook.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

/**
* @title IHyperSurgeHook
* @notice Interface for the Hyper Surge hook: oracle-deviation surge fees and
* per-token external price configuration by pool token index.
*
* @dev
* - This interface exposes Hyper-specific configuration and read APIs.
* - Vault callback methods (e.g., onComputeDynamicSwapFeePercentage, onAfterAddLiquidity,
* onAfterRemoveLiquidity, getHookFlags, onRegister) are defined elsewhere (IHooks)
* and are intentionally not duplicated here.
*/
interface IHyperSurgeHook {
enum TradeType {
ARBITRAGE,
NOISE
}

// -------------------------------------------------------------------------
// Events
// -------------------------------------------------------------------------

/**
* @notice Emitted when a pool is registered/initialized with this hook.
* @param pool Pool address
* @param numTokens Number of tokens in the pool (2..8)
*/
event PoolRegistered(address indexed pool, uint8 numTokens);

/**
* @notice Emitted when a token's external price configuration is set by token index.
* @param pool Pool address being configured
* @param tokenIndex Token index within the pool (0-based)
* @param hlPairIndex Hyperliquid pair/market index
* @param hlTokenIndex Hyperliquid token index
* @param szDecimals Hyperliquid size-decimals for that pair
*/
event TokenPriceConfiguredIndex(
address indexed pool,
uint8 indexed tokenIndex,
uint32 hlPairIndex,
uint32 hlTokenIndex,
uint8 szDecimals
);

/**
* @notice Emitted when the per-pool maximum surge fee percentage is changed.
* @dev 1e18-scaled (e.g., 1e17 = 10%).
* @param sender address of the sender
* @param pool Pool address
* @param pct New max surge fee percentage (1e18 scale)
* @param tradeType which direction the fee should be charged in
*/
event MaxSurgeFeePercentageChanged(address indexed sender, address indexed pool, uint256 pct, TradeType tradeType);

/**
* @notice Emitted when the per-pool surge threshold percentage is changed.
* @dev 1e18-scaled (e.g., 5e16 = 5%).
* @param sender address of the sender
* @param pool Pool address
* @param pct New threshold percentage (1e18 scale)
* @param tradeType which direction the fee should be charged in
*/
event ThresholdPercentageChanged(address indexed sender, address indexed pool, uint256 pct, TradeType tradeType);

/***
* @notice Emitted when the per pool cap deviation is changed
* @param sender address of the sender
* @param pool address of the pool
* @param pct the fee in pct 1e18 scale
* @param tradeType which direction the fee should be charged in
*/
event CapDeviationPercentageChanged(address indexed sender, address indexed pool, uint256 pct, TradeType tradeType);

/**
* @notice Configure a single token’s external price mapping by token index for a given pool.
* @param tokenIndex balancer pools index of the token
* @param hlPairIdx the index of the pair being set from hl
* @param hlTokenIdx the index of the token being set from hl
*/
function setTokenPriceConfigIndex(
address pool,
uint8 tokenIndex,
uint32 hlPairIdx,
uint32 hlTokenIdx
) external;

/**
* @notice Batch configure multiple tokens’ external price mapping by token index for a given pool.
* @param pool The pool address to configure.
* @param tokenIndices The balancer indices of the tokens to configure (0..7).
* @param hlPairIdx The indices of the pairs being set from hl.
* @param hlTokenIdx The indices of the tokens being set from hl.
*/
function setTokenPriceConfigBatchIndex(
address pool,
uint8[] calldata tokenIndices,
uint32[] calldata hlPairIdx,
uint32[] calldata hlTokenIdx
) external;

/**
* @notice Set the per-pool maximum surge fee percentage (cap).
* @param pool Pool address
* @param pct18 New maximum surge fee percentage (1e18 scale)
*/
function setMaxSurgeFeePercentage(address pool, uint256 pct18, TradeType tradeType) external;

/**
* @notice Set the per-pool surge threshold percentage (deviation level at which fees start ramping).
* @param pool Pool address
* @param pct18 New threshold percentage (1e18 scale)
*/
function setSurgeThresholdPercentage(address pool, uint256 pct18, TradeType tradeType) external;

/**
@notice sets the deviation where the max fee kicks in
@param pool address of the pool
@param capDevPct18 the deviation to set the cap to in %
*/
function setCapDeviationPercentage(address pool, uint256 capDevPct18, TradeType tradeType) external;

// -------------------------------------------------------------------------
// Getters (read-only)
// -------------------------------------------------------------------------

/**
* @notice Current per-pool surge threshold percentage (1e18 = 100%).
* @param pool Pool address
* @return pct The surge threshold percentage (1e18 = 100%).
*/
function getSurgeThresholdPercentage(address pool, TradeType tradeType) external view returns (uint256);

/**
* @notice Current per-pool maximum surge fee percentage (1e18 = 100%).
* @param pool Pool address
* @return pct The maximum surge fee percentage (1e18 = 100%).
*/
function getMaxSurgeFeePercentage(address pool, TradeType tradeType) external view returns (uint256);

/**
* @notice Default cap deviation percentage used for new pools (1e18 = 100%).
* @param pool Pool address
* @return capDevPct The cap deviation percentage (1e18 = 100%)
*/
function getCapDeviationPercentage(address pool, TradeType tradeType) external view returns (uint256);

/**
* @notice Number of tokens configured for the pool (2..8).
* @param pool Pool address
* @return numTokens Number of tokens in the pool (2..8)
*/
function getNumTokens(address pool) external view returns (uint8);

/**
* @notice Read the token price configuration for a specific token index.
* @param pool Pool address
* @param tokenIndex Token index (0-based)
* @return pairIndex Hyperliquid market/pair index (0 if USD-quoted)
* @return priceDivisor Precomputed divisor used to scale Hyperliquid spot into 1e18
*/
function getTokenPriceConfigIndex(
address pool,
uint8 tokenIndex
)
external
view
returns (
uint32 pairIndex,
uint32 priceDivisor
);

/**
* @notice Read all token price configurations for a pool (length = numTokens).
* @dev Arrays are aligned by index; entry i corresponds to token index i.
* @return pairIndexArr Array of Hyperliquid pair indices (0 if USD-quoted)
* @return priceDivisorArr Array of price divisors for scaling spot into 1e18
*/
function getTokenPriceConfigs(
address pool
)
external
view
returns (
uint32[] memory pairIndexArr,
uint32[] memory priceDivisorArr
);

/**
* @notice Default max surge fee percentage used for new pools (1e18 = 100%).
* @return pct The default max surge fee percentage (1e18 = 100%)
*/
function getDefaultMaxSurgeFeePercentage() external view returns (uint256 pct);

/**
* @notice Default surge threshold percentage used for new pools (1e18 = 100%).
* @return pct The default surge threshold percentage (1e18 = 100%)
*/
function getDefaultSurgeThresholdPercentage() external view returns (uint256 pct);

/**
* @notice Default cap deviation percentage used for new pools (1e18 = 100%).
* @return pct The default cap deviation percentage (1e18 = 100%)
*/
function getDefaultCapDeviationPercentage() external view returns (uint256 pct);
}
Loading
Loading