-
Notifications
You must be signed in to change notification settings - Fork 393
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
Binance Smart Chain support #2659
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.
This is looking good so far :)
Excitedly waiting for this to move out of Draft :)
Note: since you have added swap endpoints you might want to add a token list as well.
@@ -87,7 +99,7 @@ export const BTC: NetworkBaseAsset = { | |||
}, | |||
} | |||
|
|||
export const BASE_ASSETS = [ETH, BTC, MATIC, RBTC, OPTIMISTIC_ETH, AVAX] | |||
export const BASE_ASSETS = [ETH, BTC, MATIC, RBTC, OPTIMISTIC_ETH, AVAX, BNB] |
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.
Love to see this list expand :)
Small nit - description is wrong
|
Asset Price Point should be taken for the correct network. The issue is still on the Overview page.
@jagodarybacka @0xDaedalus @hyphenized @greg-nagy I have a small problem with a BSC chain. The problem is related to the number of decimals for the selected chain. What I mean is that when we want to get the price point in the I made some changes to take the price point for the right chain. After the changes, I was able to display the data correctly in the swap and wallet views. I did some tests and noticed that the data is displayed correctly however in the overview view we don't find the price point for ETH for the BSC chain. The total balance is lower which looks strange. I'm not sure if this is the correct way to go and if this solution is acceptable. Please take a look at my solution What do you think about it? |
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.
Couple of small thoughts.
background/redux-slices/accounts.ts
Outdated
if (assetDecimals > decimals) { | ||
amount /= BigInt(`1${"0".repeat(assetDecimals - 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.
convertFixedPoint
should be your friend here I 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.
Great suggestion!
background/redux-slices/accounts.ts
Outdated
let { amount } = combinedAssetAmount | ||
|
||
if (acc[assetSymbol]?.asset) { | ||
const { decimals } = acc[assetSymbol].asset as FungibleAsset |
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 forced cast seems dangerous, no?
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.
Let's change it and make it simpler.
I think that explicitly passing around the network an asset is related to is an acceptable solution here - but I also wonder if we would benefit from attaching an asset's network to the asset object itself - meaning we make I believe we have everything we need to do this and it feels like a reasonable enough approach. I guess something I'd like to get people's opinion on is if the following mental model makes sense:
|
From the user perspective I agree with @0xDaedalus points - different network should mean it is a different asset even if symbol, name, contract are the same. I can't find more in Figma but I see that @VladUXUI tried adding network icon to assets. We can think about what is the best way to display it (sum similar assets balance across networks, group them together but show balance on each chain separately...). This would need some more work on the Portfolio page so I think it's not in the BSC scope. |
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.
Quick comment + I think it doesn't look the best multiline, can we make the label here shorter or maybe add ellipsis? cc @VladUXUI
ui/utils/constants.ts
Outdated
@@ -23,6 +24,10 @@ export const scanWebsite = { | |||
[GOERLI.chainID]: { title: "Etherscan", url: "https://goerli.etherscan.io/" }, | |||
[ARBITRUM_ONE.chainID]: { title: "Arbiscan", url: "https://arbiscan.io/" }, | |||
[AVALANCHE.chainID]: { title: "Snowtrace", url: "https://snowtrace.io/" }, | |||
[BINANCE_SMART_CHAIN.chainID]: { | |||
title: "Bscscan", |
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.
title: "Bscscan", | |
title: "BscScan", |
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.
Superb work @kkosiorowska 💯! We're so close to shipping this!
I think it's a good idea to include the network in the asset, adding chainId
should be enough but this change might be more involved than just fixing the price point handling. Left some comments on the issue.
background/constants/networks.ts
Outdated
@@ -142,6 +154,7 @@ export const CHAIN_ID_TO_RPC_URLS: { | |||
[ARBITRUM_NOVA.chainID]: ["https://nova.arbitrum.io/rpc "], | |||
[GOERLI.chainID]: ["https://ethereum-goerli-rpc.allthatnode.com"], | |||
[AVALANCHE.chainID]: ["https://api.avax.network/ext/bc/C/rpc"], | |||
[BINANCE_SMART_CHAIN.chainID]: ["https://rpc.ankr.com/bsc"], |
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.
Let's add the official one as well https://bsc-dataseed.binance.org
background/redux-slices/accounts.ts
Outdated
if (targetDecimals > decimals) { | ||
amount = convertFixedPoint( | ||
combinedAssetAmount?.amount, | ||
decimals, | ||
targetDecimals | ||
) | ||
} |
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.
We should be converting here from newAmountDecimals to existingDecimals right? Otherwise the balance is wrong after the object spread below replaces the existing asset (and it's decimals).
if (targetDecimals > decimals) { | |
amount = convertFixedPoint( | |
combinedAssetAmount?.amount, | |
decimals, | |
targetDecimals | |
) | |
} | |
if (newDecimals !== existingDecimals) { | |
amount = convertFixedPoint(amount, newDecimals, existingDecimals) | |
} |
Then we can change the existing logic to not overwrite the existing asset
if (acc[assetSymbol]) {
acc[assetSymbol].amount += amount
} else {
acc[assetSymbol] = {
...combinedAssetAmount,
}
}
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.
Good catch!
const pricedAsset = assets.find( | ||
[ | ||
selectAssetsState, | ||
selectAssetSymbol, |
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.
We can pass the asset object here instead of the symbol
and chainId
separately. I suspect we were using the symbol because it's easier to find an existing price point, but, that's now causing issues for assets with different decimals because this is a best-effort match. For base network assets, it should be enough to find a price point with the symbol alone.
If we pass the asset here we should be able to match by the symbol and use convertFixedPoint
to transform the pricePoint
amount to be more accurate for the wanted asset. We can improve this to take into account BaseNetworkAssets
and SmartContractFungible
assets too but I think it would be better to address this in another issue.
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 agree with you that maybe we should pass on the whole asset here. However, we will probably want to expand the assets to include the home network. Let's fix it in another issue.
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 is def strange here. I think creating a new ticket was a good call for this work.
@jagodarybacka @0xDaedalus @hyphenized @greg-nagy I created a separate task to distinguish assets. Please take a look at it and let me know if you agree. #2709 |
This might be a noob question, but as far as i know it's been called BNB Chain for some time now, since BSC merged with BNB? So maybe let's call it BNB Chain? |
@0xDaedalus and @jagodarybacka good call-out. Because Today and Tomorrow are sort of full, i think we can go ahead and show each asset separately with network icon. Even if they are same asset on different network. |
const pricedAsset = assets.find( | ||
[ | ||
selectAssetsState, | ||
selectAssetSymbol, |
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 is def strange here. I think creating a new ticket was a good call for this work.
@@ -82,7 +82,8 @@ const computeCombinedAssetAmountsData = ( | |||
assets: AssetsState, | |||
mainCurrencySymbol: string, | |||
currentNetwork: EVMNetwork, | |||
hideDust: boolean | |||
hideDust: boolean, | |||
useCurrentNetwork = false |
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 API naming is misleading here because it comes from the selector api.
Here it means every network every asset
sum or current network every asset sum
I would have used something like onlyForCurrentNetwork
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.
looking good, and this is a big win 👸🚀
let's fix the getAssetPricePoint, chainID weirdness in #2709
Ref #2569
This PR adds initial Binance Smart Chain support.
UI
To Test
Set
SUPPORT_BINANCE_SMART_CHAIN
totrue
.Latest build: extension-builds-2659 (as of Mon, 05 Dec 2022 09:42:41 GMT).