Skip to content

Feat: Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration#2

Open
p0n1 wants to merge 2 commits intofeat/multi-assets-poolfrom
feat/transactAndSwap
Open

Feat: Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration#2
p0n1 wants to merge 2 commits intofeat/multi-assets-poolfrom
feat/transactAndSwap

Conversation

@p0n1
Copy link
Owner

@p0n1 p0n1 commented Apr 21, 2023

Description:

I have developed a new feature called transactAndSwap that 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 SwapExecutor for managing the execution of external swaps. Additionally, I extended the ExtData struct 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 (our SwapExecutor), execute the swap using Uniswap or 0x, and, if desired, re-shield the swapped tokens back into the pool. Users can set the amountOutMin slightly below the market value to guarantee that a valid proof can be generated beforehand.

The transactAndSwap feature 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.

@p0n1 p0n1 changed the title Feat: TransactAndSwap - Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration Feat: Enhancing Privacy in Swaps with Shielded Pools and External Swap Integration Apr 21, 2023
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.

1 participant