Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c13ddc2
initial reduction
bulkcade Mar 7, 2025
825b36c
fix tests
bulkcade Mar 7, 2025
a243a7c
cherry pick factory splitter from monorepo main 4df25be3bab3f1a0e8247…
bulkcade Feb 27, 2025
e949623
deploy test
bulkcade Feb 26, 2025
8206067
further deploy
bulkcade Mar 6, 2025
41f9387
further deployment test progress
bulkcade Mar 10, 2025
bacfdf2
slight tidy up and new deploy antimom test
bulkcade Mar 12, 2025
fcefe6b
audit review md file
bulkcade Mar 11, 2025
a2121c1
initialise script
bulkcade Mar 18, 2025
19fdbf1
different pool_checks
bulkcade Apr 3, 2025
0ce23c9
push hardhat optimiser runs for further efficiencies
bulkcade Mar 12, 2025
92d1d9f
add view functions for intermediate states to help monitoring and DR …
bulkcade Apr 3, 2025
3f5690a
new scripts
bulkcade Apr 7, 2025
0203236
Merge remote-tracking branch 'origin/main' into deploy-sepolia
bulkcade Apr 8, 2025
b7dba5d
restructure scripts location for public use
bulkcade Apr 8, 2025
0c59961
fixes to imports
bulkcade Apr 9, 2025
c05839a
Merge remote-tracking branch 'origin/main' into deploy-sepolia
bulkcade Apr 11, 2025
0893df6
new test net push
bulkcade Apr 11, 2025
0811c3a
Merge remote-tracking branch 'origin/main' into deploy-sepolia
bulkcade Apr 15, 2025
2a8cad4
updates to scripts
bulkcade Apr 18, 2025
1331d6d
additional diagnostics
bulkcade Apr 23, 2025
cd972e8
new update weight runner
bulkcade Apr 23, 2025
d2af47a
updated diagnostic scripts
bulkcade Apr 25, 2025
ee26aa9
fix
bulkcade Apr 25, 2025
93c5342
add liquidity permit2
bulkcade Apr 25, 2025
143f1e8
update initialise pool
MatthewWilletts Apr 27, 2025
6929a53
updated scripts
bulkcade Apr 27, 2025
5bba951
bump liquiditiy depoloyment script
MatthewWilletts Apr 28, 2025
5d75437
Merge branch 'deploy-sepolia' of github.com:QuantAMMProtocol/QuantAMM…
MatthewWilletts Apr 28, 2025
ee458a1
update pool address to mainnet safe haven pool, set deposit amounts to 0
MatthewWilletts Apr 29, 2025
de3ce14
Merge remote-tracking branch 'origin/main' into deploy-sepolia
bulkcade May 6, 2025
0bc202d
CODEHAWKS-H-02
bulkcade Jun 12, 2025
c742f09
H-06 admin fee divide
bulkcade Jun 17, 2025
39322c6
H-07 send to owner not contract address
bulkcade Jun 17, 2025
82e78e6
H-11 proportional to deposits now
bulkcade Jun 17, 2025
b0e8f77
M-1 fix setters for uplift fee
bulkcade Jun 17, 2025
1ca2089
M-03 fix scaling for computation
bulkcade Jun 17, 2025
b698ec0
M-04 restrict transfer to sell
bulkcade Jun 17, 2025
de95ff3
M-06 add check that recipient does not have more than 100 deposits
bulkcade Jun 17, 2025
01c89a3
M-08 add maximum fee take
bulkcade Jun 17, 2025
9d62582
M-13 retain original fee level on transfer
bulkcade Jun 17, 2025
f37a650
M-18 get correct swap fee take
bulkcade Jun 17, 2025
2668238
L-14 change number to timestamp tracking
bulkcade Jun 17, 2025
0cdf0bb
restrict to 1 deposit per block
bulkcade Jun 17, 2025
8c58044
use errors instead of requires
bulkcade Jun 17, 2025
d02671d
fix ownership tests
bulkcade Jun 18, 2025
56264ba
fix tests and tweaks to logic
bulkcade Jun 26, 2025
3f1a7be
remove build warnings
bulkcade Jun 26, 2025
e7b3dcc
fuzz test progress
bulkcade Jun 27, 2025
259cf09
add debug version
bulkcade Jul 4, 2025
9651faf
uplift fuzz progress
bulkcade Jul 9, 2025
44d2961
fixes to rounding given fuzz tests, convert fees to be stored in 18dp…
bulkcade Jul 15, 2025
2688629
add fuzz and move tests
bulkcade Jul 16, 2025
89656ba
fix expectations
bulkcade Jul 16, 2025
719f92b
tidy up
bulkcade Jul 21, 2025
db903ca
merge from main
bulkcade Sep 29, 2025
0c235c2
fix build
bulkcade Sep 29, 2025
9693ffa
stack too deep in the tests
bulkcade Sep 30, 2025
168f211
fix tests
bulkcade Sep 30, 2025
e52af3d
formatting
bulkcade Sep 30, 2025
befc311
unbalanced add debug
bulkcade Oct 2, 2025
a08cd72
change to send to for the admin
bulkcade Oct 7, 2025
828fbad
uplift example
bulkcade Oct 10, 2025
e5bb5b4
uplift fuzz correction
bulkcade Oct 20, 2025
4b3c605
add too fast withdrawal
bulkcade Oct 23, 2025
52f6815
fix test
bulkcade Oct 24, 2025
15d574c
change to LPoracle
bulkcade Oct 24, 2025
b5bcb48
transfer reduced to max 50 deposits to prevent transfer dust blocking
bulkcade Oct 24, 2025
ff566b7
change to use LP oracles instead of quantamm update weight runner
bulkcade Oct 27, 2025
c919b1d
uplift test conversion progress
bulkcade Oct 29, 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
1 change: 1 addition & 0 deletions pkg/pool-hooks/contracts/hooks-quantamm/LPNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contract LPNFT is ERC721 {
previousOwner = super._update(to, tokenId, auth);
//_update is called during mint, burn and transfer. This functionality is only for transfer
if (to != address(0) && previousOwner != address(0)) {
require(previousOwner != to, "CANNOT_TRANSFER_TO_SELF");
//if transfering the record in the vault needs to be changed to reflect the change in ownership
router.afterUpdate(previousOwner, to, tokenId);
}
Expand Down
402 changes: 251 additions & 151 deletions pkg/pool-hooks/contracts/hooks-quantamm/UpliftOnlyExample.sol

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions pkg/pool-hooks/contracts/test/LPOracleBaseMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.24;

import { AggregatorV3Interface } from "@chainlink/contracts/src/v0.8/shared/interfaces/AggregatorV3Interface.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import { IWeightedLPOracle } from "@balancer-labs/v3-interfaces/contracts/standalone-utils/IWeightedLPOracle.sol";
import { ILPOracleBase } from "@balancer-labs/v3-interfaces/contracts/standalone-utils/ILPOracleBase.sol";
import { IWeightedPool } from "@balancer-labs/v3-interfaces/contracts/pool-weighted/IWeightedPool.sol";
import { Rounding } from "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol";
import { IBasePool } from "@balancer-labs/v3-interfaces/contracts/vault/IBasePool.sol";
import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol";

import { FixedPoint } from "@balancer-labs/v3-solidity-utils/contracts/math/FixedPoint.sol";

import { LPOracleBase } from "@balancer-labs/v3-standalone-utils/contracts/LPOracleBase.sol";

contract MockLPOracle is IWeightedLPOracle, LPOracleBase {
using FixedPoint for uint256;
using SafeCast for *;

uint256 internal immutable _weight0;
uint256 internal immutable _weight1;
uint256 internal immutable _weight2;
uint256 internal immutable _weight3;
uint256 internal immutable _weight4;
uint256 internal immutable _weight5;
uint256 internal immutable _weight6;
uint256 internal immutable _weight7;

constructor(
IVault vault_,
IWeightedPool pool_,
AggregatorV3Interface[] memory feeds,
uint256 version_
) LPOracleBase(vault_, IBasePool(address(pool_)), feeds, version_) {
uint256[] memory weights = pool_.getNormalizedWeights();

// prettier-ignore
{
_weight0 = weights[0];

_weight1 = weights[1];

if (_totalTokens > 2) {
_weight2 = weights[2];
}
if (_totalTokens > 3) {
_weight3 = weights[3];
}
if (_totalTokens > 4) {
_weight4 = weights[4];
}
if (_totalTokens > 5) {
_weight5 = weights[5];
}
if (_totalTokens > 6) {
_weight6 = weights[6];
}
if (_totalTokens > 7) {
_weight7 = weights[7];
}
}
}

/// @inheritdoc ILPOracleBase
function calculateTVL(int256[] memory prices) public view override returns (uint256 tvl) {
uint256[] memory weights = _getWeights();
uint256[] memory lastBalancesLiveScaled18 = _vault.getCurrentLiveBalances(address(pool));

/**********************************************************************************************
// We know that the normalized value of each token in the pool is equal:
// C = (P1 * B1 / W1) = (P2 * B2 / W2) = ... = (Pn * Bn / Wn)
//
// Where:
// n = number of tokens
// Pi = market price of token i
// Bi = balance of token i
// Wi = normalized weight of token i (sum of all Wi == 1)
// C = common normalized value across tokens
//
// From this, we can express the balance of token i:
// Bi = (C * Wi) / Pi
//
// The total value locked (TVL) is the sum of all token values:
// TVL = Σ (Bi * Pi)
// Substituting Bi:
// TVL = Σ ((C * Wi / Pi) * Pi) = C * Σ(Wi) = C
// C = TVL
//
// So:
// Bi = (TVL * Wi) / Pi
//
// The invariant of the WeightedPool pool is defined as:
// k = Π (Bi^Wi)
//
// Substituting Bi and using the fact that Σ(Wi) = 1:
// k = Π ((TVL * Wi / Pi)^Wi)
// = TVL^Σ(Wi) * Π((Wi / Pi)^Wi)
// = TVL * Π((Wi / Pi)^Wi)
//
// Solving for TVL:
// TVL = k * Π((Pi / Wi)^Wi)
**********************************************************************************************/

/**********************************************************************************************
// invariant _____ //
// wi = weight index i | | wi //
// pi = price index i k * | | (pi/wi) ^ = tvl //
// k = invariant //
**********************************************************************************************/

uint256 k = pool.computeInvariant(lastBalancesLiveScaled18, Rounding.ROUND_UP);

tvl = FixedPoint.ONE;
for (uint256 i = 0; i < _totalTokens; i++) {
tvl = tvl.mulDown(prices[i].toUint256().divDown(weights[i]).powDown(weights[i]));
}

tvl = tvl.mulDown(k);
}

function getWeights() external view returns (uint256[] memory) {
return _getWeights();
}

function _getWeights() internal view returns (uint256[] memory) {
uint256[] memory weights = new uint256[](_totalTokens);

// prettier-ignore
{
weights[0] = _weight0;
weights[1] = _weight1;
if (_totalTokens > 2) { weights[2] = _weight2; } else { return weights; }
if (_totalTokens > 3) { weights[3] = _weight3; } else { return weights; }
if (_totalTokens > 4) { weights[4] = _weight4; } else { return weights; }
if (_totalTokens > 5) { weights[5] = _weight5; } else { return weights; }
if (_totalTokens > 6) { weights[6] = _weight6; } else { return weights; }
if (_totalTokens > 7) { weights[7] = _weight7; }
}

return weights;
}
}
3 changes: 2 additions & 1 deletion pkg/pool-hooks/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ remappings = [
'permit2/=../../node_modules/permit2/',
'@balancer-labs/=../../node_modules/@balancer-labs/',
'@prb/=../../node_modules/@prb',
'@chainlink=../../node_modules/@chainlink/',
'forge-gas-snapshot/=../../node_modules/forge-gas-snapshot/src/'
]
optimizer = true
optimizer_runs = 999
solc_version = '0.8.26'
solc_version = '0.8.27'
auto_detect_solc = false
evm_version = 'cancun'
ignored_error_codes = [2394, 5574, 3860] # Transient storage, code size
Expand Down
Loading
Loading