Skip to content

Commit

Permalink
fix getSlot0 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Mar 14, 2024
1 parent e6275ad commit bd692c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions contracts/hooks/examples/GeomeanOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract GeomeanOracle is BaseHook {
/// @dev Called before any action that potentially modifies pool price or liquidity, such as swap or modify position
function _updatePool(PoolKey calldata key) private {
PoolId id = key.toId();
(, int24 tick,) = poolManager.getSlot0(id);
(, int24 tick,,) = poolManager.getSlot0(id);

uint128 liquidity = poolManager.getLiquidity(id);

Expand Down Expand Up @@ -156,7 +156,7 @@ contract GeomeanOracle is BaseHook {

ObservationState memory state = states[id];

(, int24 tick,) = poolManager.getSlot0(id);
(, int24 tick,,) = poolManager.getSlot0(id);

uint128 liquidity = poolManager.getLiquidity(id);

Expand Down
30 changes: 20 additions & 10 deletions contracts/hooks/examples/VolatilityOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
pragma solidity ^0.8.19;

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {IDynamicFeeManager} from "@uniswap/v4-core/src/interfaces/IDynamicFeeManager.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {FeeLibrary} from "@uniswap/v4-core/src/libraries/FeeLibrary.sol";
import {SwapFeeLibrary} from "@uniswap/v4-core/src/libraries/SwapFeeLibrary.sol";
import {BaseHook} from "../../BaseHook.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";

contract VolatilityOracle is BaseHook, IDynamicFeeManager {
using FeeLibrary for uint24;
contract VolatilityOracle is BaseHook {
using SwapFeeLibrary for uint24;

error MustUseDynamicFee();

uint32 deployTimestamp;

function getFee(address, PoolKey calldata) external view returns (uint24) {
uint24 startingFee = 3000;
uint32 lapsed = _blockTimestamp() - deployTimestamp;
return startingFee + (uint24(lapsed) * 100) / 60; // 100 bps a minute
}
// function getFee(address, PoolKey calldata) external view returns (uint24) {
// uint24 startingFee = 3000;
// uint32 lapsed = _blockTimestamp() - deployTimestamp;
// return startingFee + (uint24(lapsed) * 100) / 60; // 100 bps a minute
// }

/// @dev For mocking
function _blockTimestamp() internal view virtual returns (uint32) {
Expand All @@ -33,7 +32,7 @@ contract VolatilityOracle is BaseHook, IDynamicFeeManager {
function getHookPermissions() public pure override returns (Hooks.Permissions memory) {
return Hooks.Permissions({
beforeInitialize: true,
afterInitialize: false,
afterInitialize: true,
beforeAddLiquidity: false,
beforeRemoveLiquidity: false,
afterAddLiquidity: false,
Expand All @@ -54,4 +53,15 @@ contract VolatilityOracle is BaseHook, IDynamicFeeManager {
if (!key.fee.isDynamicFee()) revert MustUseDynamicFee();
return VolatilityOracle.beforeInitialize.selector;
}

function afterInitialize(address, PoolKey calldata key, uint160, int24, bytes calldata)
external
override
returns (bytes4)
{
uint24 startingFee = 3000;
uint32 lapsed = _blockTimestamp() - deployTimestamp;
uint24 fee = startingFee + (uint24(lapsed) * 100) / 60; // 100 bps a minute
poolManager.updateDynamicSwapFee(key, fee); // initial fee 0.30%
}
}

0 comments on commit bd692c4

Please sign in to comment.