Great Fleece Nightingale
Medium
The fee-first collection pattern in StablecoinHandler
causes users to lose fees when subsequent swap operations fail, as fees are collected before validating the complete transaction path.
- In
StablecoinHandler
.sol, the _stablecoinSwap function collects fees before executing the main swap operation:
Since the fee is transferred first, a failure in any subsequent transfer would result in:
- Fee already collected by protocol
- User loses fee amount
- Main swap operation not completed
- No automatic fee refund mechanism
- This creates a scenario where users pay fees for failed transactions.
No response
- User initiates swap with valid parameters
- Protocol collects fee successfully
- Main swap operation encounters failure.
- Transaction reverts
- Fee remains collected despite failed service
Users lose fee amounts while receiving no service.
it("fee_paid_for_failed_transaction", async () => { const stablecoinInputs = { liquiditySafe: deployer, destination: holder, origin: USDC.address, oAmount: ethers.parseUnits("100", 6), target: eMXN.address, tAmount: ethers.parseUnits("1800", 6), stablecoinFeeCurrency: USDC.address, stablecoinFeeSafe: safe.address, feeAmount: ethers.parseUnits("1", 6) };
const initialFeeBalance = await USDC.balanceOf(safe);
// Cause main swap to fail
await USDC.connect(deployer).transfer(otherAddress, await USDC.balanceOf(deployer));
await expect(AmirX.swap(holder, true, stablecoinInputs, defiInputs))
.to.be.reverted;
expect(await USDC.balanceOf(safe))
.to.equal(initialFeeBalance.add(ethers.parseUnits("1", 6)));
});
No response