Feat: Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration#2
Open
p0n1 wants to merge 2 commits intofeat/multi-assets-poolfrom
Open
Feat: Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration#2p0n1 wants to merge 2 commits intofeat/multi-assets-poolfrom
p0n1 wants to merge 2 commits intofeat/multi-assets-poolfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
I have developed a new feature called
transactAndSwapthat enhances privacy in DEX swaps by integrating shielded pools with external swap platforms such as Uniswap or 0x. This feature empowers users to conduct swaps while maintaining optimal privacy.To facilitate this functionality, I introduced a new contract named
SwapExecutorfor managing the execution of external swaps. Additionally, I extended theExtDatastruct with the following fields:struct ExtData { address recipient; int256 extAmount; address relayer; uint256 fee; bytes encryptedOutput1; bytes encryptedOutput2; bool isL1Withdrawal; uint256 l1Fee; + address tokenOut; // un-shield -> swap via uni or 0x -> re-shield to this token + uint256 amountOutMin; + address swapRecipient; + address swapRouter; + bytes swapData; + bytes transactData; // used for re-shield }To support this feature, I incorporated a new function named
transactAndSwap(). The workflow consists of the following steps: un-shield (withdraw) tokens to a designated recipient (ourSwapExecutor), execute the swap using Uniswap or 0x, and, if desired, re-shield the swapped tokens back into the pool. Users can set theamountOutMinslightly below the market value to guarantee that a valid proof can be generated beforehand.The
transactAndSwapfeature accommodates both swap and transfer to a recipient or re-shielding back into the pool. In the latter case, users are required to generate two proofs and forward them to the relayer for processing. The second proof is encoded in the transactData field.By leveraging
transactAndSwap, users can capitalize on the best liquidity accessible in the market. Given that on-chain transfers are inevitable, un-shielding the original token first is deemed acceptable. The multi-asset shielded pool allows users to re-shield tokens directly back into the pool without involving their wallets. This approach effectively preserves user privacy, as the identities of both the swapper and swapRecipient remain concealed.