Skip to content

Commit

Permalink
created governance token
Browse files Browse the repository at this point in the history
  • Loading branch information
naman1402 committed Nov 27, 2024
1 parent 2c6ecdf commit 61d5a85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/GovToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {Owned} from "solmate/src/auth/Owned.sol";

contract GovToken is ERC20, Owned {

constructor(string memory name, string memory symbol) ERC20(name, symbol, 18) Owned(msg.sender){}

function mint(address to, uint256 amount) external override onlyOwner() {
_mint(to, amount);
}
}
24 changes: 20 additions & 4 deletions src/JITHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {IPositionManager} from "v4-periphery/src/interfaces/IPositionManager.sol
import {Actions} from "v4-periphery/src/libraries/Actions.sol";
import {LiquidityAmounts} from "v4-core/test/utils/LiquidityAmounts.sol";
import {TickMath} from "v4-core/src/libraries/TickMath.sol";
import {GovToken} from "./GovToken.sol";

contract JITHook is BaseHook {
using PoolIdLibrary for PoolId;
Expand All @@ -32,6 +33,9 @@ contract JITHook is BaseHook {
uint256 public currentPositionId;
uint256 public currentActiveStrategyId;

mapping(PoolKey => GovToken) public govTokens;
// mapping(PoolId => GovToken) public govTokens;

constructor(
IPoolManager _manager,
address _strategiesController,
Expand All @@ -56,7 +60,7 @@ contract JITHook is BaseHook {
return
Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
afterInitialize: true,
beforeAddLiquidity: false,
afterAddLiquidity: false,
beforeRemoveLiquidity: false,
Expand All @@ -72,6 +76,13 @@ contract JITHook is BaseHook {
});
}

function afterInitialize(address, PoolKey calldata key, uint160, int24) external virtual returns (bytes4) {
string memory name = string.concat("Governance token: ", key.currency0.symbol, "-", key.currency1.symbol);
string memory symbol = string.concat(key.currency0.symbol, "-", key.currency1.symbol);
govTokens[key] = new GovToken(name, symbol);
return this.afterInitialize.selector;
}

// if swap is big => remove lquidity from external protocol and add liquidity
function beforeSwap(
address,
Expand Down Expand Up @@ -150,17 +161,22 @@ contract JITHook is BaseHook {

if(amount0 > 0) {
_depositToStrategy(currentActiveStrategyId, key.currency0, amount0);
govTokens[key].mint(msg.sender, amount0);
}
if(amount1 > 0) {
_depositToStrategy(currentActiveStrategyId, key.currency1, amount1);
govTokens[key].mint(msg.sender, amount1);
}

// todo emit event
}

// funds transferred to small LPs from external protocol
function withdraw(uint256 amount0, uint256 amount1, PoolKey calldata key) external {
uint256 withdrawAmount = _withdrawFromStrategy(currentActiveStrategyId);
address token0 = Currency.unwrap(key.currency0);
address token1 = Currency.unwrap(key.currency1);
uint256 withdrawAmount = _withdrawFromStrategy(currentActiveStrategyId, token0, amount0);
uint256 withdrawAmountToken1 = _withdrawFromStrategy(currentActiveStrategyId, token1, amount1);

// todo calculate token amount for the user, and transfer to user
// todo multiple user wil store funds here, when one user call this only his liquidty should be removed and transferred to user NOT ALL
Expand All @@ -177,8 +193,8 @@ contract JITHook is BaseHook {
IStrategy(controller.getStrategyAddress(_id)).deposit(_token, _amount);
}

function _withdrawFromStrategy(uint256 _id) internal returns (uint256) {
return IStrategy(controller.getStrategyAddress(_id)).withdraw();
function _withdrawFromStrategy(uint256 _id, address token, uint256 amount) internal returns (uint256) {
return IStrategy(controller.getStrategyAddress(_id)).withdraw(token, amount);
}

function _addLiquidityToPool(
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ pragma solidity 0.8.26;
interface IStrategy {

function deposit(address token, uint256 amount) external;
function withdraw() external returns (uint256);
function withdraw(address token, uint256 amount) external returns (uint256);
function redeemYeild() external;
}

0 comments on commit 61d5a85

Please sign in to comment.