Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to deploy6 #60

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "packages/foundry/lib/permit2"]
path = packages/foundry/lib/permit2
url = https://github.com/uniswap/permit2
[submodule "packages/foundry/lib/balancer-v3-monorepo"]
path = packages/foundry/lib/balancer-v3-monorepo
url = https://github.com/balancer/balancer-v3-monorepo
10 changes: 5 additions & 5 deletions packages/foundry/contracts/hooks/VeBALFeeDiscountHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
pragma solidity ^0.8.24;

import {
BasePoolHooks,
BaseHooks,
IVault,
IHooks,
TokenConfig,
LiquidityManagement
} from "@balancer-labs/v3-vault/contracts/BasePoolHooks.sol";
} from "@balancer-labs/v3-vault/contracts/BaseHooks.sol";
import { IBasePoolFactory } from "@balancer-labs/v3-interfaces/contracts/vault/IBasePoolFactory.sol";
import { IBasePool } from "@balancer-labs/v3-interfaces/contracts/vault/IBasePool.sol";
import { IRouterCommon } from "@balancer-labs/v3-interfaces/contracts/vault/IRouterCommon.sol";
Expand All @@ -17,15 +17,15 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title VeBAL Fee Discount Hook
*/
contract VeBALFeeDiscountHook is BasePoolHooks {
contract VeBALFeeDiscountHook is BaseHooks {
// only pools from the allowedFactory are able to register and use this hook
address private immutable _allowedFactory;
// only calls from a trusted routers are allowed to call this hook, because the hook relies on the getSender
// implementation to work properly
address private immutable _trustedRouter;
IERC20 private immutable _veBAL;

constructor(IVault vault, address allowedFactory, address veBAL, address trustedRouter) BasePoolHooks(vault) {
constructor(IVault vault, address allowedFactory, address veBAL, address trustedRouter) BaseHooks(vault) {
_allowedFactory = allowedFactory;
_trustedRouter = trustedRouter;
_veBAL = IERC20(veBAL);
Expand All @@ -49,9 +49,9 @@ contract VeBALFeeDiscountHook is BasePoolHooks {
return factory == _allowedFactory && IBasePoolFactory(factory).isPoolFromFactory(pool);
}

/// @inheritdoc IHooks
function onComputeDynamicSwapFee(
IBasePool.PoolSwapParams calldata params,
address,
uint256 staticSwapFeePercentage
) external view override returns (bool, uint256) {
// If the router is not trusted, does not apply the veBAL discount because getSender() may be manipulated by a
Expand Down
6 changes: 3 additions & 3 deletions packages/foundry/contracts/pools/ConstantProductFactory.sol
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.24;

import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol";
import {
LiquidityManagement,
PoolRoleAccounts,
TokenConfig
} from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";
import { BasePoolFactory } from "@balancer-labs/v3-vault/contracts/factories/BasePoolFactory.sol";
import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol";
import { BasePoolFactory } from "@balancer-labs/v3-pool-utils/contracts/BasePoolFactory.sol";

import { ConstantProductPool } from "./ConstantProductPool.sol";

/**
* @title Constant Sum Factory
* @title Constant Product Factory
* @dev Deploying pools via a factory is the preferred pattern as opposed to deploying a pool directly without a factory
*/
contract ConstantProductFactory is BasePoolFactory {
Expand Down
2 changes: 1 addition & 1 deletion packages/foundry/contracts/pools/ConstantSumFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
PoolRoleAccounts,
TokenConfig
} from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";
import { BasePoolFactory } from "@balancer-labs/v3-vault/contracts/factories/BasePoolFactory.sol";
import { BasePoolFactory } from "@balancer-labs/v3-pool-utils/contracts/BasePoolFactory.sol";

import { ConstantSumPool } from "./ConstantSumPool.sol";

Expand Down
1 change: 1 addition & 0 deletions packages/foundry/lib/balancer-v3-monorepo
Submodule balancer-v3-monorepo added at d048af
1 change: 0 additions & 1 deletion packages/foundry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"verify": "forge build --build-info --build-info-path out/build-info/ && forge script script/VerifyAll.s.sol --ffi --rpc-url ${1:-default_network}"
},
"dependencies": {
"@balancer-labs/v3-monorepo": "https://github.com/balancer/balancer-v3-monorepo#head=scaffold-package-setup-deploy5",
"dotenv": "~16.3.1",
"envfile": "~6.18.0",
"ethers": "~5.7.1",
Expand Down
12 changes: 7 additions & 5 deletions packages/foundry/remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
@test/=node_modules/@balancer-labs/v3-monorepo/pkg/
@balancer-labs/v3-solidity-utils/=node_modules/@balancer-labs/v3-monorepo/pkg/solidity-utils/
@balancer-labs/v3-interfaces/=node_modules/@balancer-labs/v3-monorepo/pkg/interfaces/
@balancer-labs/v3-vault/=node_modules/@balancer-labs/v3-monorepo/pkg/vault/
@test/=lib/balancer-v3-monorepo/pkg/
@balancer-labs/v3-solidity-utils/=lib/balancer-v3-monorepo/pkg/solidity-utils/
@balancer-labs/v3-pool-utils/=lib/balancer-v3-monorepo/pkg/pool-utils/
@balancer-labs/v3-interfaces/=lib/balancer-v3-monorepo/pkg/interfaces/
@balancer-labs/v3-vault/=lib/balancer-v3-monorepo/pkg/vault/
permit2/=lib/permit2/
forge-gas-snapshot/=node_modules/forge-gas-snapshot/src/
forge-gas-snapshot/=node_modules/forge-gas-snapshot/src/
@openzeppelin/=lib/openzeppelin-contracts/
15 changes: 8 additions & 7 deletions packages/foundry/script/01_DeployConstantSumPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ contract DeployConstantSumPool is PoolHelpers, ScaffoldHelpers {
address token1,
address token2
) internal view returns (RegistrationConfig memory regConfig) {
string memory name = "Constant Sum Pool #1"; // name for the pool
string memory symbol = "CS-50scUSD-50scDAI"; // symbol for the BPT
string memory name = "Constant Sum Pool"; // name for the pool
string memory symbol = "CSP"; // symbol for the BPT
bytes32 salt = keccak256(abi.encode(block.number)); // salt for the pool deployment via factory
uint256 swapFeePercentage = 1e12; // 0.00001%
uint256 swapFeePercentage = 0.001e18; // 0.1%
bool protocolFeeExempt = true;
address poolHooksContract = address(0); // zero address if no hooks contract is needed

Expand All @@ -110,7 +110,8 @@ contract DeployConstantSumPool is PoolHelpers, ScaffoldHelpers {
LiquidityManagement memory liquidityManagement = LiquidityManagement({
disableUnbalancedLiquidity: false,
enableAddLiquidityCustom: false,
enableRemoveLiquidityCustom: false
enableRemoveLiquidityCustom: false,
enableDonation: false
});

regConfig = RegistrationConfig({
Expand Down Expand Up @@ -138,9 +139,9 @@ contract DeployConstantSumPool is PoolHelpers, ScaffoldHelpers {
tokens[0] = IERC20(token1);
tokens[1] = IERC20(token2);
uint256[] memory exactAmountsIn = new uint256[](2); // Exact amounts of tokens to be added, sorted in token alphanumeric order
exactAmountsIn[0] = 10 ether; // amount of token1 to send during pool initialization
exactAmountsIn[1] = 10 ether; // amount of token2 to send during pool initialization
uint256 minBptAmountOut = 1 ether; // Minimum amount of pool tokens to be received
exactAmountsIn[0] = 50e18; // amount of token1 to send during pool initialization
exactAmountsIn[1] = 50e18; // amount of token2 to send during pool initialization
uint256 minBptAmountOut = 99e18; // Minimum amount of pool tokens to be received
bool wethIsEth = false; // If true, incoming ETH will be wrapped to WETH; otherwise the Vault will pull WETH tokens
bytes memory userData = bytes(""); // Additional (optional) data required for adding initial liquidity

Expand Down
15 changes: 8 additions & 7 deletions packages/foundry/script/02_DeployConstantProductPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ contract DeployConstantProductPool is PoolHelpers, ScaffoldHelpers {
IERC20 token1,
IERC20 token2
) internal view returns (RegistrationConfig memory regConfig) {
string memory name = "Constant Product Pool #1"; // name for the pool
string memory symbol = "CP-50scUSD-50scDAI"; // symbol for the BPT
string memory name = "Constant Product Pool"; // name for the pool
string memory symbol = "CPP"; // symbol for the BPT
bytes32 salt = keccak256(abi.encode(block.number)); // salt for the pool deployment via factory
uint256 swapFeePercentage = 1e12; // 0.00001%
uint256 swapFeePercentage = 0.001e18; // 0.1%
bool protocolFeeExempt = false;
address poolHooksContract = address(0); // zero address if no hooks contract is needed

Expand All @@ -116,7 +116,8 @@ contract DeployConstantProductPool is PoolHelpers, ScaffoldHelpers {
LiquidityManagement memory liquidityManagement = LiquidityManagement({
disableUnbalancedLiquidity: false,
enableAddLiquidityCustom: false,
enableRemoveLiquidityCustom: false
enableRemoveLiquidityCustom: false,
enableDonation: false
});

regConfig = RegistrationConfig({
Expand Down Expand Up @@ -144,9 +145,9 @@ contract DeployConstantProductPool is PoolHelpers, ScaffoldHelpers {
tokens[0] = token1;
tokens[1] = token2;
uint256[] memory exactAmountsIn = new uint256[](2); // Exact amounts of tokens to be added, sorted in token alphanumeric order
exactAmountsIn[0] = 10 ether; // amount of token1 to send during pool initialization
exactAmountsIn[1] = 10 ether; // amount of token2 to send during pool initialization
uint256 minBptAmountOut = 1 ether; // Minimum amount of pool tokens to be received
exactAmountsIn[0] = 50e18; // amount of token1 to send during pool initialization
exactAmountsIn[1] = 50e18; // amount of token2 to send during pool initialization
uint256 minBptAmountOut = 49e18; // Minimum amount of pool tokens to be received
bool wethIsEth = false; // If true, incoming ETH will be wrapped to WETH; otherwise the Vault will pull WETH tokens
bytes memory userData = bytes(""); // Additional (optional) data required for adding initial liquidity

Expand Down
4 changes: 2 additions & 2 deletions packages/foundry/script/PoolHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
*/
contract PoolHelpers {
// BalancerV3 Sepolia addresses (5th testnet release)
address internal vault = 0xD5584b37D1845fFeD958C2d94bC675603DdCce68;
address internal router = 0x1c58cc548a23956469c7C528Bb3a846c842dfaF9;
address internal vault = 0x92B5c1CB2999c45804A60d6529D77DeEF00fb839;
address internal router = 0xa12Da7dfD0792a10a5b05B575545Bd685798Ce35;
address internal permit2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

struct RegistrationConfig {
Expand Down
80 changes: 80 additions & 0 deletions packages/nextjs/app/hooks/_components/HooksCards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"use client";

import { useState } from "react";
import Link from "next/link";
import { type HookDetails } from "../page";
import Modal from "~~/components/common/Modal";

export const HooksCards = ({ hooks }: { hooks: HookDetails[] }) => {
const [activeModal, setActiveModal] = useState<number | null>(null);

const modalContent = (id: number) => {
if (!hooks) return null;
const hook = hooks.find(hook => hook.id === id);
if (!hook) return null;
const categories = hook.category.join(", ");
return (
<div className="text-lg">
<h1 className="text-3xl font-bold mb-1">{hook.title}</h1>
<div className="">Created By {hook.created_by}</div>
<p className="text-xl">{hook.description}</p>
<div>Audited: {hook.audited}</div>
<div className="flex justify-between">
<div>Categories: {categories}</div>
<Link
href={hook.github}
rel="noopener noreferrer"
target="_blank"
className="link flex items-center gap-2 hover:text-violet-400"
>
View on Github <GithubIcon />
</Link>
</div>
</div>
);
};

return (
<>
<div className="grid grid-cols-1 lg:grid-cols-2 2xl:grid-cols-3 gap-5 w-full">
{hooks.map(hook => (
<div
key={hook.id}
className="bg-base-200 hover:bg-base-100 p-5 rounded-lg w-full hover:cursor-pointer"
onClick={() => setActiveModal(hook.id)}
>
<div className="mb-3">
<div className="flex justify-between items-center">
<h1 className="text-2xl font-bold mb-0">{hook.title}</h1>
<Link target="_blank" rel="noopener noreferrer" href={hook.github}>
<GithubIcon />
</Link>
</div>
{/* <div className="">Created By {hook.created_by}</div> */}
</div>
<div className="text-lg card-description">{hook.description}</div>
</div>
))}
</div>

{activeModal && (
<Modal isOpen={activeModal !== null} onClose={() => setActiveModal(null)}>
{modalContent(activeModal)}
</Modal>
)}
</>
);
};

const GithubIcon = () => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width="30"
height="30"
fill="currentColor"
className="hover:text-violet-400"
>
<path d="M12.001 2C6.47598 2 2.00098 6.475 2.00098 12C2.00098 16.425 4.86348 20.1625 8.83848 21.4875C9.33848 21.575 9.52598 21.275 9.52598 21.0125C9.52598 20.775 9.51348 19.9875 9.51348 19.15C7.00098 19.6125 6.35098 18.5375 6.15098 17.975C6.03848 17.6875 5.55098 16.8 5.12598 16.5625C4.77598 16.375 4.27598 15.9125 5.11348 15.9C5.90098 15.8875 6.46348 16.625 6.65098 16.925C7.55098 18.4375 8.98848 18.0125 9.56348 17.75C9.65098 17.1 9.91348 16.6625 10.201 16.4125C7.97598 16.1625 5.65098 15.3 5.65098 11.475C5.65098 10.3875 6.03848 9.4875 6.67598 8.7875C6.57598 8.5375 6.22598 7.5125 6.77598 6.1375C6.77598 6.1375 7.61348 5.875 9.52598 7.1625C10.326 6.9375 11.176 6.825 12.026 6.825C12.876 6.825 13.726 6.9375 14.526 7.1625C16.4385 5.8625 17.276 6.1375 17.276 6.1375C17.826 7.5125 17.476 8.5375 17.376 8.7875C18.0135 9.4875 18.401 10.375 18.401 11.475C18.401 15.3125 16.0635 16.1625 13.8385 16.4125C14.201 16.725 14.5135 17.325 14.5135 18.2625C14.5135 19.6 14.501 20.675 14.501 21.0125C14.501 21.275 14.6885 21.5875 15.1885 21.4875C19.259 20.1133 21.9999 16.2963 22.001 12C22.001 6.475 17.526 2 12.001 2Z"></path>
</svg>
);
2 changes: 1 addition & 1 deletion packages/nextjs/app/hooks/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getMetadata } from "~~/utils/scaffold-eth/getMetadata";

export const metadata = getMetadata({
title: "Pool Hooks",
description: "...",
description: "Discover example hooks contracts",
});

const HooksLayout = ({ children }: { children: React.ReactNode }) => {
Expand Down
Loading
Loading