Skip to content

Commit

Permalink
feat: add earn controller package (#5210)
Browse files Browse the repository at this point in the history
This PR adds the new earn controller that will support both existing
products like Pooled staking and upcoming products like stablecoin
lending .

This is the first version of the controller and currently initailizes
the stake-sdk and implements functions to fetch staking data and update
state.


## References

Related to
[STAKE-896](https://consensyssoftware.atlassian.net/browse/STAKE-896)

<!--
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?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/earn-controller`

- **ADDED**: Initial release of the `EarnController` package for
managing DeFi earning opportunities
- **ADDED**: Support for pooled staking products with features:
  - Automatic state management for staking data
  - Real-time updates on network and account changes
  - Integration with `@metamask/stake-sdk`
  - Eligibility checks for staking products
- **ADDED**: Support for stablecoin lending products with state
management for:
  - Vault information (APY, liquidity, supply)

## Checklist

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


[STAKE-896]:
https://consensyssoftware.atlassian.net/browse/STAKE-896?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
  • Loading branch information
amitabh94 authored Jan 31, 2025
1 parent 58db413 commit 2ec8c03
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
/packages/transaction-controller @MetaMask/confirmations
/packages/user-operation-controller @MetaMask/confirmations

## Earn Team
/packages/earn-controller @MetaMask/earn
## Notifications Team
/packages/notification-services-controller @MetaMask/notifications

Expand Down Expand Up @@ -74,6 +76,8 @@
/packages/approval-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/assets-controllers/package.json @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
/packages/assets-controllers/CHANGELOG.md @MetaMask/metamask-assets @MetaMask/wallet-framework-engineers
/packages/earn-controller/package.json @MetaMask/earn @MetaMask/wallet-framework-engineers
/packages/earn-controller/CHANGELOG.md @MetaMask/earn @MetaMask/wallet-framework-engineers
/packages/ens-controller/package.json @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/ens-controller/CHANGELOG.md @MetaMask/confirmations @MetaMask/wallet-framework-engineers
/packages/gas-fee-controller/package.json @MetaMask/confirmations @MetaMask/wallet-framework-engineers
Expand Down Expand Up @@ -108,3 +112,4 @@
/packages/multichain-transactions-controller/CHANGELOG.md @MetaMask/accounts-engineers @MetaMask/wallet-framework-engineers
/packages/token-search-discovery-controller/package.json @MetaMask/portfolio @MetaMask/wallet-framework-engineers
/packages/token-search-discovery-controller/CHANGELOG.md @MetaMask/portfolio @MetaMask/wallet-framework-engineers

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/build-utils`](packages/build-utils)
- [`@metamask/composable-controller`](packages/composable-controller)
- [`@metamask/controller-utils`](packages/controller-utils)
- [`@metamask/earn-controller`](packages/earn-controller)
- [`@metamask/ens-controller`](packages/ens-controller)
- [`@metamask/eth-json-rpc-provider`](packages/eth-json-rpc-provider)
- [`@metamask/gas-fee-controller`](packages/gas-fee-controller)
Expand Down Expand Up @@ -74,6 +75,7 @@ linkStyle default opacity:0.5
build_utils(["@metamask/build-utils"]);
composable_controller(["@metamask/composable-controller"]);
controller_utils(["@metamask/controller-utils"]);
earn_controller(["@metamask/earn-controller"]);
ens_controller(["@metamask/ens-controller"]);
eth_json_rpc_provider(["@metamask/eth-json-rpc-provider"]);
gas_fee_controller(["@metamask/gas-fee-controller"]);
Expand Down
10 changes: 10 additions & 0 deletions packages/earn-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/core/
20 changes: 20 additions & 0 deletions packages/earn-controller/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 changes: 15 additions & 0 deletions packages/earn-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@metamask/earn-controller`

Manages state for earning features and coordinates interactions between staking services, SDK integrations, and other controllers to enable users to participate in various earning opportunities.

## Installation

`yarn add @metamask/earn-controller`

or

`npm install @metamask/earn-controller`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/earn-controller/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
78 changes: 78 additions & 0 deletions packages/earn-controller/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "@metamask/earn-controller",
"version": "0.0.0",
"description": "Manages state for earning features and coordinates interactions between staking services, SDK integrations, and other controllers to enable users to participate in various earning opportunities",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/earn-controller#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:docs": "typedoc",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/earn-controller",
"changelog:update": "../../scripts/update-changelog.sh @metamask/earn-controller",
"publish:preview": "yarn npm publish --tag preview",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch",
"since-latest-release": "../../scripts/since-latest-release.sh"
},
"dependencies": {
"@ethersproject/providers": "^5.7.0",
"@metamask/base-controller": "^7.1.1",
"@metamask/controller-utils": "^11.4.5",
"@metamask/stake-sdk": "^1.0.0"
},
"devDependencies": {
"@metamask/accounts-controller": "^22.0.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/network-controller": "^22.1.1",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
},
"peerDependencies": {
"@metamask/accounts-controller": "^22.0.0",
"@metamask/network-controller": "^22.1.1"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Loading

0 comments on commit 2ec8c03

Please sign in to comment.