Skip to content

Commit

Permalink
fix deltaB function
Browse files Browse the repository at this point in the history
  • Loading branch information
publiuss committed Aug 6, 2023
1 parent c2543e2 commit d9c9dfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
20 changes: 18 additions & 2 deletions protocol/contracts/ecosystem/price/WellPrice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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]);
}

}
10 changes: 5 additions & 5 deletions protocol/utils/well.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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'])
Expand Down

0 comments on commit d9c9dfd

Please sign in to comment.