> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compasslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas Savings with Transaction Bundler 

> Collapse multi‑step DeFi workflows into one atomic transaction and cut network costs on typical flows by ~50–70%. 

export const GithubCodeBlock = ({typescript, python}) => {
  const [typescriptCode, setTypescriptCode] = useState("");
  const [pythonCode, setPythonCode] = useState("");
  function removeWhitespace(strings, x) {
    return strings.map(str => {
      let count = 0;
      let i = 0;
      while (i < str.length && count < x && str[i] === " ") {
        count++;
        i++;
      }
      return str.slice(i);
    });
  }
  function cropToSnippet({text, from, to}) {
    const lines = text.split("\n");
    let result = [];
    let isCollecting = false;
    for (const line of lines) {
      if (line.trim() === from) {
        isCollecting = true;
        continue;
      }
      if (line.trim() === to) {
        break;
      }
      if (isCollecting) {
        result.push(line);
      }
    }
    const whitespaceToDelete = result[0].length - result[0].trimStart().length;
    result = removeWhitespace(result, whitespaceToDelete);
    return result.join("\n");
  }
  function removeSnippetComments(code) {
    return code.replace(/(\/\/|#) SNIPPET (START|END) \d+(\n|$)/g, "");
  }
  useEffect(() => {
    if (!typescript) return;
    fetch(typescript.url).then(response => response.text()).then(text => {
      let code = text;
      if (typescript.snippetNumber) {
        code = cropToSnippet({
          text,
          from: `// SNIPPET START ${typescript.snippetNumber}`,
          to: `// SNIPPET END ${typescript.snippetNumber}`
        });
      } else {
        code = removeSnippetComments(code);
      }
      setTypescriptCode(code);
    }).catch(error => {
      console.error("Error loading file:", error);
    });
  }, [typescript]);
  useEffect(() => {
    if (!python) return;
    fetch(python.url).then(response => response.text()).then(text => {
      let code = text;
      if (python.snippetNumber) {
        code = cropToSnippet({
          text,
          from: `# SNIPPET START ${python.snippetNumber}`,
          to: `# SNIPPET END ${python.snippetNumber}`
        });
      } else {
        code = removeSnippetComments(code);
      }
      setPythonCode(code);
    }).catch(error => {
      console.error("Error loading file:", error);
    });
  }, [python]);
  if (!python && !typescript) return null;
  if (!python) {
    return <CodeBlock language="typescript" filename={typescript.name} expandable={typescript?.numOfLinesExpandable ? "true" : null} lines="true" icon="https://upload.wikimedia.org/wikipedia/commons/f/f5/Typescript.svg" code={typescriptCode} children={typescriptCode || !typescript?.numOfLinesExpandable || <div style={{
      whiteSpace: "pre-wrap"
    }}>
        {Array(typescript?.numOfLinesExpandable).fill("-").map(x => x).join("\n")}
      </div>} />;
  }
  if (!typescript) {
    return <CodeBlock language="python" filename={python.name} expandable={python?.numOfLinesExpandable ? "true" : null} lines="true" icon="https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg" code={pythonCode} children={pythonCode || !python?.numOfLinesExpandable || <div style={{
      whiteSpace: "pre-wrap"
    }}>
        {Array(python?.numOfLinesExpandable).fill("-").map(x => x).join("\n")}
      </div>} />;
  }
  return <CodeGroup>
  <CodeBlock language="typescript" filename={typescript.name} expandable={typescript?.numOfLinesExpandable ? "true" : null} lines="true" icon="https://upload.wikimedia.org/wikipedia/commons/f/f5/Typescript.svg" code={typescriptCode} children={typescriptCode || !typescript?.numOfLinesExpandable || <div style={{
    whiteSpace: "pre-wrap"
  }}>
          {Array(typescript?.numOfLinesExpandable).fill("-").map(x => x).join("\n")}
        </div>} />
  <CodeBlock language="python" filename={python.name} expandable={python?.numOfLinesExpandable ? "true" : null} lines="true" icon="https://upload.wikimedia.org/wikipedia/commons/c/c3/Python-logo-notext.svg" code={pythonCode} children={pythonCode || !python?.numOfLinesExpandable || <div style={{
    whiteSpace: "pre-wrap"
  }}>
          {Array(python?.numOfLinesExpandable).fill("-").map(x => x).join("\n")}
        </div>} />
</CodeGroup>;
};

## Why bundling saves gas

* **One transaction, shared overhead.** Instead of paying per‑transaction base costs multiple times, you pay them **once**.
* **Warm storage & reused context.** Within a single transaction, repeated data access become **warm accesses**, which are cheaper than touching the same data in separate transactions.

> Savings vary by chain, market conditions, and strategy shape. [Reach out to us](https://calendly.com/elisabeth-compasslabs/30min?month=2025-09) - we’d be happy to share more details or run a custom estimate for your use case.

<img src="https://mintcdn.com/compasslabs-f07467e0/xcz0y_akL4AKxR-L/images/Screenshot2025-09-19at22.23.45.png?fit=max&auto=format&n=xcz0y_akL4AKxR-L&q=85&s=b2cdb2715b9c059289cf392b02d03f59" alt="Screenshot 2025-09-19 at 22.23.45.png" width="1852" height="858" data-path="images/Screenshot2025-09-19at22.23.45.png" />

## Experiments

We measured representative DeFi sequences on Base mainnet **with and without Compass Bundler.**

We ran tests on Base mainnet using representative DeFi transaction sequences, comparing gas usage **with and without Compass Bundler**.

### Experiment A: 10-Transaction Bundle

**Transaction sequence for Aave Leverage:**

[approve ×4](https://docs.compasslabs.ai/v1/api-reference/universal/set-allowance) → [aave\_supply](https://docs.compasslabs.ai/v1/api-reference/aave-v3/supplylend) → [aave\_borrow](https://docs.compasslabs.ai/v1/api-reference/aave-v3/borrow) → [aave\_repay](https://docs.compasslabs.ai/v1/api-reference/aave-v3/repay-loans) → [aave\_withdraw](https://docs.compasslabs.ai/v1/api-reference/aave-v3/unstake) → [uniswap\_sell\_exactly](https://docs.compasslabs.ai/v1/api-reference/uniswap-v3/sell-exact-amount) → [uniswap\_buy\_exactly](https://docs.compasslabs.ai/v1/api-reference/uniswap-v3/buy-exact-amount)

**Results:** Bundling the 10 transactions into a single atomic transaction saved **\~47% in gas** (1.89× improvement):

| Execution Method | Average Gas Used |
| :--------------- | :--------------- |
| Sequential       | 1,276,383        |
| Bundled          | 674,067          |

* [View the script used](https://github.com/CompassLabs/api_usecases/blob/main/v0/gas_estimation/gas_usage_report_base.py) and [complete results here](https://github.com/CompassLabs/api_usecases/tree/main/v0/gas_estimation/gas_usage_reports).
* [View bundled transaction on Basescan](https://basescan.org/tx/0x036c14c64b4b02597595c810a67d26fad6fa7fa7912c9bea332d125d17a6306f) — it executed the full sequence using just 672,284 gas.

### Experiment B: Larger Bundles

We extended testing to bundles of up to 100 transactions. Gas savings increase with bundle size (**2x savings at 11 transactions, 3x savings at 47 transactions**), though returns diminish:

<img src="https://mintcdn.com/compasslabs-f07467e0/xcz0y_akL4AKxR-L/images/Screenshot2025-09-19at19.30.15.png?fit=max&auto=format&n=xcz0y_akL4AKxR-L&q=85&s=6bae81253477ddebda11801dd5ce23ee" alt="Screenshot 2025-09-19 at 19.30.15.png" width="1398" height="592" data-path="images/Screenshot2025-09-19at19.30.15.png" />

| Bundle Size | Gas Savings |
| :---------- | :---------- |
| 10          | 47.89%      |
| 30          | 64.05%      |
| 50          | 68.88%      |
| 70          | 68.34%      |
| 100         | 69.45%      |

[See 100-transaction bundle on Basescan](https://basescan.org/tx/0xb070f6d8955c66622eff6c6ab0cb0f690f580b7a943dc013d428822b790b5188)

## Conclusion

Compass Bundler drastically reduces Ethereum gas costs, especially for workflows involving many DeFi operations.

For example, a 2.5× [leverage loop on Aave](/v1/transaction-bundler/aave_looping) takes 13 transactions to loop and 13 more to unwind. On Ethereum Mainnet, this would typically cost around \$6 in gas. With bundling, you’d save about \$3.

If your protocol routinely rebalances vaults or portfolios, Compass Bundler can yield significant cost reductions. [Contact us](mailto:contact@compasslabs.ai) with your use case to get a tailored estimate.
