Skip to main content

How do I build a leverage or looping position in one transaction?

Compose the deposit, borrow, and any swap or flashloan as a same-chain Bundle so the steps succeed or revert together. This is not a single Route call.

J
Written by Javier Diaz

Compose the deposit, borrow, and any swap or flashloan as a same-chain Bundle so the steps succeed or revert together. A leverage or looping position is a multi-action workflow, not a single Route call.

Definition

Looping typically deposits collateral, borrows against it, and may swap or deposit again in the same transaction. If any step fails, the whole transaction should revert so the user is not left mid-loop.

How it works

  • Use the Bundle API with an ordered action list: deposit, borrow, optional swap or deposit, and repayment of any flashloan in the same transaction if you use one.

  • Use delegate when borrow, repay, or other state-keeping actions must remain at fromAddress.

  • Chain intermediate amounts with useOutputOfCallAt instead of hardcoding them.

  • Add an Enso slippage or other documented check if you need a guard on an intermediate output.

  • If you flash-borrow the first input, include a flashloan action with a callback that can repay the borrowed amount plus any fee.

How Enso does this

Get Started lists leverage with harvest, borrow, repay, and claim as Bundle use cases. Flash liquidity, if you need it, is documented only on the Bundle API in Flashloans. Same-chain bundle actions are atomic; do not model this as a cross-chain route unless you have a separately documented path.

FAQ

Can Route open a looped position for me?

Route is for a path into one destination position. A loop that must borrow and deposit in a fixed order belongs on Bundle.

What if a callback cannot repay a flashloan?

The entire transaction reverts and no tokens are moved.

Related articles

  • How do I borrow or repay through Enso?

  • How do I use a flashloan in an Enso bundle?

  • How do I add checks or slippage guards inside a bundle?

  • What is a flashloan in a bundled transaction?

  • How do I bundle multiple DeFi actions into one transaction?

Sources

Did this answer your question?