Skip to content

Commit

Permalink
Expand positions to 208 bits to allow custom data storage
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 9, 2023
1 parent 13f702c commit 03139dc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions core/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
BorrowerGasTest:test_addMargin() (gas: 16203)
BorrowerGasTest:test_borrow() (gas: 108518)
BorrowerGasTest:test_getUniswapPositions() (gas: 5277)
BorrowerGasTest:test_modify() (gas: 80102)
BorrowerGasTest:test_modifyWithAnte() (gas: 86579)
BorrowerGasTest:test_repay() (gas: 63218)
BorrowerGasTest:test_uniswapDepositInBorrower() (gas: 238461)
BorrowerGasTest:test_uniswapDepositStandard() (gas: 167536)
BorrowerGasTest:test_uniswapWithdraw() (gas: 146005)
BorrowerGasTest:test_withdraw() (gas: 103652)
BorrowerGasTest:test_addMargin() (gas: 16225)
BorrowerGasTest:test_borrow() (gas: 108138)
BorrowerGasTest:test_getUniswapPositions() (gas: 5299)
BorrowerGasTest:test_modify() (gas: 79744)
BorrowerGasTest:test_modifyWithAnte() (gas: 86221)
BorrowerGasTest:test_repay() (gas: 62828)
BorrowerGasTest:test_uniswapDepositInBorrower() (gas: 238102)
BorrowerGasTest:test_uniswapDepositStandard() (gas: 167581)
BorrowerGasTest:test_uniswapWithdraw() (gas: 145719)
BorrowerGasTest:test_withdraw() (gas: 103294)
FactoryGasTest:test_createBorrower() (gas: 137605)
FactoryGasTest:test_createMarket() (gas: 3839024)
FactoryGasTest:test_createMarket() (gas: 3835807)
LenderGasTest:test_accrueInterest() (gas: 46092)
LenderGasTest:test_borrow() (gas: 40856)
LenderGasTest:test_deposit() (gas: 53444)
LenderGasTest:test_depositWithCourier() (gas: 53590)
LenderGasTest:test_redeem() (gas: 53136)
LenderGasTest:test_redeemWithCourier() (gas: 83547)
LenderGasTest:test_repay() (gas: 44796)
LiquidatorGasTest:test_noCallbackOneAsset() (gas: 51060)
LiquidatorGasTest:test_noCallbackTwoAssets() (gas: 59263)
LiquidatorGasTest:test_noCallbackTwoAssetsAndUniswapPosition() (gas: 93401)
LiquidatorGasTest:test_warn() (gas: 31890)
LiquidatorGasTest:test_withCallbackAndSwap() (gas: 133092)
LiquidatorGasTest:test_noCallbackOneAsset() (gas: 51109)
LiquidatorGasTest:test_noCallbackTwoAssets() (gas: 59312)
LiquidatorGasTest:test_noCallbackTwoAssetsAndUniswapPosition() (gas: 93440)
LiquidatorGasTest:test_warn() (gas: 31939)
LiquidatorGasTest:test_withCallbackAndSwap() (gas: 133185)
VolatilityGasTest:test_consult() (gas: 43075)
VolatilityGasTest:test_updateNoBinarySearch() (gas: 145980)
16 changes: 8 additions & 8 deletions core/src/Borrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface IManager {
* `Positions.extract`
* @return Updated positions, encoded using `Positions.zip`. Return 0 if you don't wish to make any changes.
*/
function callback(bytes calldata data, address owner, uint144 positions) external returns (uint144);
function callback(bytes calldata data, address owner, uint208 positions) external returns (uint208);
}

/// @title Borrower
Expand Down Expand Up @@ -76,10 +76,10 @@ contract Borrower is IUniswapV3MintCallback {
InModifyCallback
}

uint256 private constant SLOT0_MASK_POSITIONS = 0x0000000000000000000000000000ffffffffffffffffffffffffffffffffffff;
uint256 private constant SLOT0_MASK_UNLEASH = 0x00ffffffffffffffffffffffffff000000000000000000000000000000000000;
uint256 private constant SLOT0_MASK_STATE = 0x7f00000000000000000000000000000000000000000000000000000000000000;
uint256 private constant SLOT0_DIRT = 1 << 255;
uint256 private constant SLOT0_MASK_POSITIONS = 0x000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffff;
uint256 private constant SLOT0_MASK_UNLEASH = 0x00ffffffffff0000000000000000000000000000000000000000000000000000; // prettier-ignore
uint256 private constant SLOT0_MASK_STATE = 0x7f00000000000000000000000000000000000000000000000000000000000000; // prettier-ignore
uint256 private constant SLOT0_DIRT = 0x8000000000000000000000000000000000000000000000000000000000000000; // prettier-ignore

/// @notice The factory that created this contract
Factory public immutable FACTORY;
Expand Down Expand Up @@ -164,7 +164,7 @@ contract Borrower is IUniswapV3MintCallback {
require(!BalanceSheet.isHealthy(prices, assets, liabilities0, liabilities1), "Aloe: healthy");
}

slot0 = slot0_ | ((block.timestamp + LIQUIDATION_GRACE_PERIOD) << 144);
slot0 = slot0_ | ((block.timestamp + LIQUIDATION_GRACE_PERIOD) << 208);
emit Warn();
}

Expand Down Expand Up @@ -246,7 +246,7 @@ contract Borrower is IUniswapV3MintCallback {
}

if (shouldSwap) {
uint256 unleashTime = (slot0_ & SLOT0_MASK_UNLEASH) >> 144;
uint256 unleashTime = (slot0_ & SLOT0_MASK_UNLEASH) >> 208;
require(0 < unleashTime && unleashTime < block.timestamp, "Aloe: grace");

incentive1 /= strain;
Expand Down Expand Up @@ -299,7 +299,7 @@ contract Borrower is IUniswapV3MintCallback {

slot0 = slot0_ | (uint256(State.InModifyCallback) << 248);
{
uint144 positions = callee.callback(data, msg.sender, uint144(slot0_));
uint208 positions = callee.callback(data, msg.sender, uint208(slot0_));
assembly ("memory-safe") {
// Equivalent to `if (positions > 0) slot0_ = positions`
slot0_ := or(positions, mul(slot0_, iszero(positions)))
Expand Down
4 changes: 2 additions & 2 deletions core/test/Borrower.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {VolatilityOracle} from "src/VolatilityOracle.sol";
import {FatFactory} from "./Utils.sol";

contract ReenteringManager is IManager {
function callback(bytes calldata data, address, uint144) external override returns (uint144) {
function callback(bytes calldata data, address, uint208) external override returns (uint208) {
(bool success, ) = msg.sender.call(data);
require(success);
return 0;
Expand Down Expand Up @@ -576,7 +576,7 @@ contract BorrowerTest is Test, IManager, IUniswapV3SwapCallback {
if (amount1Delta > 0) deal(address(asset1), msg.sender, asset1.balanceOf(msg.sender) + uint256(amount1Delta));
}

function callback(bytes calldata data, address, uint144) external returns (uint144) {
function callback(bytes calldata data, address, uint208) external returns (uint208) {
Borrower account_ = Borrower(payable(msg.sender));

(uint256 amount0, uint256 amount1, bool withdraw) = abi.decode(data, (uint256, uint256, bool));
Expand Down
2 changes: 1 addition & 1 deletion core/test/Liquidator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ contract BorrowerLiquidationsTest is Test, IManager, ILiquidator {
}

// IManager
function callback(bytes calldata data, address, uint144) external returns (uint144 positions) {
function callback(bytes calldata data, address, uint208) external returns (uint208 positions) {
require(msg.sender == address(account));

(Action action, uint256 amount0, uint256 amount1) = abi.decode(data, (Action, uint256, uint256));
Expand Down
2 changes: 1 addition & 1 deletion core/test/gas/BorrowerGas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ contract BorrowerGasTest is Test, IManager {
UNI_WITHDRAW
}

function callback(bytes calldata data, address, uint144) external returns (uint144 positions) {
function callback(bytes calldata data, address, uint208) external returns (uint208 positions) {
require(msg.sender == address(account));

(Action action, uint256 amount0, uint256 amount1) = abi.decode(data, (Action, uint256, uint256));
Expand Down
2 changes: 1 addition & 1 deletion core/test/gas/LiquidatorGas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ contract LiquidatorGasTest is Test, IManager, ILiquidator {
}

// IManager
function callback(bytes calldata data, address, uint144) external returns (uint144 positions) {
function callback(bytes calldata data, address, uint208) external returns (uint208 positions) {
require(msg.sender == address(account));

(Action action, uint256 amount0, uint256 amount1) = abi.decode(data, (Action, uint256, uint256));
Expand Down

0 comments on commit 03139dc

Please sign in to comment.