Skip to content

Instantly share code, notes, and snippets.

@bzpassersby
Created July 7, 2023 16:52
Show Gist options
  • Select an option

  • Save bzpassersby/bae15f0dec2ed656758ff468b734ec07 to your computer and use it in GitHub Desktop.

Select an option

Save bzpassersby/bae15f0dec2ed656758ff468b734ec07 to your computer and use it in GitHub Desktop.
Single hardcoded cap used for multiple tokens in pumps causing some assets to be more stale, while having no effects on other stable assets
/**
* SPDX-License-Identifier: MIT
*
*/
pragma solidity ^0.8.17;
import {console, TestHelper} from "test/TestHelper.sol";
import {ABDKMathQuad, MultiFlowPump} from "src/pumps/MultiFlowPump.sol";
import {MockReserveWell} from "mocks/wells/MockReserveWell.sol";
import {from18, to18} from "test/pumps/PumpHelpers.sol";
import {log2, powu, UD60x18, wrap, unwrap} from "prb/math/UD60x18.sol";
import {exp2, log2, powu, UD60x18, wrap, unwrap, uUNIT} from "prb/math/UD60x18.sol";
contract PumpHardCapTest is TestHelper, MultiFlowPump {
using ABDKMathQuad for bytes16;
using ABDKMathQuad for uint256;
MultiFlowPump pump;
MockReserveWell mWell;
uint256[] b = new uint256[](2);
constructor()
MultiFlowPump(
from18(0.5e18),
from18(0.333333333333333333e18),
12,
from18(0.9e18)
)
{}
function setUp() public {
mWell = new MockReserveWell();
initUser();
pump = new MultiFlowPump(
from18(0.5e18),
from18(0.333333333333333333e18),
12,
from18(0.9e18)
);
}
function test_HardCap() public {
uint256[] memory initReserves = new uint256[](4);
//initiate for mWell and pump
initReserves[0] = 100e8; //wBTC
initReserves[1] = 1600e18; //wETH
initReserves[2] = 99000e4; //USDC
initReserves[3] = 98000e4; //USDT
mWell.update(address(pump), initReserves, new bytes(0));
increaseTime(12);
//Reserve update
uint256[] memory updateReserves = new uint256[](4);
updateReserves[0] = 160e8; //wBTC
updateReserves[1] = 1000e18; //wETH
updateReserves[2] = 96000e4; //USDC
updateReserves[3] = 101000e4; //USDT
mWell.update(address(pump), updateReserves, new bytes(0));
// lastReserves0 reflects initReserves[i]
uint256[] memory lastReserves0 = pump.readLastReserves(address(mWell));
increaseTime(12);
mWell.update(address(pump), updateReserves, new bytes(0));
// lastReserves1 reflects 1st reserve update
uint256[] memory lastReserves1 = pump.readLastReserves(address(mWell));
assertEq(
((lastReserves1[0] - lastReserves0[0]) * 1000) / lastReserves0[0],
500
); //wBTC: 50% reserve change versus 60% reserve change in well
console.log(lastReserves1[0]); //14999999999
assertEq(
((lastReserves0[1] - lastReserves1[1]) * 1000) / lastReserves0[1],
333
); //wETH: 33% reserve change versus 37.5% reserve change in well
console.log(lastReserves1[1]); //1066666666666666667199
assertApproxEqAbs(lastReserves1[2], 96000e4, 1); //USDC: reserve change matches well, 3% change decrease
assertApproxEqAbs(lastReserves1[3], 101000e4, 1); //USDT: reserve change matches well, 3% reserve increase
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment