Skip to content

Commit

Permalink
update line length formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackCoffee-cyber committed Oct 16, 2024
1 parent 9ed85b3 commit d75e242
Show file tree
Hide file tree
Showing 39 changed files with 331 additions and 111 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beanstalk/wells",
"version": "1.3.0",
"version": "1.3.1",
"description": "A [{Well}](/src/Well.sol) is a constant function AMM that allows the provisioning of liquidity into a single pooled on-chain liquidity position.",
"main": "index.js",
"directories": {
Expand Down
4 changes: 3 additions & 1 deletion script/deploy/helpers/Logger.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {console} from "forge-std/console.sol";
import {Well} from "src/Well.sol";

library logger {
function logWell(Well well) public view {
function logWell(
Well well
) public view {
console.log("\nWELL:", address(well));
console.log("Name \t", well.name());
console.log("Symbol\t", well.symbol());
Expand Down
20 changes: 15 additions & 5 deletions src/Well.sol
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,9 @@ contract Well is ERC20PermitUpgradeable, IWell, IWellErrors, ReentrancyGuardUpgr
}
}

function getShiftOut(IERC20 tokenOut) external view readOnlyNonReentrant returns (uint256 amountOut) {
function getShiftOut(
IERC20 tokenOut
) external view readOnlyNonReentrant returns (uint256 amountOut) {
IERC20[] memory _tokens = tokens();
uint256 tokensLength = _tokens.length;
uint256[] memory reserves = new uint256[](tokensLength);
Expand Down Expand Up @@ -674,7 +676,9 @@ contract Well is ERC20PermitUpgradeable, IWell, IWellErrors, ReentrancyGuardUpgr
/**
* @dev Transfer excess tokens held by the Well to `recipient`.
*/
function skim(address recipient) external nonReentrant returns (uint256[] memory skimAmounts) {
function skim(
address recipient
) external nonReentrant returns (uint256[] memory skimAmounts) {
IERC20[] memory _tokens = tokens();
uint256 tokensLength = _tokens.length;
uint256[] memory reserves = _getReserves(tokensLength);
Expand All @@ -694,7 +698,9 @@ contract Well is ERC20PermitUpgradeable, IWell, IWellErrors, ReentrancyGuardUpgr
/**
* @dev Gets the Well's token reserves by reading from byte storage.
*/
function _getReserves(uint256 _numberOfTokens) internal view returns (uint256[] memory reserves) {
function _getReserves(
uint256 _numberOfTokens
) internal view returns (uint256[] memory reserves) {
reserves = LibBytes.readUint128(RESERVES_STORAGE_SLOT, _numberOfTokens);
}

Expand All @@ -717,7 +723,9 @@ contract Well is ERC20PermitUpgradeable, IWell, IWellErrors, ReentrancyGuardUpgr
* @dev Fetches the current token reserves of the Well and updates the Pumps.
* Typically called before an operation that modifies the Well's reserves.
*/
function _updatePumps(uint256 _numberOfTokens) internal returns (uint256[] memory reserves) {
function _updatePumps(
uint256 _numberOfTokens
) internal returns (uint256[] memory reserves) {
reserves = _getReserves(_numberOfTokens);

uint256 _numberOfPumps = numberOfPumps();
Expand Down Expand Up @@ -861,7 +869,9 @@ contract Well is ERC20PermitUpgradeable, IWell, IWellErrors, ReentrancyGuardUpgr
/**
* @dev Reverts if the deadline has passed.
*/
modifier expire(uint256 deadline) {
modifier expire(
uint256 deadline
) {
if (block.timestamp > deadline) {
revert Expired();
}
Expand Down
8 changes: 6 additions & 2 deletions src/WellUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ contract WellUpgradeable is Well, UUPSUpgradeable, OwnableUpgradeable {
* @notice Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an ERC1167 minimal proxy from an aquifier, pointing to a well implmentation.
*/
function _authorizeUpgrade(address newImplementation) internal view override onlyOwner {
function _authorizeUpgrade(
address newImplementation
) internal view override onlyOwner {
// verify the function is called through a delegatecall.
require(address(this) != ___self, "Function must be called through delegatecall");

Expand Down Expand Up @@ -96,7 +98,9 @@ contract WellUpgradeable is Well, UUPSUpgradeable, OwnableUpgradeable {
* @dev `upgradeTo` was modified to support ERC-1167 minimal proxies
* cloned (Bored) by an Aquifer.
*/
function upgradeTo(address newImplementation) public override {
function upgradeTo(
address newImplementation
) public override {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
Expand Down
8 changes: 6 additions & 2 deletions src/functions/StableLUT/Stable2LUT1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ contract Stable2LUT1 is ILookupTable {
* @notice Returns the estimated range of reserve ratios for a given price,
* assuming one token reserve remains constant.
*/
function getRatiosFromPriceLiquidity(uint256 price) external pure returns (PriceData memory) {
function getRatiosFromPriceLiquidity(
uint256 price
) external pure returns (PriceData memory) {
if (price < 1.006758e6) {
if (price < 0.885627e6) {
if (price < 0.59332e6) {
Expand Down Expand Up @@ -737,7 +739,9 @@ contract Stable2LUT1 is ILookupTable {
* @notice Returns the estimated range of reserve ratios for a given price,
* assuming the pool liquidity remains constant.
*/
function getRatiosFromPriceSwap(uint256 price) external pure returns (PriceData memory) {
function getRatiosFromPriceSwap(
uint256 price
) external pure returns (PriceData memory) {
if (price < 0.993344e6) {
if (price < 0.834426e6) {
if (price < 0.718073e6) {
Expand Down
4 changes: 3 additions & 1 deletion src/interfaces/IAquifer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ interface IAquifer {
* @dev Always verify that a Well was deployed by a trusted Aquifer using a trusted implementation before using.
* If `wellImplementation == address(0)`, then the Aquifer did not deploy the Well.
*/
function wellImplementation(address well) external view returns (address implementation);
function wellImplementation(
address well
) external view returns (address implementation);
}
8 changes: 6 additions & 2 deletions src/interfaces/ILookupTable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ interface ILookupTable {
uint256 precision;
}

function getRatiosFromPriceLiquidity(uint256) external view returns (PriceData memory);
function getRatiosFromPriceSwap(uint256) external view returns (PriceData memory);
function getRatiosFromPriceLiquidity(
uint256
) external view returns (PriceData memory);
function getRatiosFromPriceSwap(
uint256
) external view returns (PriceData memory);
function getAParameter() external view returns (uint256);
}
16 changes: 12 additions & 4 deletions src/interfaces/IWell.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ interface IWell {
* @param tokenOut The token to shift into
* @return amountOut The amount of `tokenOut` received
*/
function getShiftOut(IERC20 tokenOut) external returns (uint256 amountOut);
function getShiftOut(
IERC20 tokenOut
) external returns (uint256 amountOut);

//////////////////// ADD LIQUIDITY ////////////////////

Expand Down Expand Up @@ -279,7 +281,9 @@ interface IWell {
* @param tokenAmountsIn The amount of each token to add; MUST match the indexing of {Well.tokens}
* @return lpAmountOut The amount of LP tokens received
*/
function getAddLiquidityOut(uint256[] memory tokenAmountsIn) external view returns (uint256 lpAmountOut);
function getAddLiquidityOut(
uint256[] memory tokenAmountsIn
) external view returns (uint256 lpAmountOut);

//////////////////// REMOVE LIQUIDITY: BALANCED ////////////////////

Expand All @@ -303,7 +307,9 @@ interface IWell {
* @param lpAmountIn The amount of LP tokens to burn
* @return tokenAmountsOut The amount of each underlying token received
*/
function getRemoveLiquidityOut(uint256 lpAmountIn) external view returns (uint256[] memory tokenAmountsOut);
function getRemoveLiquidityOut(
uint256 lpAmountIn
) external view returns (uint256[] memory tokenAmountsOut);

//////////////////// REMOVE LIQUIDITY: ONE TOKEN ////////////////////

Expand Down Expand Up @@ -388,7 +394,9 @@ interface IWell {
* @return skimAmounts The amount of each token skimmed
* @dev No deadline is needed since this function does not use the user's assets.
*/
function skim(address recipient) external returns (uint256[] memory skimAmounts);
function skim(
address recipient
) external returns (uint256[] memory skimAmounts);

/**
* @notice Gets the reserves of each token held by the Well.
Expand Down
12 changes: 9 additions & 3 deletions src/libraries/LibContractInfo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ library LibContractInfo {
* @return symbol The symbol of the contract
* @dev if the contract does not have a symbol function, the first 4 bytes of the address are returned
*/
function getSymbol(address _contract) internal view returns (string memory symbol) {
function getSymbol(
address _contract
) internal view returns (string memory symbol) {
(bool success, bytes memory data) = _contract.staticcall(abi.encodeWithSignature("symbol()"));
symbol = new string(4);
if (success) {
Expand All @@ -31,7 +33,9 @@ library LibContractInfo {
* @return name The name of the contract
* @dev if the contract does not have a name function, the first 8 bytes of the address are returned
*/
function getName(address _contract) internal view returns (string memory name) {
function getName(
address _contract
) internal view returns (string memory name) {
(bool success, bytes memory data) = _contract.staticcall(abi.encodeWithSignature("name()"));
name = new string(8);
if (success) {
Expand All @@ -49,7 +53,9 @@ library LibContractInfo {
* @return decimals The decimals of the contract
* @dev if the contract does not have a decimals function, 18 is returned
*/
function getDecimals(address _contract) internal view returns (uint8 decimals) {
function getDecimals(
address _contract
) internal view returns (uint8 decimals) {
(bool success, bytes memory data) = _contract.staticcall(abi.encodeWithSignature("decimals()"));
decimals = success ? abi.decode(data, (uint8)) : 18; // default to 18 decimals
}
Expand Down
4 changes: 3 additions & 1 deletion src/libraries/LibMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ library LibMath {
* Implementation from: https://github.com/Gaussian-Process/solidity-sqrt/blob/main/src/FixedPointMathLib.sol
* based on https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol
*/
function sqrt(uint256 a) internal pure returns (uint256 z) {
function sqrt(
uint256 a
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let y := a // We start y at a, which will help us make our initial estimate.
Expand Down
4 changes: 3 additions & 1 deletion test/Stable2/Well.Stable2.RemoveLiquidity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ contract WellStable2RemoveLiquidityTest is LiquidityHelper {

/// @dev Fuzz test: EQUAL token reserves, BALANCED removal
/// The Well contains equal reserves of all underlying tokens before execution.
function test_removeLiquidity_fuzz(uint256 a0) public prank(user) {
function test_removeLiquidity_fuzz(
uint256 a0
) public prank(user) {
// Setup amounts of liquidity to remove
// NOTE: amounts may or may not match the maximum removable by `user`.
uint256[] memory amounts = new uint256[](2);
Expand Down
4 changes: 3 additions & 1 deletion test/Stable2/Well.Stable2.RemoveLiquidityOneToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ contract WellStable2RemoveLiquidityOneTokenTest is TestHelper {

/// @dev Fuzz test: EQUAL token reserves, IMBALANCED removal
/// The Well contains equal reserves of all underlying tokens before execution.
function testFuzz_removeLiquidityOneToken(uint256 a0) public prank(user) {
function testFuzz_removeLiquidityOneToken(
uint256 a0
) public prank(user) {
// Assume we're removing tokens[0]
uint256[] memory amounts = new uint256[](2);
amounts[0] = bound(a0, 1e18, 750e18);
Expand Down
12 changes: 9 additions & 3 deletions test/Stable2/Well.Stable2.Shift.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ contract WellStable2ShiftTest is TestHelper {
}

/// @dev Shift excess token0 into token1.
function testFuzz_shift(uint256 amount) public prank(user) {
function testFuzz_shift(
uint256 amount
) public prank(user) {
amount = bound(amount, 1, 1000e18);

// Transfer `amount` of token0 to the Well
Expand Down Expand Up @@ -67,7 +69,9 @@ contract WellStable2ShiftTest is TestHelper {
}

/// @dev Shift excess token0 into token0 (just transfers the excess token0 to the user).
function testFuzz_shift_tokenOut(uint256 amount) public prank(user) {
function testFuzz_shift_tokenOut(
uint256 amount
) public prank(user) {
amount = bound(amount, 1, 1000e18);

// Transfer `amount` of token0 to the Well
Expand Down Expand Up @@ -144,7 +148,9 @@ contract WellStable2ShiftTest is TestHelper {
checkInvariant(address(well));
}

function test_shift_fail_slippage(uint256 amount) public prank(user) {
function test_shift_fail_slippage(
uint256 amount
) public prank(user) {
amount = bound(amount, 1, 1000e18);

// Transfer `amount` of token0 to the Well
Expand Down
4 changes: 3 additions & 1 deletion test/Stable2/Well.Stable2.Skim.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ contract WellStable2SkimTest is TestHelper {
assertEq(wellBalance.tokens[1], 1000e18);
}

function testFuzz_skim(uint256[2] calldata amounts) public prank(user) {
function testFuzz_skim(
uint256[2] calldata amounts
) public prank(user) {
vm.assume(amounts[0] <= 800e18);
vm.assume(amounts[1] <= 800e18);

Expand Down
12 changes: 9 additions & 3 deletions test/Stable2/Well.Stable2.SwapFrom.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ contract WellStable2SwapFromTest is SwapHelper {
well.swapFrom(tokens[0], tokens[1], 0, 0, user, block.timestamp - 1);
}

function testFuzz_swapFrom(uint256 amountIn) public prank(user) {
function testFuzz_swapFrom(
uint256 amountIn
) public prank(user) {
amountIn = bound(amountIn, 0, tokens[0].balanceOf(user));

(Snapshot memory bef, SwapAction memory act) = beforeSwapFrom(0, 1, amountIn);
Expand All @@ -78,7 +80,9 @@ contract WellStable2SwapFromTest is SwapHelper {
checkStableSwapInvariant(address(well));
}

function testFuzz_swapAndRemoveAllLiq(uint256 amountIn) public {
function testFuzz_swapAndRemoveAllLiq(
uint256 amountIn
) public {
amountIn = bound(amountIn, 0, tokens[0].balanceOf(user));
vm.prank(user);
well.swapFrom(tokens[0], tokens[1], amountIn, 0, user, type(uint256).max);
Expand All @@ -91,7 +95,9 @@ contract WellStable2SwapFromTest is SwapHelper {
}

/// @dev Zero hysteresis: token0 -> token1 -> token0 gives the same result
function testFuzz_swapFrom_equalSwap(uint256 token0AmtIn) public prank(user) {
function testFuzz_swapFrom_equalSwap(
uint256 token0AmtIn
) public prank(user) {
vm.assume(token0AmtIn < tokens[0].balanceOf(user));
uint256 token1Out = well.swapFrom(tokens[0], tokens[1], token0AmtIn, 0, user, type(uint256).max);
uint256 token0Out = well.swapFrom(tokens[1], tokens[0], token1Out, 0, user, type(uint256).max);
Expand Down
12 changes: 9 additions & 3 deletions test/Stable2/Well.Stable2.SwapTo.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ contract WellStable2SwapToTest is SwapHelper {
assertEq(amountIn, 103_464_719_546_263_310_322); // ~3% slippage
}

function testFuzz_getSwapIn_revertIf_insufficientWellBalance(uint256 i) public prank(user) {
function testFuzz_getSwapIn_revertIf_insufficientWellBalance(
uint256 i
) public prank(user) {
IERC20[] memory _tokens = well.tokens();
Balances memory wellBalances = getBalances(address(well), well);
vm.assume(i < _tokens.length);
Expand Down Expand Up @@ -60,7 +62,9 @@ contract WellStable2SwapToTest is SwapHelper {
}

/// @dev tests assume 2 tokens in future we can extend for multiple tokens
function testFuzz_swapTo(uint256 amountOut) public prank(user) {
function testFuzz_swapTo(
uint256 amountOut
) public prank(user) {
// User has 1000 of each token
// Given current liquidity, swapping 1000 of one token gives 500 of the other
uint256 maxAmountIn = 1000 * 1e18;
Expand Down Expand Up @@ -100,7 +104,9 @@ contract WellStable2SwapToTest is SwapHelper {
}

/// @dev Zero hysteresis: token0 -> token1 -> token0 gives the same result
function testFuzz_swapTo_equalSwap(uint256 token0AmtOut) public prank(user) {
function testFuzz_swapTo_equalSwap(
uint256 token0AmtOut
) public prank(user) {
// assume amtOut is lower due to slippage
vm.assume(token0AmtOut < 500e18);
uint256 token1In = well.swapTo(tokens[0], tokens[1], 1000e18, token0AmtOut, user, type(uint256).max);
Expand Down
4 changes: 3 additions & 1 deletion test/SwapHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ contract SwapHelper is TestHelper {
return beforeSwapFrom(act);
}

function beforeSwapFrom(SwapAction memory act) internal returns (Snapshot memory, SwapAction memory) {
function beforeSwapFrom(
SwapAction memory act
) internal returns (Snapshot memory, SwapAction memory) {
Snapshot memory bef = _newSnapshot();

vm.expectEmit(true, true, true, true, address(well));
Expand Down
Loading

0 comments on commit d75e242

Please sign in to comment.