From eeb09d74a075c5b5351b36e90d9f6807f813de77 Mon Sep 17 00:00:00 2001 From: Jeff Wu Date: Tue, 28 Nov 2023 14:56:02 -0800 Subject: [PATCH] fix: check if get actual supply exists --- contracts/vaults/BalancerWeightedAuraVault.sol | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contracts/vaults/BalancerWeightedAuraVault.sol b/contracts/vaults/BalancerWeightedAuraVault.sol index b6488d13..325ea67a 100644 --- a/contracts/vaults/BalancerWeightedAuraVault.sol +++ b/contracts/vaults/BalancerWeightedAuraVault.sol @@ -91,4 +91,19 @@ contract BalancerWeightedAuraVault is AuraStakingMixin { return _calculateLPTokenValue(balances, spotPrices); } + + /// @notice Weighted pools may have pre-minted BPT. If that is the case then + /// we need to call getActualSupply() instead. Legacy pools do not have the + /// getActualSupply method. See: + /// https://docs.balancer.fi/concepts/advanced/valuing-bpt/valuing-bpt.html#getting-bpt-supply + function _totalPoolSupply() internal view override returns (uint256) { + // As of this writing the documentation linked above appears inaccurate and the + // pre-minted total supply returned by a pool is not a fixed constant. Therefore, + // we use a try / catch here instead. + try IComposablePool(address(BALANCER_POOL_TOKEN)).getActualSupply() returns (uint256 totalSupply) { + return totalSupply; + } catch { + return super._totalPoolSupply(); + } + } } \ No newline at end of file