Skip to navigation or content

Nov 17, 2022

The Subtlety Behind Sweeping

Jack Burt
Jack Burt

Writer

Curious what happens, from a semi-technical perspective, when you sweep a collection on Flip?

Flip Bulk Cart

Pressing ‘Purchase’ on a sweeping transaction starts a number of processes that occur ‘under the hood’.

For instance, the first thing we do is find you the most gas-efficient and user-friendly transaction, given the list of assets you’d like to buy. If every asset you’re buying is listed on OpenSea, we’ll route you directly to OpenSea’s smart contract to save you money on gas fees. The same goes if every asset you want is listed on another specific exchange.

On the other hand, if your sweep targets multiple exchanges (maybe you’re sweeping 10 assets, and five are listed on OpenSea, three on LooksRare, and two on X2Y2), then we’ll send you through our router contract. This ‘router contract’ takes the list of trades and executes them in silos; all of your OpenSea trades, then your LooksRare trades, and then your X2Y2 trades.

The advantage to using our router contract is that you can buy your entire shopping cart’s worth of items in one transaction — rather than having to submit a separate transaction for each marketplace — but it is slightly more expensive in terms of gas, which is also why we wouldn’t use the router contract when all items in a sweep come from the same marketplace.

Amidst all this, we’re also accounting for transactional preference, so if any of your trades fail (say 2/15 of the assets in your sweep were delisted while your transaction was pending) your entire transaction won’t fail. Instead, you’ll receive the 13 items you successfully purchased, and the leftover ETH (from the delisted items) will be refunded to you. In the future, we’ll be implementing a ‘fill or kill’ option, which could, in a scenario where even one of your trades fails, cause the entire transaction to fail.

After we’ve figured out the optimal route for your transaction, we build the transaction itself. Each exchange (typically) has its own smart contracts, so the transaction’s data needs to be formatted differently for each exchange. We won’t get into the exact technical details here, but, in general, it requires some data manipulation/formatting; we take your address, the data on the asset(s) you’d like to buy, and then format them in a way that tells each exchange's smart contract "this user would like to purchase these assets at these prices".

After the transaction has been built, all that’s left is for you to, using your wallet, sign and submit the transaction. Once your transaction lands in a block on-chain, we’ll show you a summary of your order, including what you successfully purchased, the total cost, and if any purchases failed (which would, of course, result in a refund to you).

And sure, it might not be as sexy as what goes on ‘under the hood’ of a sports car, but it’s damn interesting — and hopefully, knowing how much goes on behind the scenes of a sweeping transaction brings you a little more dopamine next time you hit ‘Purchase’ on Flip.

Back to updates archive