← Writing

Swap is not repay: two ways a CDP took my coins

Ten months apart, two collateralised debt positions took my coins without a hack. On Sui, a redemption halved my position and raised my collateral ratio; on IOTA, I was liquidated within minutes while trying to leave. The arithmetic of both, and the order of operations I now follow.

Virtue's position management window: collateral ratio 110.10% in red against a minimum collateral ratio of 110.00%. Prices, amounts and debt are blurred.

Earlier this month I was liquidated. I wasn’t adding risk; I was taking it off, unwinding a position on IOTA one step at a time, and the position was gone within minutes of the step I took. Last December a different protocol, on Sui, took half of another position from me without my doing anything at all. Neither was a hack, a scam or a bug. In both cases the protocol did exactly what its documentation says it does, to someone who hadn’t worked through what that meant. Tonight I’m working through it.

One ratio

Both protocols are collateralised debt positions, CDPs. You lock a volatile coin as collateral and borrow a stablecoin against it. Everything about the position comes down to one number, the collateral ratio: the value of what you locked divided by what you owe. With n coins at price P and a debt of D stablecoins,

CR=nPD

Each protocol sets a minimum, MCR; on both of the protocols in this post it is 110% [1] [2]. Below it, the position can be liquidated. People use these positions to borrow against coins they don’t want to sell, or, as I did, to loop: borrow the stablecoin, put it to work for a yield, and keep the coin’s upside.

Redemption: the peg’s backstop, paid for with your coins

In October last year I opened my first CDP, on Bucket, a stablecoin protocol on Sui. I locked SUI, borrowed its dollar coin, BUCK, at a collateral ratio of about 150%, well above the minimum, and staked the BUCK for a yield of 15 to 20% and points towards the protocol’s coming token. In late November I borrowed more, which took me to about 170%.

Bucket's borrow page: minimum borrowed debt 10.00; borrow fee 0.5%; minimum collateral ratio 110%; recovery mode threshold 150%.
The terms on Bucket's borrow page when I opened the position, October 2024. The borrow amount is blurred.

At the start of December, SUI had barely moved, but my position had shrunk. My debt had been cut roughly in half, a large part of my SUI had gone with it, and my collateral ratio had gone up. That was the clue. I had been redeemed.

Bucket’s design follows Liquity, a stablecoin protocol on Ethereum. Anyone holding BUCK can hand it to the protocol and receive one dollar’s worth of SUI per BUCK, at the oracle price, and the SUI is taken from borrowers’ positions “in ascending order of their collateralization ratio” [3]. The redeemer pays a fee of at least 0.5%, which rises when many people redeem at once [3] [4]. This is what holds the stablecoin’s price up: whenever BUCK trades below a dollar, buying it and redeeming it is a profit, and the buying pushes the price back. The cost of that floor is paid by whichever borrowers happen to be at the front of the queue.

Bucket Protocol's documentation, Redemptions: BUCK token redemption allows holders to redeem their BUCK for any collateral accepted by the protocol, including SUI, at face value; positions are redeemed in ascending order of their collateralization ratio. Redemptions are not the same as paying back debt. As a borrower, do I lose money if I'm redeemed against? You won't incur a net loss but lose some SUI exposure; your bottle's collateral ratio will improve. To avoid being redeemed against, maintain a high collateral ratio; the riskiest positions are redeemed first.
Bucket's documentation on redemptions, as archived in early 2025 [3].

The documentation is honest about what this does to the borrower: “you won’t incur a net loss but lose some SUI exposure. Your bottle’s collateral ratio will improve” [3]. Both halves are true, and the arithmetic shows why.

Redemption takes R dollars of debt and R dollars’ worth of collateral, at the oracle price P, from the same position:

n→n−RP,D→D−RCR′=nP−RD−R>CRwheneverCR>1

In dollars, nothing was lost: I owed R less and held R less. The protocol even considers me safer. But I had not opened the position to hold dollars. I had opened it to hold SUI, and redemption is a forced sale of my SUI at the price on the day someone else chose. To get back to where I was, I had to buy the coins back, at whatever the price was when I did:

coins lost=R(1Predeem−1Pbuy back)

I rebuilt the position that afternoon, re-collateralised it twice more over the following months, and finally converted the last of my BUCK back into SUI in March. Every one of those conversions happened at whatever SUI cost that day, not at the price at which I had been redeemed. SUI was about $3.50 when I noticed; five weeks later it reached an all-time high of about $5.35 [5]. I didn’t add it up until this May, when I reconciled every transaction on a block explorer and found that nearly a fifth of my SUI had gone. There was no single moment of loss to notice. It leaked out through the round trips.

A redemption shrinks a position and raises its collateral ratio An example position before and after a redemption of 50 dollars. Before: 170 dollars of collateral against 100 dollars of debt, a collateral ratio of 170%. After: 120 dollars of collateral against 50 dollars of debt, a collateral ratio of 240%. In dollars nothing is lost, but 50 dollars' worth of the coin has been sold at the day's price. Before After redeeming $50 $170$100 $120$50−$50−$50 coindebt coindebt CR = 170% CR = 240%

Liquidation: the exit is a trade too

The second lesson came on IOTA. In July, after IOTA’s new mainnet, a CDP called Virtue and a DEX called Pools launched together, and I built a loop: stake IOTA into stIOTA, lock stIOTA on Virtue, borrow its dollar coin VUSD, and provide stIOTA and VUSD as liquidity on Pools for the farming rewards. The parameters were familiar: a 110% minimum, and below it, a stability pool of VUSD repays the debt and takes the collateral [2].

Virtue's documentation, Stability Pool and Liquidations, How it works: when a position's collateral ratio falls below the Minimum Collateral Ratio it becomes eligible for liquidation; liquidation is triggered by whitelisted executors; debt is repaid using VUSD from the Stability Pool; the protocol seizes the collateral, 0.7% as a protocol fee and 99.3% to Stability Pool depositors.
How Virtue liquidates a position [2].

I had thought about the risks. In August I worked out both of the loop’s failure bands: if IOTA ran above about $0.25, impermanent loss in the pool would eat the rewards; if it fell below about $0.14, the CDP would be in the same trouble as my Bucket position. What I hadn’t modelled was my own exit.

When I left the pool, I received stIOTA and VUSD. I swapped the VUSD into IOTA, because I wanted IOTA. That felt like closing the position. It wasn’t: the VUSD I owed Virtue was still owed. A swap is not a repayment. I had turned my loop into a plain leveraged long on IOTA, without meaning to, and left it there.

In the middle of this month I went to unwind what I thought was a small leftover. The first step I took was to withdraw collateral, and the app let me withdraw as much as the rules allowed, which is exactly the amount that leaves the position at the minimum:

Δmax=n−MCR×DP⇒CR=MCR

The screenshot at the top of this post is my position just after that withdrawal: a collateral ratio of 110.10% against a minimum of 110.00%, with the liquidation price a hair below the market price. A position at exactly its minimum ratio survives only as long as the price doesn’t move against it at all. IOTA had been sliding since the crash of 10 and 11 October, when more than $19 billion of leveraged positions were liquidated across the market in a day, the largest such event on record [6], and it kept falling, below $0.13 at one point [7]. I had stepped away for a few minutes, waiting to take the next step. When I looked again, the position had been liquidated, and a third of my IOTA had gone with it.

Virtue's dashboard: total collateral value $0.00, total borrow 0, and under My Position, You don't have any position yet.
The same dashboard a few minutes after the screenshot at the top.
The same exit in two orders The collateral ratio of a position over three moments: the start, after the first step of an exit, and a few minutes later after a small fall in price. If the first step is to repay debt, the ratio rises well above the minimum and a small price fall does not matter. If the first step is to withdraw as much collateral as allowed, the ratio drops to exactly the minimum, and the small price fall pushes it below the line, where the position is liquidated. collateral ratio minimum (MCR) repay first withdraw first liquidated start first step price dips

Order of operations

The fix is simple to state, and I now write it down before every exit.

First, repay before you withdraw. Paying down the debt raises the collateral ratio; withdrawing lowers it. Doing them in the wrong order walks the position down to the edge, however briefly.

Second, a swap is not a repayment. If you borrowed a stablecoin, the debt is in that stablecoin, and it stays open until you return it to the protocol, whatever you do with the coins in between.

Third, check the ratio after every step, not just at the end. An exit is a sequence of transactions, and the riskiest moment of a position is often halfway out of it.

Fourth, anything with a loan in it needs watching. A redemption can come any day the stablecoin dips below its peg while your position is near the front of the queue, and the only defence is noticing in time. I was busy with exams and the lab, and in both cases I noticed late.

The real lesson is about the denomination. Both protocols measure everything in dollars, and in dollars, the redemption was fair and the liquidation followed the rules. I measure my holdings in coins, and in coins I lost a fifth of one position and a third of another. A CDP is a tool for people who think in dollars and borrow against coins. I have used it twice as someone who thinks in coins, and I won’t borrow again.

References

  1. Bucket Protocol. Borrowing. Documentation, archived 16 October 2024. web.archive.org.
  2. Virtue. Stability pool and liquidations. Documentation. docs.virtue.money.
  3. Bucket Protocol. Redemptions. Documentation, archived 3 December 2024. web.archive.org.
  4. Liquity. LUSD redemptions. Liquity v1 documentation. docs.liquity.org.
  5. CoinGecko. Sui historical data. coingecko.com.
  6. CoinDesk Research. Market spotlight: the $19 billion liquidation that shook crypto. 17 October 2025. coindesk.com.
  7. CoinGecko. IOTA historical data. coingecko.com.

More writing →