# Introducing AssetScooper

By [Asset Scooper](https://paragraph.com/@assetscooper) · 2025-03-07

---

In the ever-evolving world of decentralized finance (DeFi), efficiency and security are paramount. Today, we’re excited to introduce **AssetScooper**, a smart contract designed to streamline batch swaps on Uniswap V3 while leveraging the power of Permit2 for seamless token approvals.

This article will dive deep into the mechanics of AssetScooper, its features, and how it enhances the user experience in DeFi.

What is AssetScooper?
=====================

AssetScooper is a smart contract that enables users to perform batch swaps across multiple tokens in a single transaction. By integrating Uniswap V3 for decentralized trading and Permit2 for gas-efficient token approvals, AssetScooper simplifies the process of swapping multiple assets into a single output token. This is particularly useful for users who want to consolidate their holdings or execute complex trading strategies with minimal gas costs.

The contract is designed with security and efficiency in mind, incorporating features like reentrancy protection, deadline enforcement, and protocol fee collection.

Let’s break down how it works.

Key Features of AssetScooper
----------------------------

**1\. Batch Swaps with Uniswap V3**

AssetScooper leverages Uniswap V3’s concentrated liquidity model to execute swaps at optimal prices. Users can specify multiple input tokens, and the contract will swap each token for a single output token (e.g., USDC) in a single transaction.

This is achieved through Uniswap V3’s **\`exactInputSingle\`** function, which ensures that swaps are executed with minimal slippage.

**2.** **Permit2** **Integration**

Traditional token approvals in Ethereum require users to send multiple transactions, which can be costly and time-consuming. AssetScooper integrates **Permit2**, a token approval mechanism that allows users to approve tokens in a single transaction using off-chain signatures.

This eliminates the need for multiple approvals and significantly reduces gas costs.

**3\. Multicall for Efficient Execution**

AssetScooper uses multicall to bundle multiple swap transactions into a single call. This not only reduces gas costs but also ensures atomicity—either all swaps succeed, or none do.

This is particularly important for batch swaps, where partial execution could lead to undesirable outcomes.

**4\. Protocol Fee Collection**

AssetScooper includes a built-in protocol fee mechanism. A small percentage of the output tokens(configurable via **\`PROTOCOL\_FEE\_BPS\`**) is deducted and sent to a designated fee recipient. This fee can be used to fund further development or maintenance of the protocol.

**5\. Security Features**

\- **Reentrancy Protection**: AssetScooper uses OpenZeppelin’s **\`Reentrancy Guard**\` to prevent reentrancy attacks.

\- **Deadline Enforcement**: Users can specify a deadline for their transactions, ensuring that swaps are executed within a specific time frame.

\- **Pausable**: The contract owner can pause the contract in case of emergencies or upgrades.

How AssetScooper Works
----------------------

**Step 1: User Initiates a Swap**

The user prepares a batch swap by specifying:

\- An array of input tokens **(\`assets\`)**.

\- The desired output token **(\`tokenOut\`)**.

\- Minimum output amounts for each swap **(\`minOutputAmounts\`)**.

\- A deadline for the transaction.

**Step 2: Permit2 Signature**

The user signs a Permit2 permit, which grants AssetScooper permission to transfer their tokens. This permit includes:

\- The list of tokens to be transferred.

\- The amounts to be transferred.

\- A signature for verification.

**Step 3: Token Transfer and Approval**

AssetScooper uses Permit2 to transfer the tokens from the user’s wallet to the contract. It then checks and approves the Uniswap V3 router to spend the tokens if necessary.

**Step 4: Batch Swap Execution**

The contract constructs a multicall payload containing all the swap transactions and sends it to the Uniswap V3 router. Each swap is executed using the **\`exactInputSingle\`** function, ensuring optimal pricing and minimal slippage.

**Step 5: Fee Deduction and Output Transfer**

After the swaps are completed, the contract calculates the protocol fee and deducts it from the total output. The remaining tokens are transferred to the user’s specified address.

### Technical Deep Dive

1\. **Permit2 Integration**

Permit2 is a revolutionary tool that simplifies token approvals. Instead of requiring users to approve each token individually, Permit2 allows users to sign a single off-chain message that grants the contract permission to transfer their tokens.

This is particularly useful for batch swaps, where multiple tokens need to be approved.

In AssetScooper, the **\`permitTransferFrom\`** function is used to transfer tokens from the user’s wallet to the contract. This function verifies the user’s signature and transfers the tokens in a single transaction.

    permit2.permitTransferFrom(
       permit,
       transferDetails,
       _msgSender(),
       signature
    );
    ```

2\. **Multicall for Batch Swaps**

AssetScooper uses Uniswap V3’s multicall feature to bundle multiple swap transactions into a single call. This is achieved by encoding each swap as a \`bytes\` array and passing it to the router.

    (bool success, ) = 
    address(swapRouter).call(
         abi.encodeWithSelector(0x5ae401dc, deadline, calls)
    );
    ```

3\. **Fee Calculation**

The protocol fee is calculated as a percentage of the total output tokens. The fee is deducted before transferring the remaining tokens to the user.

    uint256 protocolFee = Math.mulDiv(            
          outputTokenBalance,
          PROTOCOL_FEE_BPS,
          10_000
    );
    uint256 amountOutMinusFee = outputTokenBalance - protocolFee;
    ```

4\. **Pool Fee Discovery**

AssetScooper dynamically discovers the optimal fee tier for each token pair by checking the available pools on Uniswap V3. It iterates through the fee tiers (0.01%, 0.05%, 0.3%, and 1%) and selects the first pool with sufficient liquidity.

    function getPoolFee(address tokenIn, 
    address tokenOut) private view returns 
    (uint24) {
         uint24[] memory feeTier = new 
    uint24[](4);    
       feeTier[0] = 100; 
       feeTier[1] = 500; 
       feeTier[2] = 3000; 
       feeTier[3] = 10000; 
     
      for (uint256 i = 0; i < feeTier.length; i++) 
    {
          address pool = 
    v3factory.getPool(tokenIn, tokenOut, 
    feeTier[i]); 
             if (pool != address(0) && 
    hasliquidity(pool)) {
                  return feeTier[i]; 
             } 
      } 
     revert PoolFeeNotFound(tokenIn,
     tokenOut);
    }
    ```
    

### Benefits of AssetScooper

1\. **Gas Efficiency**

By combining Permit2 and multicall, AssetScooper significantly reduces gas costs compared to traditional batch swaps.

2\. **Improved User Experience**

Users can execute complex swaps with a single transaction, eliminating the need for multiple approvals and swaps.

3\. **Enhanced Security**

AssetScooper incorporates multiple security features, including reentrancy protection and deadline enforcement, to ensure safe and reliable swaps.

4\. **Protocol Sustainability**

The built-in fee mechanism ensures that the protocol can sustainably fund its development and maintenance.

### Use Cases

1\. **Portfolio Consolidation**

Users can consolidate multiple tokens into a single stablecoin token in one transaction.

2\. **Liquidity Provision**

Liquidity providers can use AssetScooper to swap multiple tokens into a single asset before providing liquidity on Uniswap V3.

3\. **Arbitrage Strategies**

Traders can use AssetScooper to execute arbitrage strategies across multiple tokens efficiently.

### Conclusion

AssetScooper represents a significant step forward in DeFi efficiency and usability. By combining the power of **Uniswap V3, Permit2**, and **multicall**, it enables users to execute complex batch swaps with ease and security. Whether you’re a casual user looking to consolidate your portfolio or a sophisticated trader executing arbitrage strategies, AssetScooper has you covered.

We’re excited to see how the community adopts and builds upon this technology.

Stay tuned for more updates, and happy swapping!

---

*Originally published on [Asset Scooper](https://paragraph.com/@assetscooper/introducing-assetscooper-1)*
