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

STAKE-817 Show Staked ETH position in mobile homepage along with other tokens #4879

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

nickewansmith
Copy link

@nickewansmith nickewansmith commented Oct 31, 2024

Explanation

What is the current state of things and why does it need to change?

  • Currently the metamask-mobile app using the assets-controllers to get information about account token balances. We need to be able to support getting a new type of asset on mainnet and holesky chains, Staked Ethereum, which is not a token but represents the amount of ETH staked using our products.

What is the solution your changes offer and how does it work?

  • We update the AssetContractController with a new method, getStakedBalanceForChain, which gets staked ethereum balances per account from the Stakewise vault contract. We update the AccountTrackerController with options to includeStakedAssets and to add a getStakedBalanceForChain method.
  • We bind AssetContractController.getStakedBalanceForChain to getStakedBalanceForChain option property in metamask-mobile code and then set includeStakingAssets option to the boolean feature flag for ETH Staking on Mobile.
  • We use the AccountTrackerController state in mobile to update the account balance and now, if enabled the stakedBalance as well.

Are there any changes whose purpose might not obvious to those unfamiliar with the domain?

  • We don't want to show stakedBalance if not on a supported network, and so return undefined vs defaulting to zero hex. If there is an error and we are on a supported network, we want to default to zero hex.

If your primary goal was to update one package but you found you had to update another one along the way, why did you do so?

  • There is 1 package affected

If you had to upgrade a dependency, why did you do so?

  • No need to update dependency

References

Are there any issues that this pull request is tied to?

Are there other links that reviewers should consult to understand these changes better?

Are there client or consumer pull requests to adopt any breaking changes?

  • No

Changelog

@metamask/assets-controllers

ADDED: AssetsContractController.getStakedBalanceForChain method to get staked ethereum balance for an address
ADDED: AccountTrackerController options includeStakedEthereum and getStakedBalanceForChain for turning on staked balance functionality and providing a method to do so

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

…troller

- add SupportedStakedBalanceNetworks enum to assetsUtils.ts
- add AssetsContractController->getStakedBalanceForChain to support stakewise contract balance calls
- add ability to includeStakedAssets in AccountTrackerController class options which returns staked balances along with native balance on refresh/sync
@nickewansmith nickewansmith force-pushed the STAKE-817-fe-show-staked-eth-position-in-homepage-along-with-other-tokens branch from 359007a to 4d90470 Compare October 31, 2024 05:50
@nickewansmith nickewansmith marked this pull request as ready for review October 31, 2024 05:54
@nickewansmith nickewansmith requested a review from a team as a code owner October 31, 2024 05:54
Copy link

@amitabh94 amitabh94 left a comment

Choose a reason for hiding this comment

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

Just some questions but overall LGTM!

);
});

it('should update staked balance when includeStakedAssets and multi-account is enabled', async () => {
Copy link

@amitabh94 amitabh94 Oct 31, 2024

Choose a reason for hiding this comment

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

How does this multi account work?

Copy link
Author

Choose a reason for hiding this comment

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

This feature is not currently enabled in production but allows all accounts to get balances refreshed and not just the currently selected account. I added a test here to make sure that the staked balance feature is compatible.

const multiplier = exchangeRateDenominator;
const userShares = await contract.getShares(address);

// convert shares to assets only if address shares > 0 else return default balance

Choose a reason for hiding this comment

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

Do we need to calculate exchange rate here or can we directly get assets from convertToAssets function ?

Copy link
Author

Choose a reason for hiding this comment

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

Hm, you're right we don't really need to get the rate here. Thx will make that change!

@nickewansmith nickewansmith force-pushed the STAKE-817-fe-show-staked-eth-position-in-homepage-along-with-other-tokens branch from d6c3ee7 to a60a14b Compare October 31, 2024 17:37
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.

2 participants