-
Couldn't load subscription status.
- Fork 22
v4 Hook Exploration #48
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
Conversation
src/EulerSwapHook.sol
Outdated
| // 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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
-
have access to the EVC functions (depositAssets/withdrawAssets)
-
not break all the tests
| abi.encodePacked( | ||
| bytes1(0xFF), | ||
| deployer, | ||
| keccak256(abi.encode(account, salt)), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
src/EulerSwapHook.sol
Outdated
| // 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(); |
There was a problem hiding this comment.
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
-
Hook takes capital from PoolManager and puts it in Euler. This creates a debt, which is paid by the swapper - the input currency
-
Hook withdraws from Euler to the PoolManager. This creates a credit, which is collected by the swapper - the output currency
src/EulerSwapHook.sol
Outdated
| // 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the latest version of the router https://github.com/Uniswap/v4-periphery/blob/main/src/V4Router.sol ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
test setup for EulerSwapHook
- 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
V4 compute quote
V4 exploration merge
Minimal Router with Prepaid Inputs
test: ensure swap fees are accounted
Drafting so you guys can look into the diff
Tried minimizing the diff as possible, but major callouts here: