diff --git a/subgraphs/v3-pools/abis/HyperSurgeHook.json b/subgraphs/v3-pools/abis/HyperSurgeHook.json new file mode 100644 index 0000000..bebad3a --- /dev/null +++ b/subgraphs/v3-pools/abis/HyperSurgeHook.json @@ -0,0 +1,1280 @@ +[ + { + "inputs": [ + { + "internalType": "contract IVault", + "name": "vault", + "type": "address" + }, + { + "internalType": "uint256", + "name": "defaultMaxSurgeFeePercentage18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "defaultThresholdPercentage18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "defaultCapDeviationPercentage18", + "type": "uint256" + }, + { + "internalType": "string", + "name": "version", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "InvalidArrayLengths", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidCapDeviationPercentage", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidDecimals", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidPairIndex", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidPercentage", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidSurgeFeePercentage", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidThresholdDeviation", + "type": "error" + }, + { + "inputs": [], + "name": "NumTokensOutOfRange", + "type": "error" + }, + { + "inputs": [], + "name": "PoolNotInitialized", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "bits", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "SafeCastOverflowedUintDowncast", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "SenderIsNotVault", + "type": "error" + }, + { + "inputs": [], + "name": "SenderNotAllowed", + "type": "error" + }, + { + "inputs": [], + "name": "SpotPriceIsZero", + "type": "error" + }, + { + "inputs": [], + "name": "SpotPricePrecompileFailed", + "type": "error" + }, + { + "inputs": [], + "name": "TokenIndexOutOfRange", + "type": "error" + }, + { + "inputs": [], + "name": "TokenInfoPrecompileFailed", + "type": "error" + }, + { + "inputs": [], + "name": "VaultNotSet", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "pct", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "CapDeviationPercentageChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "pct", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "MaxSurgeFeePercentageChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "numTokens", + "type": "uint8" + } + ], + "name": "PoolRegistered", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "pct", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "ThresholdPercentageChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "hlPairIndex", + "type": "uint32" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "hlTokenIndex", + "type": "uint32" + }, + { + "indexed": false, + "internalType": "uint8", + "name": "szDecimals", + "type": "uint8" + } + ], + "name": "TokenPriceConfiguredIndex", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "bytes4", + "name": "selector", + "type": "bytes4" + } + ], + "name": "getActionId", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAuthorizer", + "outputs": [ + { + "internalType": "contract IAuthorizer", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "getCapDeviationPercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getDefaultCapDeviationPercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getDefaultMaxSurgeFeePercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getDefaultSurgeThresholdPercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getHookFlags", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "enableHookAdjustedAmounts", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallBeforeInitialize", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallAfterInitialize", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallComputeDynamicSwapFee", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallBeforeSwap", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallAfterSwap", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallBeforeAddLiquidity", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallAfterAddLiquidity", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallBeforeRemoveLiquidity", + "type": "bool" + }, + { + "internalType": "bool", + "name": "shouldCallAfterRemoveLiquidity", + "type": "bool" + } + ], + "internalType": "struct HookFlags", + "name": "hookFlags", + "type": "tuple" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "getMaxSurgeFeePercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "getNumTokens", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "getSurgeThresholdPercentage", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + } + ], + "name": "getTokenPriceConfigIndex", + "outputs": [ + { + "internalType": "uint32", + "name": "pairIndex", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "priceDivisor", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + } + ], + "name": "getTokenPriceConfigs", + "outputs": [ + { + "internalType": "uint32[]", + "name": "pairIndexArr", + "type": "uint32[]" + }, + { + "internalType": "uint32[]", + "name": "priceDivisorArr", + "type": "uint32[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVault", + "outputs": [ + { + "internalType": "contract IVault", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "enum AddLiquidityKind", + "name": "kind", + "type": "uint8" + }, + { + "internalType": "uint256[]", + "name": "amountsInScaled18", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "amountsInRaw", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "balancesScaled18", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onAfterAddLiquidity", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "uint256[]", + "name": "hookAdjustedAmountsInRaw", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onAfterInitialize", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "enum RemoveLiquidityKind", + "name": "kind", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "amountsOutScaled18", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "amountsOutRaw", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "balancesScaled18", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onAfterRemoveLiquidity", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "uint256[]", + "name": "hookAdjustedAmountsOutRaw", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum SwapKind", + "name": "kind", + "type": "uint8" + }, + { + "internalType": "contract IERC20", + "name": "tokenIn", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "tokenOut", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amountInScaled18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutScaled18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenInBalanceScaled18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "tokenOutBalanceScaled18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountCalculatedScaled18", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountCalculatedRaw", + "type": "uint256" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "bytes", + "name": "userData", + "type": "bytes" + } + ], + "internalType": "struct AfterSwapParams", + "name": "", + "type": "tuple" + } + ], + "name": "onAfterSwap", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "enum AddLiquidityKind", + "name": "", + "type": "uint8" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onBeforeAddLiquidity", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onBeforeInitialize", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "enum RemoveLiquidityKind", + "name": "", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "onBeforeRemoveLiquidity", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum SwapKind", + "name": "kind", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "amountGivenScaled18", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "balancesScaled18", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "indexIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "indexOut", + "type": "uint256" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "bytes", + "name": "userData", + "type": "bytes" + } + ], + "internalType": "struct PoolSwapParams", + "name": "", + "type": "tuple" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "onBeforeSwap", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "enum SwapKind", + "name": "kind", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "amountGivenScaled18", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "balancesScaled18", + "type": "uint256[]" + }, + { + "internalType": "uint256", + "name": "indexIn", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "indexOut", + "type": "uint256" + }, + { + "internalType": "address", + "name": "router", + "type": "address" + }, + { + "internalType": "bytes", + "name": "userData", + "type": "bytes" + } + ], + "internalType": "struct PoolSwapParams", + "name": "p", + "type": "tuple" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "staticSwapFee", + "type": "uint256" + } + ], + "name": "onComputeDynamicSwapFeePercentage", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "enum TokenType", + "name": "tokenType", + "type": "uint8" + }, + { + "internalType": "contract IRateProvider", + "name": "rateProvider", + "type": "address" + }, + { + "internalType": "bool", + "name": "paysYieldFees", + "type": "bool" + } + ], + "internalType": "struct TokenConfig[]", + "name": "tokenCfgs", + "type": "tuple[]" + }, + { + "components": [ + { + "internalType": "bool", + "name": "disableUnbalancedLiquidity", + "type": "bool" + }, + { + "internalType": "bool", + "name": "enableAddLiquidityCustom", + "type": "bool" + }, + { + "internalType": "bool", + "name": "enableRemoveLiquidityCustom", + "type": "bool" + }, + { + "internalType": "bool", + "name": "enableDonation", + "type": "bool" + } + ], + "internalType": "struct LiquidityManagement", + "name": "", + "type": "tuple" + } + ], + "name": "onRegister", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "capDevPct18", + "type": "uint256" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "setCapDeviationPercentage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "pct18", + "type": "uint256" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "setMaxSurgeFeePercentage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint256", + "name": "pct18", + "type": "uint256" + }, + { + "internalType": "enum IHyperSurgeHook.TradeType", + "name": "tradeType", + "type": "uint8" + } + ], + "name": "setSurgeThresholdPercentage", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint8[]", + "name": "tokenIndices", + "type": "uint8[]" + }, + { + "internalType": "uint32[]", + "name": "pairIdx", + "type": "uint32[]" + }, + { + "internalType": "uint32[]", + "name": "hlTokenIdx", + "type": "uint32[]" + } + ], + "name": "setTokenPriceConfigBatchIndex", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "uint8", + "name": "tokenIndex", + "type": "uint8" + }, + { + "internalType": "uint32", + "name": "hlPairIdx", + "type": "uint32" + }, + { + "internalType": "uint32", + "name": "hlTokenIdx", + "type": "uint32" + } + ], + "name": "setTokenPriceConfigIndex", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/subgraphs/v3-pools/schema.graphql b/subgraphs/v3-pools/schema.graphql index 4422732..5927d28 100644 --- a/subgraphs/v3-pools/schema.graphql +++ b/subgraphs/v3-pools/schema.graphql @@ -3,6 +3,7 @@ enum PoolType { Stable QuantAMMWeighted StableSurge + HyperSurge Gyro2 GyroE LBP @@ -85,6 +86,45 @@ type StableSurgeParams @entity { surgeThresholdPercentage: BigDecimal! } +type HyperSurgeParams @entity { + "Unique identifier for the HyperSurgeParams (recommended: pool address)" + id: Bytes! + + "Number of tokens configured for oracle mapping (0..8)" + numTokens: Int! + + "ARBITRAGE: Maximum surge fee percentage" + arbMaxSurgeFeePercentage: BigDecimal! + "ARBITRAGE: Surge threshold percentage (fees start ramping above this)" + arbSurgeThresholdPercentage: BigDecimal! + "ARBITRAGE: Deviation cap percentage (fee reaches max at this deviation)" + arbCapDeviationPercentage: BigDecimal! + + "NOISE: Maximum surge fee percentage" + noiseMaxSurgeFeePercentage: BigDecimal! + "NOISE: Surge threshold percentage (fees start ramping above this)" + noiseSurgeThresholdPercentage: BigDecimal! + "NOISE: Deviation cap percentage (fee reaches max at this deviation)" + noiseCapDeviationPercentage: BigDecimal! + + "Per-token external price configuration" + tokenPriceConfigs: [HyperSurgeTokenPriceConfig!]! @derivedFrom(field: "params") +} + +type HyperSurgeTokenPriceConfig @entity { + "Unique identifier (e.g., params.id + '/' + tokenIndex)" + id: Bytes! + "Back-reference to the HyperSurgeParams" + params: HyperSurgeParams! + + "Balancer token index within the pool (0..7)" + tokenIndex: Int! + "External oracle/pair index used for this token" + pairIndex: Int! + "Price divisor applied to the external price (derived from on-chain size/decimals)" + priceDivisor: Int! +} + type Gyro2Params @entity { "Unique identifier for the Gyro2Params" id: Bytes! @@ -174,6 +214,8 @@ type Pool @entity { stableParams: StableParams "Parameters for StableSurge pools (null for other pool types)" stableSurgeParams: StableSurgeParams + "Parameters for HyperSurge pools (null for other pool types)" + hyperSurgeParams: HyperSurgeParams "Parameters for Gyro2 pools (null for other pool types)" gyro2Params: Gyro2Params "Parameters for GyroE pools (null for other pool types)" diff --git a/subgraphs/v3-pools/src/mappings/hypersurge.ts b/subgraphs/v3-pools/src/mappings/hypersurge.ts new file mode 100644 index 0000000..15c123f --- /dev/null +++ b/subgraphs/v3-pools/src/mappings/hypersurge.ts @@ -0,0 +1,205 @@ +/* src/mappings/hypersurge.ts */ + +import { + Address, + BigDecimal, + BigInt, + log, +} from "@graphprotocol/graph-ts"; + +import { + HyperSurgeParams, + HyperSurgeTokenPriceConfig, +} from "../../generated/schema"; + +import { + HyperSurgeHook, + PoolRegistered, + TokenPriceConfiguredIndex, + MaxSurgeFeePercentageChanged, + ThresholdPercentageChanged, + CapDeviationPercentageChanged, +} from "../../generated/HyperSurgeHook/HyperSurgeHook"; + +/** ----------------------------------------------------------------------- + * Helpers + * --------------------------------------------------------------------- */ + +const DECIMALS_18 = 18 as i32; +const TRADE_TYPE_ARBITRAGE = 0; +const TRADE_TYPE_NOISE = 1; + +/** Convert a 1e18-scaled uint256 percentage to BigDecimal (e.g., 0.01e18 -> 0.01) */ +function pctToBd(value: BigInt): BigDecimal { + const scale = BigInt.fromI32(10).pow(DECIMALS_18 as u8); + return value.toBigDecimal().div(scale.toBigDecimal()); +} + +/** Fetch or init the per-pool entity */ +function loadParams(pool: Address): HyperSurgeParams { + const id = pool.toHexString(); + let p = HyperSurgeParams.load(id); + if (p == null) { + p = new HyperSurgeParams(id); + // initialize with zeros to avoid nulls + p.numTokens = 0; + p.arbMaxSurgeFeePercentage = BigDecimal.zero(); + p.arbSurgeThresholdPercentage = BigDecimal.zero(); + p.arbCapDeviationPercentage = BigDecimal.zero(); + p.noiseMaxSurgeFeePercentage = BigDecimal.zero(); + p.noiseSurgeThresholdPercentage = BigDecimal.zero(); + p.noiseCapDeviationPercentage = BigDecimal.zero(); + } + return p as HyperSurgeParams; +} + +function refreshParamsFromChain(contract: HyperSurgeHook, pool: Address): void { + let p = loadParams(pool); + + const tryNum = contract.try_getNumTokens(pool); + if (!tryNum.reverted) { + p.numTokens = tryNum.value; + } + + const tryArbMax = contract.try_getMaxSurgeFeePercentage(pool, BigInt.fromI32(TRADE_TYPE_ARBITRAGE)); + if (!tryArbMax.reverted) { + p.arbMaxSurgeFeePercentage = pctToBd(tryArbMax.value); + } + + const tryArbThr = contract.try_getSurgeThresholdPercentage(pool, BigInt.fromI32(TRADE_TYPE_ARBITRAGE)); + if (!tryArbThr.reverted) { + p.arbSurgeThresholdPercentage = pctToBd(tryArbThr.value); + } + + const tryArbCap = contract.try_getCapDeviationPercentage(pool, BigInt.fromI32(TRADE_TYPE_ARBITRAGE)); + if (!tryArbCap.reverted) { + p.arbCapDeviationPercentage = pctToBd(tryArbCap.value); + } + + const tryNoiseMax = contract.try_getMaxSurgeFeePercentage(pool, BigInt.fromI32(TRADE_TYPE_NOISE)); + if (!tryNoiseMax.reverted) { + p.noiseMaxSurgeFeePercentage = pctToBd(tryNoiseMax.value); + } + + const tryNoiseThr = contract.try_getSurgeThresholdPercentage(pool, BigInt.fromI32(TRADE_TYPE_NOISE)); + if (!tryNoiseThr.reverted) { + p.noiseSurgeThresholdPercentage = pctToBd(tryNoiseThr.value); + } + + const tryNoiseCap = contract.try_getCapDeviationPercentage(pool, BigInt.fromI32(TRADE_TYPE_NOISE)); + if (!tryNoiseCap.reverted) { + p.noiseCapDeviationPercentage = pctToBd(tryNoiseCap.value); + } + + p.save(); +} + +/** Refresh all per-token price configs for a pool */ +function refreshAllTokenPriceConfigs(contract: HyperSurgeHook, pool: Address, numTokens: i32): void { + // Bulk fetch (getTokenPriceConfigs returns arrays) + const tryCfg = contract.try_getTokenPriceConfigs(pool); + if (tryCfg.reverted) { + // Fallback: query individually below + for (let i = 0; i < numTokens; i++) { + refreshOneTokenPriceConfig(contract, pool, i as i32); + } + return; + } + + const pairIdxArr = tryCfg.value.value0; // uint32[] (as BigInt[]) + const priceDivArr = tryCfg.value.value1; // uint32[] (as BigInt[]) + const n = pairIdxArr.length; + + for (let i = 0; i < numTokens && i < n; i++) { + const idx = i as i32; + const entityId = pool.toHexString() + "/" + idx.toString(); + let c = HyperSurgeTokenPriceConfig.load(entityId); + if (c == null) { + c = new HyperSurgeTokenPriceConfig(entityId); + c.params = pool.toHexString(); + c.tokenIndex = idx; + } + c.pairIndex = pairIdxArr[i].toI32(); + c.priceDivisor = priceDivArr[i].toI32(); + c.save(); + } +} + +/** Refresh a single token’s price config (used on TokenPriceConfiguredIndex) */ +function refreshOneTokenPriceConfig(contract: HyperSurgeHook, pool: Address, tokenIndex: i32): void { + const tryOne = contract.try_getTokenPriceConfigIndex(pool, tokenIndex as i32); + if (tryOne.reverted) { + log.warning("getTokenPriceConfigIndex reverted for pool {} token {}", [ + pool.toHexString(), + tokenIndex.toString(), + ]); + return; + } + const pairIndex = tryOne.value.value0.toI32(); + const priceDiv = tryOne.value.value1.toI32(); + + const entityId = pool.toHexString() + "/" + tokenIndex.toString(); + let c = HyperSurgeTokenPriceConfig.load(entityId); + if (c == null) { + c = new HyperSurgeTokenPriceConfig(entityId); + c.params = pool.toHexString(); + c.tokenIndex = tokenIndex; + } + c.pairIndex = pairIndex; + c.priceDivisor = priceDiv; + c.save(); +} + +/** ----------------------------------------------------------------------- + * Event handlers + * --------------------------------------------------------------------- */ + +/** Emitted when a pool registers with the hook (pool, numTokens). */ +export function handlePoolRegistered(event: PoolRegistered): void { + const pool = event.params.pool; + const contract = HyperSurgeHook.bind(event.address); + + // Create/update params entity and set numTokens right away + let p = loadParams(pool); + p.numTokens = event.params.numTokens; // uint8 -> i32 automatic + p.save(); + + // Refresh on-chain params and all token configs + refreshParamsFromChain(contract, pool); + refreshAllTokenPriceConfigs(contract, pool, p.numTokens); +} + +/** Emitted when a token’s oracle mapping or divisor changes. */ +export function handleTokenPriceConfiguredIndex(event: TokenPriceConfiguredIndex): void { + const pool = event.params.pool; + const tokenIdx = event.params.tokenIndex; // uint8 -> i32 + const contract = HyperSurgeHook.bind(event.address); + + // Ensure parent exists + loadParams(pool).save(); + + // Update only this token’s config (uses getTokenPriceConfigIndex for canonical values) + refreshOneTokenPriceConfig(contract, pool, tokenIdx); +} + +/** Any of these param-change events may alter the fee schedule for ARB/NOISE. Refresh both sides. */ +export function handleMaxSurgeFeePercentageChanged(event: MaxSurgeFeePercentageChanged): void { + const contract = HyperSurgeHook.bind(event.address); + const pool = event.params.pool; + loadParams(pool).save(); + refreshParamsFromChain(contract, pool); +} + +export function handleThresholdPercentageChanged(event: ThresholdPercentageChanged): void { + const contract = HyperSurgeHook.bind(event.address); + const pool = event.params.pool; + loadParams(pool).save(); + refreshParamsFromChain(contract, pool); +} + +export function handleCapDeviationPercentageChanged(event: CapDeviationPercentageChanged): void { + const contract = HyperSurgeHook.bind(event.address); + const pool = event.params.pool; + loadParams(pool).save(); + refreshParamsFromChain(contract, pool); +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..0c46add --- /dev/null +++ b/yarn.lock @@ -0,0 +1,15 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +argparse@^2.0.1: + version "2.0.1" + resolved "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz" + integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== + +js-yaml@^4.1.0: + version "4.1.0" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz" + integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + dependencies: + argparse "^2.0.1"