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

[skip ci] wip: chainflip swapper #8049

Draft
wants to merge 84 commits into
base: develop
Choose a base branch
from
Draft

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Oct 30, 2024

Description

Authored to be able to see diff, WIP.
Takes over the monster work done in #7991 by @CumpsD 🐐

  • cleanup
  • if feat: getTradeRate swapper endpoint #7997 goes in first (which it will, most likely), split rates and quotes
  • status endpint 🍺
  • double-check status endpoint is happy for UTXOs sends and receives, not only EVMs
  • make it work (ensure execution is happy)
  • mixpanel

Issue (if applicable)

closes #8026

Risk

High Risk PRs Require 2 approvals

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

Testing

Engineering

Operations

  • 🏁 My feature is behind a flag and doesn't require operations testing (yet)

Screenshots (if applicable)

  • BTC Receive
image image image image image image
  • BTC Sends

Blocked for the time being

  • Native EVM asset send

https://jam.dev/c/bf0f392f-64c1-40ac-a0e6-7a96809e954d

  • EVM token send

https://jam.dev/c/9735bf9d-61aa-404d-96eb-d7e2aa92c0cd

)
}

export const getGasLimit = (chainflipAsset: string) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This won't generalize and should be programmatic. Since we're talking sends, allowance isn't a problem - there will never be allowance required (which, on a tangent, means we should be cognicent in ensuring allowance step is never triggered in swapper)

Comment on lines 30 to 35
export const usdcAssetId: AssetId = 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
export const usdcOnArbitrumOneAssetId: AssetId =
'eip155:42161/erc20:0xaf88d065e77c8cc2239327c5edb3a432268e5831'
export const usdcOnSolanaAssetId: AssetId =
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/token:EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
export const flipAssetId: AssetId = 'eip155:1/erc20:0x826180541412d574cf1336d22c0c0a287822678a'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

all common AssetIds moved into one block + some additions

@@ -169,3 +171,7 @@ REACT_APP_ZERION_BASE_URL=https://api.proxy.shapeshift.com/api/v1/zerion

# 0x
REACT_APP_ZRX_BASE_URL=https://api.proxy.shapeshift.com/api/v1/zrx/

# chainflip
REACT_APP_CHAINFLIP_API_KEY=6ba154d4-e219-472a-9674-5fa5b1300ccf
Copy link

Choose a reason for hiding this comment

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

Give me a ping to set up Shapeshift's API key when going forward, this is currently mine for testing! :) The best person to reach out to me for this would be the one who will be responsible for redeeming affiliate rewards in the future. The one controlling the wallet to sign Chainflip transactions that is (redeeming is a chainflip tx)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good @CumpsD! Is there any reason we should wait for go-live to get an actual API key here, or can we already get one? Will get the convs going already

Copy link

Choose a reason for hiding this comment

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

The key in there right now is actually the one from my swapping Discord bot https://swappy.be/ :) It works, you can test with it, but it charges 0.15% fee (0.05 BaaS + 0.10 Swappy). I can make you a temp one that does only 0.05 (BaaS fee + 0% partner) if you want. You can go live with that as well and swap it out to the Shapeshift one afterwards. lmk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CumpsD just to be sure, we can parametrize fee bps right i.e this isn't tied to the API key used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Current one for dev is absolutely fine, so long as we go live on prod (and ideally on develop as a follow-up) with a proper API key 🙏🏽

Copy link

Choose a reason for hiding this comment

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

@CumpsD just to be sure, we can parametrize fee bps right i.e this isn't tied to the API key used?

Yes, you can pass in commissionBps for both quote and opening a deposit channel (I think I added that in the PR already even! taking in affiliateBps from shapeshift)

export const CHAINFLIP_DCA_SWAP_SOURCE: SwapSource = `${SwapperName.Chainflip} • DCA`
export const CHAINFLIP_DCA_BOOST_SWAP_SOURCE: SwapSource = `${SwapperName.Chainflip} • DCA • Boost`

export const usdcAsset: Asset = {
Copy link

Choose a reason for hiding this comment

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

A fyi, the reason I copied this here is because the usdcAsset in caip is only the assetId, but where I've used it, it also needed precision (in the protocol fees calculations)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's absolutely fine @CumpsD!
Just to disambiguate here, what's the two actual flows when fees will be denominated in USDC? i.e i can see the condition is fee.type === 'network'and fee.type === 'liquidity' && fee.asset === 'usdc.eth' but not sure what this means exactly.

Asking because we may be able to simply use buyAsset / sellAsset if one of these is USDC

Copy link

Choose a reason for hiding this comment

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

Network fee is always USDC, it is the 0.10% buy & burn fee the chainflip network uses.

Liquidity is the LP fee, which I would have to double check but I believe the second leg is always USDC. It's possible this if (fee.type === 'liquidity' && fee.asset === buyChainflipChainKey) return buyAsset might actually never be hit.

Will double check!

Copy link

Choose a reason for hiding this comment

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

Yep, so the second leg seems to be always usdc.eth for the liquidity fee.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to keep the second branch for the sake of paranoia. Tyvm for disambiguating this! Looks like indeed, we need usdc as a static asset then, which means keeping it here as a const is absolutely fine.

Copy link

@CumpsD CumpsD Nov 4, 2024

Choose a reason for hiding this comment

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

Happy to keep the second branch for the sake of paranoia.

Pretty much the reason I added all branches too :D

)
}

const sellChainflipChainKey = `${sellAsset.symbol.toLowerCase()}.${
Copy link

Choose a reason for hiding this comment

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

Another fyi, if you want to improve this. The assets are available here: https://chainflip-broker.io/assets as the id property in the format asset.chain, it just so happened all of them matched the .symbol, but perhaps you want to have this in a mapping in constants as well, like the chains?

Copy link

@CumpsD CumpsD Oct 31, 2024

Choose a reason for hiding this comment

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

I added this to the axios cache on chainflipService by the way, if it helps :) Didn't use it though

const error = maybeQuoteResponse.unwrapErr()
const cause = error.cause as AxiosError<any, any>

if (
Copy link

Choose a reason for hiding this comment

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

This can probably be done cleaner, the error responses follow the problem details rfc, maybe axios has some way to properly parse that to a typed thing instead of the any I had to do here

Copy link

Choose a reason for hiding this comment

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

Also, minimum amounts are also on the https://chainflip-broker.io/assets endpoint as minimalAmountNative

return await getUtxoTxFees({
sellAmountCryptoBaseUnit: sellAmount,
sellAdapter,
publicKey,
})
}

case CHAIN_NAMESPACE.Solana: {
// TODO(gomes): Cosmos SDK too
case CHAIN_NAMESPACE.CosmosSdk:
Copy link

Choose a reason for hiding this comment

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

Will this ever be the case? No idea what CosmosSdk is, but chainflip doesnt support any cosmos chains (right now)

gasPrice: unsignedTxInput.gasPrice,
}
},
getUnsignedUtxoTransaction,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should come back to this module as well since we'll need to add to trade quote meta for status polling


// Assume any state that isn't completed is pending.
// Going forward, we will want to add granular status polling similar to what we do for THOR.
if (state !== 'completed' || !swapEgress?.transactionReference) {
Copy link

Choose a reason for hiding this comment

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

completed or failed imho

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

Successfully merging this pull request may close these issues.

Finish chainflip swapper implementation
2 participants