Skip to content

Conversation

@saucepoint
Copy link
Collaborator

@saucepoint saucepoint commented Mar 7, 2025

Drafting so you guys can look into the diff

Tried minimizing the diff as possible, but major callouts here:

  • EulerSwapHook inherits EulerSwap
    • avoid breaking tests
    • set up boilerplate for "custom curve" v4 hook
  • EulerSwapFactory has an IPoolManager constructor-param
  • EulerSwapFactory deploys EulerSwapHook
    • factory provides IPoolManager as a constructor to EulerSwapHook
    • developers will need to mine valid salts that produce valid EulerSwapHook addresses
    • EulerSwapHook at-construction, will initialize a v4 pool for itself

Comment on lines 53 to 57
// TODO: compute the open side of the trade, using computeQuote() ?
uint256 amountIn;
uint256 amountOut;
// uint256 amountIn = isExactInput ? uint256(-params.amountSpecified) : computeQuote(..., false);
// uint256 amountOut = isExactInput ? computeQuote(..., true) : uint256(params.amountSpecified);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we need a way to calculate the amountIn or the amountOut for a given trade on the eulerswap curve, then we can start testing it

} from "@uniswap/v4-core/src/types/BeforeSwapDelta.sol";
import {EulerSwap, IEulerSwap, IEVault} from "./EulerSwap.sol";

contract EulerSwapHook is EulerSwap, BaseHook {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

inherited the OG EulerSwap to

  1. have access to the EVC functions (depositAssets/withdrawAssets)

  2. not break all the tests

abi.encodePacked(
bytes1(0xFF),
deployer,
keccak256(abi.encode(account, salt)),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

had the fork the canonical HookMiner because EulerSwapFactory encodes the euler account holder in the salt

Copy link
Collaborator Author

@saucepoint saucepoint Mar 7, 2025

Choose a reason for hiding this comment

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

added this from uniswap/briefcase because v4-core/src/PoolManager.sol is hard-pinned to a solidity version (we cant import it and use new PoolManager();)

but essentially it just deploys PoolManager from its known creationCode

Comment on lines 59 to 69
// take the input token, from the PoolManager to the Euler vault
// the debt will be paid by the swapper via the swap router
// TODO: can we optimize the transfer by pulling from PoolManager directly to Euler?
poolManager.take(inputCurrency, address(this), amountIn);
depositAssets(inputCurrency == key.currency0 ? vault0 : vault1, amountIn);

// pay the output token, to the PoolManager from an Euler vault
// the credit will be forwarded to the swap router, which then forwards it to the swapper
poolManager.sync(outputCurrency);
withdrawAssets(outputCurrency == key.currency0 ? vault0 : vault1, amountOut, address(poolManager));
poolManager.settle();
Copy link
Collaborator Author

@saucepoint saucepoint Mar 7, 2025

Choose a reason for hiding this comment

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

this is where the hook facilitiates capital transfer to-and-from PoolManager <--> Euler

  1. Hook takes capital from PoolManager and puts it in Euler. This creates a debt, which is paid by the swapper - the input currency

  2. Hook withdraws from Euler to the PoolManager. This creates a credit, which is collected by the swapper - the output currency

// uint256 amountOut = isExactInput ? computeQuote(..., true) : uint256(params.amountSpecified);

// take the input token, from the PoolManager to the Euler vault
// the debt will be paid by the swapper via the swap router
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this credit/debit pattern should be compatible with all v4 swap routers, i.e. universal router, z0r0z/v4-router, and PoolSwapTest

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TLDR:

depsite the hook creating deltas (taking input, providing output), the BeforeSwapDelta that is returned to PoolManager gets "processed" in a way that the deltas are passed to the swap router "the sender"

from the eyes of a swap router, it just observes: "i owe money to PoolManager (input), so i'll use the EOA balance. and PoolManager owes me money (output), so i'll send it to the EOA"

Copy link
Contributor

Choose a reason for hiding this comment

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

Will routers automatically support EulerSwap hook? E.g how will z0r0z/v4-router quote this pool as it does not use the standard Uniswap curve?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the revert-quoter will work on EulerSwap https://github.com/Uniswap/v4-periphery/blob/main/src/lens/V4Quoter.sol, since its swapping thru the hook with eth_call (simulated tx)

its whats powering the labs routing algorithm

saucepoint and others added 10 commits March 15, 2025 16:00
- eulerSwap instance should be activated first for approvals/enabling collateral
  - used to be done on first swap
- Seeds poolManager with starting balance
- Typo in exact output test
@hoytech hoytech marked this pull request as ready for review April 3, 2025 19:58
@hoytech hoytech merged commit fce4e34 into master Apr 3, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants