Skip to content

Commit

Permalink
Add comment explaining slot0
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 11, 2023
1 parent 03139dc commit 07f14a4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
48 changes: 23 additions & 25 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ jobs:
# echo "## Lint result" >> $GITHUB_STEP_SUMMARY
# echo "✅ Passed" >> $GITHUB_STEP_SUMMARY

build:
test-core:
name: Test core
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
Expand All @@ -58,17 +59,30 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build core
- name: "Generate a fuzz seed that changes weekly to avoid burning through RPC allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV
- name: "Install Node.js"
uses: "actions/setup-node@v3"
with:
cache: "yarn"
node-version: "lts/*"
- name: Test core
env:
CHECK_CONSTANTS: true
CHECK_STORAGE_LAYOUTS: true
CHECK_LEDGER_PURITY: true
CHECK_FORGE_TESTS: true
CHECK_COVERAGE: true
run: |
cd "${GITHUB_WORKSPACE}/core"
forge build
- name: Build periphery
run: |
cd "${GITHUB_WORKSPACE}/periphery"
forge build
echo "## Testing core" >> $GITHUB_STEP_SUMMARY
./test.sh
test:
needs: ["build"]
test-periphery:
name: Test periphery
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v3
Expand All @@ -78,27 +92,11 @@ jobs:
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: "Install Node.js"
uses: "actions/setup-node@v3"
with:
cache: "yarn"
node-version: "lts/*"
- name: "Generate a fuzz seed that changes weekly to avoid burning through RPC allowance"
run: >
echo "FOUNDRY_FUZZ_SEED=$(
echo $(($EPOCHSECONDS - $EPOCHSECONDS % 604800))
)" >> $GITHUB_ENV
- name: Test core
env:
CHECK_CONSTANTS: true
CHECK_STORAGE_LAYOUTS: true
CHECK_LEDGER_PURITY: true
CHECK_FORGE_TESTS: true
CHECK_COVERAGE: true
run: |
cd "${GITHUB_WORKSPACE}/core"
echo "## Testing core" >> $GITHUB_STEP_SUMMARY
./test.sh
- name: Test periphery
run: |
cd "${GITHUB_WORKSPACE}/periphery"
Expand Down
9 changes: 9 additions & 0 deletions core/src/Borrower.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ contract Borrower is IUniswapV3MintCallback {
/// @notice The lender of `TOKEN1`
Lender public immutable LENDER1;

/**
* @notice The `Borrower`'s only mutable storage. Lowest 144 bits store the lower/upper bounds of up to 3 Uniswap
* positions, encoded by `Positions.zip`. Next 64 bits are unused within the `Borrower` and available to users as
* "free" storage - no additional sstore's. These 208 bits (144 + 64) are passed to `IManager.callback`, and get
* updated when the callback returns a non-zero value. The next 40 bits are either 0 or `unleashLiquidationTime`,
* as explained in the `Warn` event docs. The highest 8 bits represent the current `State` enum, plus 128. We add
* 128 (i.e. set the highest bit to 1) so that the slot is always non-zero, even in the absence of Uniswap
* positions - this saves gas.
*/
uint256 public slot0;

modifier onlyInModifyCallback() {
Expand Down
6 changes: 6 additions & 0 deletions core/test/Borrower.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ contract BorrowerTest is Test, IManager, IUniswapV3SwapCallback {
vm.createSelectFork(vm.rpcUrl("anvil"));
}

function test_stateMaskIsAddition(uint8 state) external {
state = uint8(bound(state, 0, 127));
assertEq(state | 0x80, state + 128);
assertEq((state | 0x80) & 0x7f, state);
}

function test_permissionsModify(
address owner,
address caller,
Expand Down

0 comments on commit 07f14a4

Please sign in to comment.