diff --git a/protocol/contracts/ecosystem/price/WellPrice.sol b/protocol/contracts/ecosystem/price/WellPrice.sol index ef978fdd51..244831bc27 100644 --- a/protocol/contracts/ecosystem/price/WellPrice.sol +++ b/protocol/contracts/ecosystem/price/WellPrice.sol @@ -4,7 +4,7 @@ pragma experimental ABIEncoderV2; import {P} from "./P.sol"; import {SafeMath} from "@openzeppelin/contracts/math/SafeMath.sol"; -import {IWell, IERC20} from "../../interfaces/basin/IWell.sol"; +import {Call, IWell, IERC20} from "../../interfaces/basin/IWell.sol"; import {IBeanstalkWellFunction} from "../../interfaces/basin/IBeanstalkWellFunction.sol"; import {LibUsdOracle} from "../../libraries/Oracle/LibUsdOracle.sol"; import {LibWellMinting} from "../../libraries/Minting/LibWellMinting.sol"; @@ -74,9 +74,25 @@ contract WellPrice { .mul(2) .div(PRICE_PRECISION); - pool.deltaB = BEANSTALK.poolDeltaB(wellAddress); + pool.deltaB = getDeltaB(wellAddress, wellTokens, wellBalances); pool.lpUsd = pool.liquidity.mul(WELL_DECIMALS).div(IERC20(wellAddress).totalSupply()); pool.lpBdv = BEANSTALK.bdv(wellAddress, WELL_DECIMALS); } + function getDeltaB(address well, IERC20[] memory tokens, uint256[] memory reserves) internal view returns (int256 deltaB) { + Call memory wellFunction = IWell(well).wellFunction(); + (uint256[] memory ratios, uint256 beanIndex, bool success) = LibWell.getRatiosAndBeanIndex(tokens); + // If the USD Oracle oracle call fails, we can't compute deltaB + if(!success) return 0; + + uint256 beansAtPeg = IBeanstalkWellFunction(wellFunction.target).calcReserveAtRatioLiquidity( + reserves, + beanIndex, + ratios, + wellFunction.data + ); + + deltaB = int256(beansAtPeg) - int256(reserves[beanIndex]); + } + } diff --git a/protocol/utils/well.js b/protocol/utils/well.js index 8d6fce4b9e..8ce3638fdd 100644 --- a/protocol/utils/well.js +++ b/protocol/utils/well.js @@ -100,7 +100,7 @@ async function deployWell(tokens, verbose = false, salt = ethers.constants.HashZ if (verbose) console.log("Deployed Aquifer", aquifer.address); const wellFunction = await deployWellContract('ConstantProduct2'); if (verbose) console.log("Deployed Well Function", wellFunction.address); - const pump = await deployGeoEmaAndCumSmaPump() + const pump = await deployMultiFlowPump() if (verbose) console.log("Deployed Pump", pump.address); const immutableData = await encodeWellImmutableData( @@ -205,8 +205,8 @@ async function deployMockPump() { return await ethers.getContractAt('MockPump', BEANSTALK_PUMP) } -async function deployGeoEmaAndCumSmaPump() { - pump = await (await getWellContractFactory('GeoEmaAndCumSmaPump')).deploy( +async function deployMultiFlowPump() { + pump = await (await getWellContractFactory('MultiFlowPump')).deploy( '0x3ffe0000000000000000000000000000', // 0.5 '0x3ffd555555555555553cbcd83d925070', // 0.333333333333333333 12, @@ -218,7 +218,7 @@ async function deployGeoEmaAndCumSmaPump() { BEANSTALK_PUMP, await ethers.provider.getCode(pump.address), ]); - return await getWellContractAt('GeoEmaAndCumSmaPump', BEANSTALK_PUMP) + return await getWellContractAt('MultiFlowPump', BEANSTALK_PUMP) } async function deployMockWell() { @@ -229,7 +229,7 @@ async function deployMockWell() { let well = await (await ethers.getContractFactory('MockSetComponentsWell', await getWellDeployer())).deploy() await well.deployed() - pump = await deployGeoEmaAndCumSmaPump() + pump = await deployMultiFlowPump() await well.setPumps([[pump.address, '0x']]) await well.setWellFunction([wellFunction.address, '0x'])