-
-
Notifications
You must be signed in to change notification settings - Fork 246
SWAPS-2839 update bridge controllers for bitcoin #6454
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
base: main
Are you sure you want to change the base?
SWAPS-2839 update bridge controllers for bitcoin #6454
Conversation
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.
Sorry for the confusion on the spec. The ClientRequest:
bit was only to outline it it's an onClientRequest
import { toHex } from '@metamask/controller-utils'; | ||
import { SolScope } from '@metamask/keyring-api'; | ||
import type { |
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.
nice! I believe you can remove keyring-api from the package.json as well
{ exchangeRate, usdExchangeRate }: ExchangeRate, | ||
chainId: string | number, | ||
) => { | ||
const { nonEvmFeesInNative } = bridgeQuote; |
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.
For 1 SOL, is nonEvmFeesInNative
equal to 1000000000
or 1
?
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.
For 1 SOL, nonEvmFeesInNative equals 1000000000, and the calcNonEvmTotalNetworkFee function converts this to 1 SOL by dividing by 10^9
export type SolanaFees = { | ||
solanaFeesInLamports?: string; // solana fees in lamports, appended by BridgeController.#appendSolanaFees | ||
export type NonEvmFees = { | ||
nonEvmFeesInNative?: string; // Non-EVM chain fees in smallest units (lamports for Solana, satoshis for BTC, sun for Tron) |
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.
Personally I've been calling them atomic
units
* @param chainId - The chain ID to check | ||
* @returns True if the chain is a supported non-EVM chain, false otherwise | ||
*/ | ||
export const isNonEvmChainId = ( |
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 wonder if there's an easier way, otherwise we need to keep updating this for every single new non EVM network
How about:
- Convert chainId to CAIP
- Check CAIP namespace for
eip155
- If
eip155
, then it's EVM
What do you think?
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 like that idea! It does add some testing scope whereas the current functionality is already tested and working. Is this blocking? If not, I'd prefer to get these changes released to unblock the client PR, and then can update the function next week. Let me know what you think and I can add a // TODO comment @infiniteflower
if (isSolanaChainId(chainId)) { | ||
// Solana fees are stored in lamports (smallest units), need to convert to SOL | ||
const decimals = 9; | ||
feeInNative = calcTokenAmount(nonEvmFeesInNative ?? '0', decimals); |
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.
Why do we convert the SOL amount to lamports in bridge-controller.ts if we need to convert it back to SOL here?
Explanation
This PR extends the bridge controller to support Bitcoin transactions, building on the existing Solana support to create a more generic non-EVM chain handling system.
Current state: The bridge controller currently only supports EVM chains and Solana for cross-chain transactions.
Solution: This PR:
instead of SolanaFees, handleNonEvmTx instead of handleSolanaTx)
that work across all non-EVM chains
Key changes:
References
Checklist