Skip to content

Add custom curve#70

Merged
alexkeating merged 46 commits intomainfrom
chore/more-cleanup
Feb 25, 2026
Merged

Add custom curve#70
alexkeating merged 46 commits intomainfrom
chore/more-cleanup

Conversation

@alexkeating
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread src/FixedFeeSwapMarket.sol Outdated
abi.decode(_hookParams, (int256, bool, uint256));
if (amountIn <= 0) revert FixedFeeSwap__SwapAmountCannotBeZero();
if (activeLiquidity == 0) revert FixedFeeSwap__NoActiveLiquidity();
if (currentPrice == 0) currentPrice = tickToPrice(currentTick);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the currentPrice == 0 condition here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Price initialization

Comment thread src/FixedFeeSwapMarket.sol Outdated
return Hooks.Permissions({
beforeInitialize: false,
afterInitialize: false,
beforeAddLiquidity: false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we said we want this to be true right?

Comment thread src/FixedFeeSwapMarket.sol Outdated
afterInitialize: false,
beforeAddLiquidity: false,
afterAddLiquidity: false,
beforeRemoveLiquidity: false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this

// want to make this better. Maturities may want
// to end at the same time.
constructor(
uint48 _lengthOfMarket,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a check for this so it's not 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a min market length check.

Comment thread src/FixedFeeSwapMarket.sol Outdated
function _scaledTimeElapsedWad() internal view returns (uint256) {
uint256 elapsed = block.timestamp - START_TIME;
if (elapsed == 0) revert FixedFeeSwap__TimeElapsedIsZero();
return (elapsed * WAD) / (MATURITY - START_TIME);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens at MATURITY? does this keep growing?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The market should close at or near maturity to avoid this, good callout

bytes calldata _hookParams
) internal virtual override returns (bytes4, BeforeSwapDelta, uint24) {
if (_hookParams.length == 0) {
return (BaseHook.beforeSwap.selector, toBeforeSwapDelta(0, 0), 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we just return, does PoolManager still makes a swap without the hook or does it revert?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it still bypasses the swapping logic since swap delta is 0. Essentially no swap takes place, but we don't fail the route. Maybe we should

Comment thread src/FixedFeeSwapMarket.sol Outdated

return BalanceDelta({
amount0: _getAmountPrincipleDelta(currentTick, _tickUpper, _liquidity).toInt128(),
amount1: _getAmountCashDelta(_tickLower, currentTick, _liquidity).toInt128()
Copy link
Copy Markdown
Member

@garyghayrat garyghayrat Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why _getAmountPrincipleDelta just multiply by tick difference, but _getAmountCashDelta needs tickToPrice() and time? – @thelostone-mc

Comment thread src/FixedFeeSwapMarket.sol Outdated
// Check price limit
if (ctx.priceLimitWad != 0) {
uint256 priceAbs = currentPrice.abs();
if (ctx.principalForCash ? priceAbs <= ctx.priceLimitWad : priceAbs >= ctx.priceLimitWad) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this – @thelostone-mc

Comment thread src/FixedFeeSwapMarket.sol Outdated

// Convert NET to GROSS. Clamp to remaining gross to handle rounding edge cases
// where _grossFromNet slightly overshoots due to rounding up.
stepGross = _grossFromNet(stepNet);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seem redundant.

@alexkeating alexkeating changed the base branch from feature/add-fixed-fee-swap-custom-curve to main February 5, 2026 21:07
@github-actions
Copy link
Copy Markdown

Coverage after merging chore/more-cleanup into main will be

99.34%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   FixedFeeSwap.sol99.23%96.67%100%100%393
   FixedFeeSwapMarket.sol94.50%77.17%100%98.55%1023, 1034, 1036, 1137, 1149, 1159, 1177, 342–343, 532, 649–650, 663–664, 671–672, 771–772, 782–783, 790–791, 834, 867, 942–943
   LPVault.sol99.53%95.45%100%100%223
   PrincipalToken.sol100%100%100%100%
   VaultShareToken.sol100%100%100%100%
   YieldToken.sol100%100%100%100%
   Zapper.sol100%100%100%100%
src/lib
   FeeTracking.sol100%100%100%100%

@alexkeating alexkeating changed the title More cleanup Add custom curve Feb 25, 2026
@alexkeating alexkeating marked this pull request as ready for review February 25, 2026 13:49
@alexkeating alexkeating merged commit c51a3e6 into main Feb 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants