Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add uniswap swap quote provider #73

Merged
merged 32 commits into from
Jul 25, 2024

Conversation

janndriessen
Copy link
Collaborator

@janndriessen janndriessen commented Jun 28, 2024

  • Adds UniswapSwapQuoteProvider
  • Adds CurveSwapQuoteProvider
  • Adds provider to combine Uniswap and Curve quotes for potentially replacing 0x

Resources

Tests

The Number is the indexTokenAmount e.g. 1 BTC2x/ETH means minting 1 BTC2x with ETH.

  • 1 BTC2x/ETH ✅
    • 0x: 31218855312224373, Uniswap: 31140884101062165
    • diff: +0,00007797121116 (~$0.2714957573)
  • 1 ETH2x/ETH ✅
    • 0x: 24676197216674554, Uniswap: 24633062733307580
    • diff: +0.00004313448337 (~$0.15)
  • 1 hyETH/ETH ✅
    • 0x: 1193325273405705946, Uniswap: 1194770128447086764
    • diff: +0.001444855041 (~$5.0235, + 0.14%)
  • 1 hyETH/USDC ✅
    • 0x: 1193325273405705946, Uniswap: 1194770128447086764
    • diff: +0.001444855041 (~$5.0235, + 0.14%)
  • 1 icETH/ETH ✅
    • 0x: 1119935057816718678, Uniswap: 1130470406314721726
    • diff: -0.0105353485 (~$34.82)
  • 0.1 icETH/WETH ✅
    • 0x: 112517489203671567, Uniswap: 113380656522522445
    • diff: -0.0008631673189 (~$3.01)

These test do not check for deep liquidity.

TODOs

  • return encoded call data from uniswap swap quote provider (won't do)
  • compare quotes of 0x and new swap quote provider


import { getSwapData } from './swap-data'

export class CurveSwapQuoteProvider implements SwapQuoteProvider {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This adapter we need for a few products that specifically use quotes of a Curve pool for ETH/stETH.

exchange: Exchange.Curve,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
path: [WETH.address!, stETH.address!],
fees: [], // not needed for curve
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be correct with what I saw in tests but please confirm @ckoopmann

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, should be correct.

I'm not 100% sure now at one point the condition fees.length = path.length - 1 is checked. It should only be checked for uniswap swaps, but if you do end up getting "path / fee length mismatch" errors, then just set fees: [0].
Just in case, shouldn't be necessary though.

return [inputToken, outputToken]
}
return [inputToken, weth, outputToken]
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Might not need this and will delete later.

outputToken,
inputAmount: inputAmount ?? quotedAmount,
outputAmount: outputAmount ?? quotedAmount,
callData: '0x', // TOOD:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ckoopmann I would assume this is the call data for the 0x contract right? Or would it work to send a Uniswap encoded tx call data here?

This should be only relevant for the FlashMintZeroEx contract, correct? https://github.com/IndexCoop/flash-mint-sdk/blob/main/src/quote/flashmint/zeroEx/provider.ts#L91

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we only need fully encoded calldata for 0x interactions.
All other flashmint contracts encode the calldata themselves based on the SwapData object provided.

return await curveSwapQuoteProvider.getSwapQuote(request)
}
const uniswapSwapQuoteProvider = new UniswapSwapQuoteProvider(this.rpcUrl)
return await uniswapSwapQuoteProvider.getSwapQuote(request)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just a simple check to take Curve for ETH/stETH. Otherwise, use Uniswap V3 (or V2).

Copy link
Collaborator

@0xonramp 0xonramp left a comment

Choose a reason for hiding this comment

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

👍

isSameAddress(inputToken, EthAddress) ||
isSameAddress(outputToken, EthAddress)
) {
// FIXME: remove for production, just for runnint tests and catching any of these cases
Copy link
Collaborator

Choose a reason for hiding this comment

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

Flagging for pre-release

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll keep this until we have part 2 because it now actually shouldn't happen anymore but might catch some "bugs".

@janndriessen janndriessen marked this pull request as ready for review July 25, 2024 19:38
@janndriessen janndriessen merged commit 923c7c6 into main Jul 25, 2024
2 checks passed
@janndriessen janndriessen deleted the feat/add-uniswap-swap-quote-provider branch July 25, 2024 19:39
Copy link

🎉 This PR is included in version 3.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants