Position Playbooks
Four ways to alter, scale or restructure a live margin position inside a single block — without closing it out, without depositing new cash, and without exposing the intermediate steps to front-running. Each one is a different use of the same primitive: borrowed liquidity that must be returned before the block ends.
⚡ Where the money comes from — and why it has to go back
Every playbook here opens by borrowing liquidity from one of Atomic’s integrated lending pools — the Trading desk integrates it, prices it and routes the transaction. There is no credit relationship to underwrite, so there is nothing to approve you for.
What makes these workflows possible is atomicity. The borrow, every intermediate step, and the repayment all execute inside one transaction. If the pool is not made whole by the final instruction — or any safety bound you set is breached — the entire sequence reverts and the chain keeps no record of it having been attempted. You are out the gas and nothing else.
That is also why no step in the middle can be front-run. There is no moment where your position sits half-restructured and exposed: the intermediate states never exist on-chain as observable, interruptible facts.
One-block leverage scaling
Raise the leverage on a live position — say 1.5× to 4× — without running borrow‑swap‑deposit cycles across many blocks, and without out-of-pocket capital.
- Draw flash credit. Borrow $150,000 USDC from the lending pool.
- Convert to collateral. Swap it for roughly 50 ETH through a DEX router.
- Top up the position. Deposit the 50 ETH into your existing margin vault.
- Draw new debt. Borrow $150,000 USDC against the borrowing capacity that collateral just created.
- Settle. Return the principal plus fee to the pool, same transaction.
Contract function: leverageLoop() — proven end-to-end against live lending and DEX protocols on Ethereum and BNB Chain.
Deleveraging without out-of-pocket cash
Cut your loan-to-value and lift your health factor when volatility threatens liquidation — using nothing but the position's own collateral.
- Draw the debt principal. Flash-borrow the debt asset from the pool.
- Pay down the vault. Repay the outstanding borrow in your margin position.
- Withdraw freed collateral. With the debt cleared, the collateral unlocks.
- Sell only what is needed. Swap enough collateral to cover the repayment, bounded by a slippage limit you set.
- Settle. Return principal plus fee to the pool.
- Keep the rest. All unsold collateral transfers straight back to you.
Contract function: selfLiquidate() — full close only. Fork-tested on Ethereum and BNB Chain.
In-place collateral swap
Change what backs your loan — say $1M of WBTC to $1M of ETH — while the debt stays exactly where it is. No close-out, no unbonding queue.
- Flash the new collateral asset. Borrow the ETH you intend to back the loan with.
- Supply it first. Deposit the ETH into the vault while the old collateral is still in place.
- Withdraw the old collateral. Now safe to remove, because the position is already over-collateralised by the new asset.
- Sell the old asset. Swap the WBTC for ETH, bounded by your slippage limit.
- Settle. Return principal plus fee to the pool.
Contract function: swapCollateral() — fork-tested moving a live position's collateral from WETH to WBTC on Ethereum with the debt untouched throughout.
Debt refinancing and rate arbitrage
Cut the interest you pay by moving the debt to wherever it is cheapest — without unwinding the position or finding bridge capital.
- Flash the outstanding debt. Borrow the full amount owed, read live on-chain so accrued interest is covered exactly.
- Clear the expensive venue. Repay the debt and pull the collateral out.
- Reopen on the cheaper venue. Supply the collateral and re-borrow the same asset at the better rate.
- Settle. Return principal plus fee to the pool. Only the fee is added to your new debt — never the unused buffer.
Contract function: refinance() — fork-tested moving a live position between venues, with property tests proving the new debt is exactly the old debt plus the fee.
What is actually built
The honest version of the table, since none of it is live yet. Everything marked built has been executed against forked mainnet using the real protocols — not mocked.
| Playbook | Function | Status |
|---|---|---|
| 1 · Leverage scaling | leverageLoop() | As described |
| 2 · Deleveraging | selfLiquidate() | Full close only — no partial paydown |
| 3 · Collateral swap | swapCollateral() | As described |
| 4 · Rate arbitrage | refinance() | Across venues — not debt-asset swaps |
| Execution for customers | — | Not audited · not deployed |
If you are building this yourself
The three things that most often go wrong, from having got them wrong.
- Implement the provider's receiver interface exactly. Some lenders call executeOperation; ERC-3156 lenders call onFlashLoan. Gate the callback on the caller being the pool and the initiator being your own contract — otherwise anyone can invoke it directly with fabricated arguments.
- Approve the pool inside the callback, before returning. The pool pulls principal plus premium back out of your contract at the end. Approving beforehand in a separate transaction leaves a standing allowance; approving inside the callback does not.
- Set an explicit floor — and make it a floor on the thing you care about. A minimum output bounds slippage; a minimum health factor bounds the state you are left in. They are not the same guarantee, and a swap can respect its slippage bound while still leaving a position one bad candle from liquidation.
- Repay by reading the debt on-chain, not from a figure computed off-chain. Interest accrues every block, so any amount quoted in advance is fractionally short by the time the transaction lands, leaving dust debt that blocks the collateral withdrawal and reverts everything. This one cost us a full debugging session.
- Check which router you are calling. Uniswap and PancakeSwap each ship two, and only one of each pair takes the four-field swap structs. The other differs by a single deadline field, which changes the function selector, so every swap silently fails to dispatch — no revert reason, no warning.
Price any of this against live liquidity
The desk reads capacity and fees from the lending contracts at the current block and tells you the edge a route has to beat. That part is live today.
Open the Flash Loan Desk →