Skip to content

feat: swap USDFC back to FIL#14

Merged
pyropy merged 17 commits intomainfrom
feat/swap-usdfc-back-to-fil
Feb 11, 2026
Merged

feat: swap USDFC back to FIL#14
pyropy merged 17 commits intomainfrom
feat/swap-usdfc-back-to-fil

Conversation

@pyropy
Copy link
Member

@pyropy pyropy commented Feb 2, 2026

  • Adds a swap from USDFC back to FIL
    • Swap is performed in parallel with bid using higher nonce
  • Refactors index.js into multiple files
  • Adds tests

Closes #6

@FilOzzy FilOzzy added this to FOC Feb 2, 2026
@github-project-automation github-project-automation bot moved this to 📌 Triage in FOC Feb 2, 2026
@BigLep BigLep moved this from 📌 Triage to ⌨️ In Progress in FOC Feb 2, 2026
@rjan90 rjan90 added this to the M4.1: mainnet ready milestone Feb 3, 2026
@pyropy pyropy changed the title WIP feat: swap USDFC back to FIL feat: swap USDFC back to FIL Feb 3, 2026
@pyropy pyropy marked this pull request as ready for review February 3, 2026 10:24
@pyropy pyropy requested review from bajtos, juliangruber and wjmelements and removed request for juliangruber February 3, 2026 11:53
@rjan90 rjan90 moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Feb 3, 2026
@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Feb 3, 2026
@pyropy pyropy requested a review from juliangruber February 4, 2026 15:04
@pyropy
Copy link
Member Author

pyropy commented Feb 4, 2026

@juliangruber I've added bunch of tests to validate functionality of the code. Do you think it would make sense to split it into a separate PR?

sender: config.account.address,
})

if (!sushiswapRouterAddress && config.chainId === 314) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not fatal if this happens on testnet?

Copy link
Member Author

@pyropy pyropy Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not since there is no calibration deployment for sushiswap and so do not perform swaps there.

However, should we leave the mainnet bot running even if we're not able to find the router?

lib/auction.js Outdated
Comment on lines 177 to 183
? publicClient.estimateGas({
account: walletAddress,
to: swapTx.to,
data: swapTx.data,
value: swapTx.value,
})
: Promise.resolve(0n),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work because the simulation would fail without USDFC in the wallet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does swapTx have .gas?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but only when we set simulate param to true which also throws an error if we don't actually have tokens.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed swap gas estimation in afd0e27

Quote HTTP API returns gasSpent property which can be multiplied with the gas price to get an approximate gas requirements for the swap.

@rjan90 rjan90 requested a review from wjmelements February 6, 2026 14:38
@rjan90 rjan90 moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Feb 6, 2026
@juliangruber juliangruber removed their request for review February 9, 2026 14:55
@pyropy pyropy dismissed juliangruber’s stale review February 10, 2026 10:16

dismissed as Julian has unassigned himself.

@pyropy
Copy link
Member Author

pyropy commented Feb 10, 2026

@wjmelements would you be able to give this another pass?

Comment on lines +335 to +338
const swapAmountOut = BigInt(quote.assumedAmountOut)
const totalGasCost = bidGasCost + swapGasCost
const totalCost = auctionPrice + totalGasCost
const isProfitable = swapAmountOut >= totalCost

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the quote was for amount in that includes existingUsdfcBalance, so this is effectively selling any prior balance at a huge discount

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kudos for catching this. Should be fixed in cc572a0 . Now we should get quote for the bid amount only, but swap the whole USDFC amount back to FIL. Now, that doesn't mean that the bot will be profitable, but that's not the goal here.

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FOC Feb 11, 2026
@pyropy pyropy merged commit 8b93653 into main Feb 11, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Feb 11, 2026
@pyropy pyropy deleted the feat/swap-usdfc-back-to-fil branch February 11, 2026 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

Swap USDFC back to FIL with a separate transaction

5 participants