Skip to main content

EarnController Actions

20 actions registered.

NameDeprecated
executeLendingDeposit
executeLendingTokenApprove
executeLendingWithdraw
getLendingMarketDailyApysAndAverages
getLendingPositionHistory
getLendingTokenAllowance
getLendingTokenMaxDeposit
getLendingTokenMaxWithdraw
getState
getTronStakingApy
refreshEarnEligibility
refreshLendingData
refreshLendingMarkets
refreshLendingPositions
refreshPooledStakes
refreshPooledStakingData
refreshPooledStakingVaultApyAverages
refreshPooledStakingVaultDailyApys
refreshPooledStakingVaultMetadata
refreshTronStakingApy

EarnController:executeLendingDeposit​

Package: @metamask/earn-controller

Executes a lending deposit transaction.

Parameters:

NameDescription
optionsThe options for the lending deposit transaction.
options.amountThe amount to deposit.
options.chainIdThe chain ID for the lending deposit transaction.
options.protocolThe protocol of the lending market.
options.underlyingTokenAddressThe address of the underlying token.
options.gasOptionsThe gas options for the transaction.
options.gasOptions.gasLimitThe gas limit for the transaction.
options.gasOptions.gasBufferPctThe gas buffer percentage for the transaction.
options.txOptionsThe 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:

NameDescription
optionsThe options for the lending token approve transaction.
options.amountThe amount to approve.
options.chainIdThe chain ID for the lending token approve transaction.
options.protocolThe protocol of the lending market.
options.underlyingTokenAddressThe address of the underlying token.
options.gasOptionsThe gas options for the transaction.
options.gasOptions.gasLimitThe gas limit for the transaction.
options.gasOptions.gasBufferPctThe gas buffer percentage for the transaction.
options.txOptionsThe 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:

NameDescription
optionsThe options for the lending withdraw transaction.
options.amountThe amount to withdraw.
options.chainIdThe chain ID for the lending withdraw transaction.
options.protocolThe protocol of the lending market.
options.underlyingTokenAddressThe address of the underlying token.
options.gasOptionsThe gas options for the transaction.
options.gasOptions.gasLimitThe gas limit for the transaction.
options.gasOptions.gasBufferPctThe gas buffer percentage for the transaction.
options.txOptionsThe 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:

NameDescription
optionsOptional arguments
options.chainIdThe chain id to get lending market daily apys and averages for.
options.protocolThe protocol to get lending market daily apys and averages for.
options.marketIdThe market id to get lending market daily apys and averages for.
options.daysThe 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:

NameDescription
optionsOptional arguments
options.addressThe address to get lending position history for (optional).
options.chainIdThe chain id to get lending position history for.
options.positionIdThe position id to get lending position history for.
options.marketIdThe market id to get lending position history for.
options.marketAddressThe market address to get lending position history for.
options.protocolThe protocol to get lending position history for.
options.daysThe 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:

NameDescription
protocolThe protocol of the lending market.
underlyingTokenAddressThe 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:

NameDescription
protocolThe protocol of the lending market.
underlyingTokenAddressThe 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:

NameDescription
protocolThe protocol of the lending market.
underlyingTokenAddressThe 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:

NameDescription
optionsOptional arguments
options.addressAddress 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:

NameDescription
optionsOptional arguments
options.addressThe 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:

NameDescription
optionsOptional arguments
options.resetCacheControl whether the BE cache should be invalidated (optional).
options.addressThe address to refresh pooled stakes for (optional).
options.chainIdThe 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:

NameDescription
optionsOptional arguments
options.resetCacheControl whether the BE cache should be invalidated (optional).
options.addressThe 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:

NameDescription
chainIdThe 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:

NameDescription
optionsThe options for refreshing pooled staking vault daily apys.
options.chainIdThe chain id to refresh pooled staking vault daily apys for (defaults to Ethereum).
options.daysThe number of days to fetch pooled staking vault daily apys for (defaults to 365).
options.orderThe 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:

NameDescription
chainIdThe 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:

NameDescription
apyFetcherAn 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>