-
Notifications
You must be signed in to change notification settings - Fork 177
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
base: develop
Are you sure you want to change the base?
Conversation
) | ||
} | ||
|
||
export const getGasLimit = (chainflipAsset: string) => { |
There was a problem hiding this comment.
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)
packages/caip/src/constants.ts
Outdated
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' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🙏🏽
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()}.${ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
completed
or failed
imho
Description
Authored to be able to see diff, WIP.
Takes over the monster work done in #7991 by @CumpsD 🐐
Issue (if applicable)
closes #8026
Risk
Testing
Engineering
Operations
Screenshots (if applicable)
Blocked for the time being
https://jam.dev/c/bf0f392f-64c1-40ac-a0e6-7a96809e954d
https://jam.dev/c/9735bf9d-61aa-404d-96eb-d7e2aa92c0cd