Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/eth support 2 #160

Merged
merged 53 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0dc8e2b
test: add payable casting to hook address
clemlak Oct 16, 2024
0d15ec6
feat: add receive function
clemlak Oct 15, 2024
8416d1e
test: add receive test
clemlak Oct 16, 2024
cb9fa6d
fix: modifyLiquidity !isToken0 case
kinrezC Oct 15, 2024
24c5c0a
fix: valid constructor params test
kinrezC Oct 15, 2024
a25003e
build: add via_ir setting in Foundry config
clemlak Oct 16, 2024
3beb921
build: add new test workflows
clemlak Oct 16, 2024
bb6f203
build: merge all the test workflows together
clemlak Oct 16, 2024
85569bc
test: add usingEth, change test tokens to address type
clemlak Oct 16, 2024
f5fdc8a
test: remove useless casting
clemlak Oct 16, 2024
59669a2
test: add missing TestERC20 casting
clemlak Oct 16, 2024
8ce106c
test: wip just checking if tests are passing
clemlak Oct 16, 2024
1a44311
Merge branch 'main' into feat/eth-support-2
clemlak Oct 17, 2024
33c20f8
test: add buy and sell functions
clemlak Oct 17, 2024
1fab248
test: add Quoter, implement computeBuyAmountIn, fix buy
clemlak Oct 17, 2024
c0b016c
test: add approve in sell, fix price limit
clemlak Oct 17, 2024
4ac6b14
test: use buy and sell instead of swap, clean up imports
clemlak Oct 17, 2024
6b857fb
test: add assert descriptions, format file
clemlak Oct 17, 2024
5fd8f29
test: use buy and sell in test_rebalance_CollectsFeeFromAllSlugs
clemlak Oct 17, 2024
2802f11
test: use buy and sell in test_rebalance_FullFlow
clemlak Oct 17, 2024
8251b74
test: use buy in testPriceDiscoverySlug_LastEpoch
clemlak Oct 17, 2024
2055677
test: use buy and sell in test_rebalance_MaxDutchAuction
clemlak Oct 17, 2024
5b0865b
test: use buy to swap
clemlak Oct 17, 2024
3234802
test: use buy instead of swap in test_rebalance_RelativeDutchAuction
clemlak Oct 18, 2024
43fb68b
test: use buy and sell instead of swap in test_rebalance_ExtremeOvers…
clemlak Oct 18, 2024
698dbe4
test: use buy and sell instead of swap in test_rebalance_LowerSlug_Su…
clemlak Oct 18, 2024
3868803
test: use buy and sell instead of swap in test_rebalance_LowerSlug_In…
clemlak Oct 18, 2024
e2379ee
test: use buy instead of swap in test_rebalance_OversoldCase
clemlak Oct 18, 2024
783403c
test: use buy instead of swap in test_rebalance_PriceDiscoverySlug_Re…
clemlak Oct 18, 2024
a7320d2
test: use buy instead of swap in test_rebalance_UpperSlug_Undersold
clemlak Oct 18, 2024
95172e4
test: fix buy negative mintAmount
clemlak Oct 18, 2024
74e4ca1
test: fix sell function
clemlak Oct 18, 2024
e2c4c81
chore: add NatSpec to buy and sell
clemlak Oct 18, 2024
8b6fe99
fix: useApproxEqAbs on currentTick == upperSlug.tickLower
kinrezC Oct 18, 2024
0672fab
test: fix tests using assertApproxEqAbs
clemlak Oct 21, 2024
411151f
test: use isToken0 to fix broken tests
clemlak Oct 21, 2024
a26577a
test: add buy / sell exact in / out
clemlak Oct 22, 2024
c4007a5
test: attempt to fix more tests using isToken0 condition
clemlak Oct 22, 2024
6addf5a
test: add Quoter to DopplerHandler
clemlak Oct 22, 2024
0e82468
test: add buy and sell functions to DopplerHandler
clemlak Oct 22, 2024
5abc750
test: return values in buy and sell functions
clemlak Oct 22, 2024
fb99771
test: add CustomRouter
clemlak Oct 22, 2024
b1b5684
test: add mintAndBuy, remove minting from buy
clemlak Oct 22, 2024
b3d7ed4
test: remove buy and sell util functions, implement buyExactAmountIn
clemlak Oct 22, 2024
68e8762
test: add custom router to BaseTest
clemlak Oct 22, 2024
926bcc2
chore: fix typo in NatSpec
clemlak Oct 22, 2024
e925a5a
test: update invariant tests setup
clemlak Oct 22, 2024
ae050e0
Merge branch 'main' of github.com:whetstoneresearch/doppler-smart-con…
kinrezC Oct 22, 2024
8f271dd
fix tests
kinrezC Oct 22, 2024
6fe9e8d
Merge branch 'main' of github.com:whetstoneresearch/doppler-smart-con…
kinrezC Oct 22, 2024
bd24900
rm spurious slugvis
kinrezC Oct 22, 2024
0c358e1
Fix !isToken0 && fee != 0 && protocolFee != 0 test cases (#148)
kinrezC Oct 23, 2024
e88e188
Revert swap utils (#152)
kinrezC Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,41 @@ jobs:
forge test -vvv --via-ir
id: test0

- name: Run forge tests isToken0 (true) fee (300) protocolFee (0)
- name: Run forge tests isToken0 (true) fee (30) protocolFee (0)
run: |
export IS_TOKEN_0=TRUE
export FEE=300
export FEE=30
forge test -vvv --via-ir
id: test1

- name: Run forge tests isToken0 (true) fee (300) protocolFee (50)
- name: Run forge tests isToken0 (true) fee (30) protocolFee (50)
run: |
export IS_TOKEN_0=TRUE
export FEE=300
export FEE=30
export PROTOCOL_FEE=50
forge test -vvv --via-ir
id: test2

- name: Run forge tests with usingEth (true)
run: |
export USING_ETH=TRUE
export FEE=0
export PROTOCOL_FEE=0
forge test -vvv --via-ir
id: test3

- name: Run forge tests with usingEth (true) fee (30) protocolFee (0)
run: |
export USING_ETH=TRUE
export FEE=30
export PROTOCOL_FEE=0
forge test -vvv --via-ir
id: test4

- name: Run forge tests with usingEth (true) fee (30) protocolFee (50)
run: |
export USING_ETH=TRUE
export FEE=30
export PROTOCOL_FEE=50
forge test -vvv --via-ir
id: test5
33 changes: 17 additions & 16 deletions src/Doppler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ contract Doppler is BaseHook {
bool immutable isToken0; // whether token0 is the token being sold (true) or token1 (false)
uint256 immutable numPDSlugs; // number of price discovery slugs

receive() external payable {}

constructor(
IPoolManager _poolManager,
PoolKey memory _poolKey,
Expand Down Expand Up @@ -216,11 +218,13 @@ contract Doppler is BaseHook {
for (uint256 i; i < numPDSlugs + 1; ++i) {
delete positions[bytes32(uint256(2 + i))];
}
} else {
revert InvalidSwapAfterMaturitySufficientProceeds();
}
}

if (block.timestamp > endingTime && !insufficientProceeds) {
revert InvalidSwapAfterMaturitySufficientProceeds();
}

if (!insufficientProceeds) {
_rebalance(key);
} else if (isToken0) {
Expand All @@ -230,7 +234,7 @@ contract Doppler is BaseHook {
}
} else {
if (swapParams.zeroForOne == true) {
revert InvalidSwapAfterMaturitySufficientProceeds();
revert InvalidSwapAfterMaturityInsufficientProceeds();
}
}

Expand Down Expand Up @@ -427,7 +431,8 @@ contract Doppler is BaseHook {

SlugData memory lowerSlug =
_computeLowerSlugData(key, requiredProceeds, numeraireAvailable, totalTokensSold_, tickLower, currentTick);
(SlugData memory upperSlug, uint256 assetRemaining) = _computeUpperSlugData(key, totalTokensSold_, currentTick, assetAvailable);
(SlugData memory upperSlug, uint256 assetRemaining) =
_computeUpperSlugData(key, totalTokensSold_, currentTick, assetAvailable);
SlugData[] memory priceDiscoverySlugs =
_computePriceDiscoverySlugsData(key, upperSlug, tickUpper, assetRemaining);

Expand Down Expand Up @@ -726,8 +731,8 @@ contract Doppler is BaseHook {
(BalanceDelta positionDeltas, BalanceDelta feesAccrued) = poolManager.modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({
tickLower: lastEpochPositions[i].tickLower,
tickUpper: lastEpochPositions[i].tickUpper,
tickLower: isToken0 ? lastEpochPositions[i].tickLower : lastEpochPositions[i].tickUpper,
tickUpper: isToken0 ? lastEpochPositions[i].tickUpper : lastEpochPositions[i].tickLower,
liquidityDelta: -int128(lastEpochPositions[i].liquidity),
salt: bytes32(uint256(lastEpochPositions[i].salt))
}),
Expand Down Expand Up @@ -763,12 +768,8 @@ contract Doppler is BaseHook {
poolManager.modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({
tickLower: newPositions[i].tickLower < newPositions[i].tickUpper
? newPositions[i].tickLower
: newPositions[i].tickUpper,
tickUpper: newPositions[i].tickUpper > newPositions[i].tickLower
? newPositions[i].tickUpper
: newPositions[i].tickLower,
tickLower: isToken0 ? newPositions[i].tickLower : newPositions[i].tickUpper,
tickUpper: isToken0 ? newPositions[i].tickUpper : newPositions[i].tickLower,
liquidityDelta: int128(newPositions[i].liquidity),
salt: bytes32(uint256(newPositions[i].salt))
}),
Expand Down Expand Up @@ -824,8 +825,8 @@ contract Doppler is BaseHook {
(BalanceDelta callerDelta,) = poolManager.modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({
tickLower: upperSlug.tickLower,
tickUpper: upperSlug.tickUpper,
tickLower: isToken0 ? upperSlug.tickLower : upperSlug.tickUpper,
tickUpper: isToken0 ? upperSlug.tickUpper : upperSlug.tickLower,
liquidityDelta: int128(upperSlug.liquidity),
salt: UPPER_SLUG_SALT
}),
Expand All @@ -839,8 +840,8 @@ contract Doppler is BaseHook {
(BalanceDelta callerDelta,) = poolManager.modifyLiquidity(
key,
IPoolManager.ModifyLiquidityParams({
tickLower: priceDiscoverySlugs[i].tickLower,
tickUpper: priceDiscoverySlugs[i].tickUpper,
tickLower: isToken0 ? priceDiscoverySlugs[i].tickLower : priceDiscoverySlugs[i].tickUpper,
tickUpper: isToken0 ? priceDiscoverySlugs[i].tickUpper : priceDiscoverySlugs[i].tickLower,
liquidityDelta: int128(priceDiscoverySlugs[i].liquidity),
salt: bytes32(uint256(3 + i))
}),
Expand Down
Loading