From eb2ae987cc6d65516a1993d66b5ed38475fc7754 Mon Sep 17 00:00:00 2001 From: Matthew Walsh Date: Thu, 31 Oct 2024 11:04:38 +0000 Subject: [PATCH] feat: add staking transaction types (#4874) --- packages/transaction-controller/src/types.ts | 61 ++++++------------- .../src/utils/validation.test.ts | 5 +- 2 files changed, 21 insertions(+), 45 deletions(-) diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index b806f13bc6a..f70679a6bc8 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -542,6 +542,7 @@ export enum WalletDevice { OTHER = 'other_device', } +/* eslint-disable @typescript-eslint/naming-convention */ /** * The type of the transaction. */ @@ -549,8 +550,6 @@ export enum TransactionType { /** * A transaction that bridges tokens to a different chain through Metamask Bridge. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention bridge = 'bridge', /** @@ -559,15 +558,11 @@ export enum TransactionType { * of the user for the MetaMask Bridge contract. The first bridge for any token * will have an accompanying bridgeApproval transaction. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention bridgeApproval = 'bridgeApproval', /** * A transaction sending a network's native asset to a recipient. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention cancel = 'cancel', /** @@ -575,43 +570,31 @@ export enum TransactionType { * have not treated as a special case, such as approve, transfer, and * transferfrom. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention contractInteraction = 'contractInteraction', /** * A transaction that deployed a smart contract. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention deployContract = 'contractDeployment', /** * A transaction for Ethereum decryption. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention ethDecrypt = 'eth_decrypt', /** * A transaction for getting an encryption public key. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention ethGetEncryptionPublicKey = 'eth_getEncryptionPublicKey', /** * An incoming (deposit) transaction. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention incoming = 'incoming', /** * A transaction for personal sign. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention personalSign = 'personal_sign', /** @@ -620,43 +603,46 @@ export enum TransactionType { * to speed up pending transactions. This is accomplished by creating a new tx with * the same nonce and higher gas fees. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention retry = 'retry', /** * A transaction sending a network's native asset to a recipient. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention simpleSend = 'simpleSend', /** * A transaction that is signing typed data. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention signTypedData = 'eth_signTypedData', /** * A transaction sending a network's native asset to a recipient. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention smart = 'smart', + /** + * A transaction that claims staking rewards. + */ + stakingClaim = 'stakingClaim', + + /** + * A transaction that deposits tokens into a staking contract. + */ + stakingDeposit = 'stakingDeposit', + + /** + * A transaction that unstakes tokens from a staking contract. + */ + stakingUnstake = 'stakingUnstake', + /** * A transaction swapping one token for another through MetaMask Swaps. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention swap = 'swap', /** * A transaction swapping one token for another through MetaMask Swaps, then sending the swapped token to a recipient. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention swapAndSend = 'swapAndSend', /** @@ -665,16 +651,12 @@ export enum TransactionType { * of the user for the MetaMask Swaps contract. The first swap for any token * will have an accompanying swapApproval transaction. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention swapApproval = 'swapApproval', /** * A token transaction requesting an allowance of the token to spend on * behalf of the user. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodApprove = 'approve', /** @@ -683,16 +665,12 @@ export enum TransactionType { * this method the contract checks to ensure that the receiver is an address * capable of handling the token being sent. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodSafeTransferFrom = 'safetransferfrom', /** * A token transaction where the user is sending tokens that they own to * another address. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodTransfer = 'transfer', /** @@ -700,25 +678,20 @@ export enum TransactionType { * has an allowance of. For more information on allowances, see the approve * type. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodTransferFrom = 'transferfrom', /** * A token transaction requesting an allowance of all of a user's tokens to * spend on behalf of the user. */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodSetApprovalForAll = 'setapprovalforall', /** * Increase the allowance by a given increment */ - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/naming-convention tokenMethodIncreaseAllowance = 'increaseAllowance', } +/* eslint-enable @typescript-eslint/naming-convention */ /** * Standard data concerning a transaction to be processed by the blockchain. diff --git a/packages/user-operation-controller/src/utils/validation.test.ts b/packages/user-operation-controller/src/utils/validation.test.ts index cdb2f26fa87..180221394f3 100644 --- a/packages/user-operation-controller/src/utils/validation.test.ts +++ b/packages/user-operation-controller/src/utils/validation.test.ts @@ -1,5 +1,6 @@ /* eslint-disable jest/expect-expect */ +import { TransactionType } from '@metamask/transaction-controller'; import { cloneDeep } from 'lodash'; import type { @@ -341,7 +342,9 @@ describe('validation', () => { 'type', 'wrong type', 123, - 'Expected one of `"bridge","bridgeApproval","cancel","contractInteraction","contractDeployment","eth_decrypt","eth_getEncryptionPublicKey","incoming","personal_sign","retry","simpleSend","eth_signTypedData","smart","swap","swapAndSend","swapApproval","approve","safetransferfrom","transfer","transferfrom","setapprovalforall","increaseAllowance"`, but received: 123', + `Expected one of \`${Object.values(TransactionType) + .map((value) => `"${value as string}"`) + .join(',')}\`, but received: 123`, ], ])( 'throws if %s is %s',