EarnController Actions
20 actions registered.
EarnController:executeLendingDeposit
Package: @metamask/earn-controller
Executes a lending deposit transaction.
Parameters:
| Name | Description |
|---|---|
options | The options for the lending deposit transaction. |
options.amount | The amount to deposit. |
options.chainId | The chain ID for the lending deposit transaction. |
options.protocol | The protocol of the lending market. |
options.underlyingTokenAddress | The address of the underlying token. |
options.gasOptions | The gas options for the transaction. |
options.gasOptions.gasLimit | The gas limit for the transaction. |
options.gasOptions.gasBufferPct | The gas buffer percentage for the transaction. |
options.txOptions | The transaction options for the transaction. |
Returns: A promise that resolves to the transaction hash.
Handler signature:
({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
amount: string;
chainId: string;
protocol: LendingMarket['protocol'];
underlyingTokenAddress: string;
gasOptions: {
gasLimit?: GasLimitParams;
gasBufferPct?: number;
};
txOptions: Parameters<typeof TransactionController.prototype.addTransaction>[1];
}) => Promise<import("@metamask/transaction-controller").Result>
EarnController:executeLendingTokenApprove
Package: @metamask/earn-controller
Executes a lending token approve transaction.
Parameters:
| Name | Description |
|---|---|
options | The options for the lending token approve transaction. |
options.amount | The amount to approve. |
options.chainId | The chain ID for the lending token approve transaction. |
options.protocol | The protocol of the lending market. |
options.underlyingTokenAddress | The address of the underlying token. |
options.gasOptions | The gas options for the transaction. |
options.gasOptions.gasLimit | The gas limit for the transaction. |
options.gasOptions.gasBufferPct | The gas buffer percentage for the transaction. |
options.txOptions | The transaction options for the transaction. |
Returns: A promise that resolves to the transaction hash.
Handler signature:
({ protocol, amount, chainId, underlyingTokenAddress, gasOptions, txOptions, }: {
protocol: LendingMarket['protocol'];
amount: string;
chainId: string;
underlyingTokenAddress: string;
gasOptions: {
gasLimit?: GasLimitParams;
gasBufferPct?: number;
};
txOptions: Parameters<typeof TransactionController.prototype.addTransaction>[1];
}) => Promise<import("@metamask/transaction-controller").Result>
EarnController:executeLendingWithdraw
Package: @metamask/earn-controller
Executes a lending withdraw transaction.
Parameters:
| Name | Description |
|---|---|
options | The options for the lending withdraw transaction. |
options.amount | The amount to withdraw. |
options.chainId | The chain ID for the lending withdraw transaction. |
options.protocol | The protocol of the lending market. |
options.underlyingTokenAddress | The address of the underlying token. |
options.gasOptions | The gas options for the transaction. |
options.gasOptions.gasLimit | The gas limit for the transaction. |
options.gasOptions.gasBufferPct | The gas buffer percentage for the transaction. |
options.txOptions | The transaction options for the transaction. |
Returns: A promise that resolves to the transaction hash.
Handler signature:
({ amount, chainId, protocol, underlyingTokenAddress, gasOptions, txOptions, }: {
amount: string;
chainId: string;
protocol: LendingMarket['protocol'];
underlyingTokenAddress: string;
gasOptions: {
gasLimit?: GasLimitParams;
gasBufferPct?: number;
};
txOptions: Parameters<typeof TransactionController.prototype.addTransaction>[1];
}) => Promise<import("@metamask/transaction-controller").Result>
EarnController:getLendingMarketDailyApysAndAverages
Package: @metamask/earn-controller
Gets the lending market daily apys and averages for the current chain.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.chainId | The chain id to get lending market daily apys and averages for. |
options.protocol | The protocol to get lending market daily apys and averages for. |
options.marketId | The market id to get lending market daily apys and averages for. |
options.days | The number of days to get lending market daily apys and averages for (optional). |
Returns: A promise that resolves when the lending market daily apys and averages have been updated
Handler signature:
({ chainId, protocol, marketId, days, }: {
chainId: number;
protocol: string;
marketId: string;
days?: number;
}) => Promise<HistoricLendingMarketApys> | undefined
EarnController:getLendingPositionHistory
Package: @metamask/earn-controller
Gets the lending position history for the current account.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.address | The address to get lending position history for (optional). |
options.chainId | The chain id to get lending position history for. |
options.positionId | The position id to get lending position history for. |
options.marketId | The market id to get lending position history for. |
options.marketAddress | The market address to get lending position history for. |
options.protocol | The protocol to get lending position history for. |
options.days | The number of days to get lending position history for (optional). |
Returns: A promise that resolves when the lending position history has been updated
Handler signature:
({ address, chainId, positionId, marketId, marketAddress, protocol, days, }: {
address?: string;
chainId: number;
positionId: string;
marketId: string;
marketAddress: string;
protocol: string;
days?: number;
}) => never[] | Promise<import("@metamask/stake-sdk").LendingPositionHistory[]>
EarnController:getLendingTokenAllowance
Package: @metamask/earn-controller
Gets the allowance for a lending token.
Parameters:
| Name | Description |
|---|---|
protocol | The protocol of the lending market. |
underlyingTokenAddress | The address of the underlying token. |
Returns: A promise that resolves to the allowance.
Handler signature:
(protocol: LendingMarket['protocol'], underlyingTokenAddress: string) => Promise<BigNumber | undefined>
EarnController:getLendingTokenMaxDeposit
Package: @metamask/earn-controller
Gets the maximum deposit amount for a lending token.
Parameters:
| Name | Description |
|---|---|
protocol | The protocol of the lending market. |
underlyingTokenAddress | The address of the underlying token. |
Returns: A promise that resolves to the maximum deposit amount.
Handler signature:
(protocol: LendingMarket['protocol'], underlyingTokenAddress: string) => Promise<BigNumber | undefined>
EarnController:getLendingTokenMaxWithdraw
Package: @metamask/earn-controller
Gets the maximum withdraw amount for a lending token's output token or shares if no output token.
Parameters:
| Name | Description |
|---|---|
protocol | The protocol of the lending market. |
underlyingTokenAddress | The address of the underlying token. |
Returns: A promise that resolves to the maximum withdraw amount.
Handler signature:
(protocol: LendingMarket['protocol'], underlyingTokenAddress: string) => Promise<BigNumber | undefined>
EarnController:getState
Package: @metamask/earn-controller
The action which can be used to retrieve the state of the EarnController.
Handler signature:
() => EarnControllerState
EarnController:getTronStakingApy
Package: @metamask/earn-controller
Gets the TRON staking APY.
Returns: The APY for TRON staking, or undefined if not available.
Handler signature:
() => string | undefined
EarnController:refreshEarnEligibility
Package: @metamask/earn-controller
Refreshes the earn eligibility status for the current account. Updates the eligibility status in the controller state based on the location and address blocklist for compliance.
Note: Pooled-staking and Lending used the same result since there isn't a need to split these up right now.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.address | Address to refresh earn eligibility for (optional). |
Returns: A promise that resolves when the eligibility status has been updated
Handler signature:
({ address, }?: RefreshEarnEligibilityOptions) => Promise<void>
EarnController:refreshLendingData
Package: @metamask/earn-controller
Refreshes all lending related data including markets, positions, and eligibility. This method allows partial success, meaning some data may update while other requests fail. All errors are collected and thrown as a single error message.
Returns: A promise that resolves when all possible data has been updated
Handler signature:
() => Promise<void>
EarnController:refreshLendingMarkets
Package: @metamask/earn-controller
Refreshes the lending markets data for all chains. Updates the lending markets in the controller state.
Returns: A promise that resolves when the lending markets have been updated
Handler signature:
() => Promise<void>
EarnController:refreshLendingPositions
Package: @metamask/earn-controller
Refreshes the lending positions for the current account. Updates the lending positions in the controller state.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.address | The address to refresh lending positions for (optional). |
Returns: A promise that resolves when the lending positions have been updated
Handler signature:
({ address, }?: RefreshLendingPositionsOptions) => Promise<void>
EarnController:refreshPooledStakes
Package: @metamask/earn-controller
Refreshes the pooled stakes data for the current account. Fetches updated stake information including lifetime rewards, assets, and exit requests from the staking API service and updates the state.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.resetCache | Control whether the BE cache should be invalidated (optional). |
options.address | The address to refresh pooled stakes for (optional). |
options.chainId | The chain id to refresh pooled stakes for (optional). |
Returns: A promise that resolves when the stakes data has been updated
Handler signature:
({ resetCache, address, chainId, }?: RefreshPooledStakesOptions) => Promise<void>
EarnController:refreshPooledStakingData
Package: @metamask/earn-controller
Refreshes all pooled staking related data including stakes, eligibility, and vault data. This method allows partial success, meaning some data may update while other requests fail. All errors are collected and thrown as a single error message.
Parameters:
| Name | Description |
|---|---|
options | Optional arguments |
options.resetCache | Control whether the BE cache should be invalidated (optional). |
options.address | The address to refresh pooled stakes for (optional). |
Returns: A promise that resolves when all possible data has been updated
Handler signature:
({ resetCache, address, }?: RefreshPooledStakingDataOptions) => Promise<void>
EarnController:refreshPooledStakingVaultApyAverages
Package: @metamask/earn-controller
Refreshes pooled staking vault apy averages for the current chain. Updates the pooled staking vault apy averages controller state.
Parameters:
| Name | Description |
|---|---|
chainId | The chain id to refresh pooled staking vault apy averages for (optional). |
Returns: A promise that resolves when the pooled staking vault apy averages have been updated.
Handler signature:
(chainId?: number) => Promise<void>
EarnController:refreshPooledStakingVaultDailyApys
Package: @metamask/earn-controller
Refreshes pooled staking vault daily apys for the current chain. Updates the pooled staking vault daily apys controller state.
Parameters:
| Name | Description |
|---|---|
options | The options for refreshing pooled staking vault daily apys. |
options.chainId | The chain id to refresh pooled staking vault daily apys for (defaults to Ethereum). |
options.days | The number of days to fetch pooled staking vault daily apys for (defaults to 365). |
options.order | The order in which to fetch pooled staking vault daily apys. Descending order fetches the latest N days (latest working backwards). Ascending order fetches the oldest N days (oldest working forwards) (defaults to 'desc'). |
Returns: A promise that resolves when the pooled staking vault daily apys have been updated.
Handler signature:
({ chainId, days, order, }?: RefreshPooledStakingVaultDailyApysOptions) => Promise<void>
EarnController:refreshPooledStakingVaultMetadata
Package: @metamask/earn-controller
Refreshes pooled staking vault metadata for the current chain. Updates the vault metadata in the controller state including APY, capacity, fee percentage, total assets, and vault address.
Parameters:
| Name | Description |
|---|---|
chainId | The chain id to refresh pooled staking vault metadata for (optional). |
Returns: A promise that resolves when the vault metadata has been updated
Handler signature:
(chainId?: number) => Promise<void>
EarnController:refreshTronStakingApy
Package: @metamask/earn-controller
Refreshes the APY for TRON staking. The consumer provides a fetcher function that returns the APY for TRON.
Parameters:
| Name | Description |
|---|---|
apyFetcher | An async function that fetches and returns the APY as a decimal string. |
Returns: A promise that resolves when the APY has been updated.
Handler signature:
(apyFetcher: () => Promise<string>) => Promise<void>