From 66608040c29436d563ff613e82c85426dcd0295c Mon Sep 17 00:00:00 2001 From: Dmitrii Podlesnyi Date: Mon, 3 Jul 2023 17:12:52 +0400 Subject: [PATCH] chore: retiring obsolete motion creation forms --- modules/motions/evmAddresses.ts | 10 +- .../motions/hooks/useRegistryWithLimits.ts | 2 +- modules/motions/providers/motionDetailed.tsx | 8 +- modules/motions/types.ts | 43 ++--- .../MotionFormStartNew/Parts/StartNewLEGO.tsx | 170 ------------------ .../ui/MotionFormStartNew/Parts/index.ts | 5 - .../motions/utils/getContractMethodParams.ts | 34 ---- .../motions/utils/getMotionTypeDisplayName.ts | 4 +- modules/motions/utils/index.ts | 1 - 9 files changed, 28 insertions(+), 249 deletions(-) delete mode 100644 modules/motions/ui/MotionFormStartNew/Parts/StartNewLEGO.tsx delete mode 100644 modules/motions/utils/getContractMethodParams.ts diff --git a/modules/motions/evmAddresses.ts b/modules/motions/evmAddresses.ts index 96029df3..7bfab5e3 100644 --- a/modules/motions/evmAddresses.ts +++ b/modules/motions/evmAddresses.ts @@ -12,7 +12,6 @@ export const EvmAddressesByChain = { [CHAINS.Mainnet]: { [MotionType.NodeOperatorIncreaseLimit]: '0xFeBd8FAC16De88206d4b18764e826AF38546AfE0', - [MotionType.LEGOTopUp]: '0x648C8Be548F43eca4e482C0801Ebccccfb944931', [MotionType.AllowedRecipientTopUpTrpLdo]: '0xBd2b6dC189EefD51B273F5cb2d99BA1ce565fb8C', [MotionType.LegoLDOTopUp]: '0x00caAeF11EC545B192f16313F53912E453c91458', @@ -20,8 +19,6 @@ export const EvmAddressesByChain = { [MotionType.RccDAITopUp]: '0x84f74733ede9bFD53c1B3Ea96338867C94EC313e', [MotionType.PmlDAITopUp]: '0x4E6D3A5023A38cE2C4c5456d3760357fD93A22cD', [MotionType.AtcDAITopUp]: '0x67Fb97ABB9035E2e93A7e3761a0d0571c5d7CD07', - [MotionType.GasFunderETHTopUp]: - '0x41F9daC5F89092dD6061E59578A2611849317dc8', [MotionType.StethRewardProgramAdd]: '0x935cb3366Faf2cFC415B2099d1F974Fd27202b77', [MotionType.StethRewardProgramRemove]: @@ -37,6 +34,9 @@ export const EvmAddressesByChain = { // next motion factories are @deprecated // we are keeping them here to display history data + [MotionType.LEGOTopUp]: '0x648C8Be548F43eca4e482C0801Ebccccfb944931', + [MotionType.GasFunderETHTopUp]: + '0x41F9daC5F89092dD6061E59578A2611849317dc8', [MotionType.RewardProgramAdd]: '0x9D15032b91d01d5c1D940eb919461426AB0dD4e3', [MotionType.RewardProgramRemove]: '0xc21e5e72Ffc223f02fC410aAedE3084a63963932', @@ -66,7 +66,6 @@ export const EvmAddressesByChain = { [CHAINS.Goerli]: { [MotionType.NodeOperatorIncreaseLimit]: '0xE033673D83a8a60500BcE02aBd9007ffAB587714', - [MotionType.LEGOTopUp]: '0xb2bcf211F103d7F13789394DD475c2274e044C4C', [MotionType.AllowedRecipientTopUpTrpLdo]: '0x43f33C52156d1Fb2eA24d82aBfD342E69835E79f', [MotionType.LegoLDOTopUp]: '0xc39Dd5B66968e364D99e0c9E7089049351AB89CA', @@ -74,7 +73,6 @@ export const EvmAddressesByChain = { [MotionType.RccDAITopUp]: '0xd0411e7c4A24E7d4509D5F13AEd19aeb8e5644AB', [MotionType.PmlDAITopUp]: '0xc749aD24572263887Bc888d3Cb854FCD50eCCB61', [MotionType.AtcDAITopUp]: '0xF4b8b5760EE4b5c5Cb154edd0f0841465d821006', - [MotionType.GasFunderETHTopUp]: '0x', [MotionType.StethRewardProgramAdd]: '0x785A8B1CDC03Bb191670Ed4696e9ED5B11Af910A', [MotionType.StethRewardProgramRemove]: @@ -90,6 +88,8 @@ export const EvmAddressesByChain = { // next motion factories are @deprecated // we are keeping them here to display history data + [MotionType.LEGOTopUp]: '0xb2bcf211F103d7F13789394DD475c2274e044C4C', + [MotionType.GasFunderETHTopUp]: '0x', [MotionType.RewardProgramAdd]: '0x5560d40b00EA3a64E9431f97B3c79b04e0cdF6F2', [MotionType.RewardProgramRemove]: '0x31B68d81125E52fE1aDfe4076F8945D1014753b5', diff --git a/modules/motions/hooks/useRegistryWithLimits.ts b/modules/motions/hooks/useRegistryWithLimits.ts index a504af85..5b8ae9ed 100644 --- a/modules/motions/hooks/useRegistryWithLimits.ts +++ b/modules/motions/hooks/useRegistryWithLimits.ts @@ -48,7 +48,7 @@ export const REGISTRY_WITH_LIMITS_BY_MOTION_TYPE = { [MotionType.StethGasSupplyAdd]: ContractStethGasSupplyRegistry, [MotionType.StethGasSupplyRemove]: ContractStethGasSupplyRegistry, [MotionType.StethGasSupplyTopUp]: ContractStethGasSupplyRegistry, -} +} as const type HookArgs = { registryType: keyof typeof REGISTRY_WITH_LIMITS_BY_MOTION_TYPE diff --git a/modules/motions/providers/motionDetailed.tsx b/modules/motions/providers/motionDetailed.tsx index ca2ffb70..2370afd1 100644 --- a/modules/motions/providers/motionDetailed.tsx +++ b/modules/motions/providers/motionDetailed.tsx @@ -7,7 +7,6 @@ import { getMotionTypeByScriptFactory, getMotionTypeDisplayName, getEventMotionCreated, - getContractMethodParams, estimateGasFallback, } from 'modules/motions/utils' import { @@ -130,20 +129,17 @@ export const MotionDetailedProvider: FC = props => { motion.id, ) const gasLimit = await estimateGasFallback( - contractEasyTrack.estimateGas.enactMotion(motion.id, _callData, { - ...getContractMethodParams(motion.evmScriptFactory, 'enact'), - }), + contractEasyTrack.estimateGas.enactMotion(motion.id, _callData), ) const tx = await contractEasyTrack.populateTransaction.enactMotion( motion.id, _callData, { gasLimit, - ...getContractMethodParams(motion.evmScriptFactory, 'enact'), }, ) return tx - }, [contractEasyTrack, motion.evmScriptFactory, motion.id]) + }, [contractEasyTrack, motion.id]) const txEnact = useTransactionSender(populateEnact, { onFinish: onInvalidate, diff --git a/modules/motions/types.ts b/modules/motions/types.ts index 262cd065..a8b0aa09 100644 --- a/modules/motions/types.ts +++ b/modules/motions/types.ts @@ -2,25 +2,32 @@ import type { BigNumber } from 'ethers' import type { PromiseValue } from 'type-fest' import type { EasyTrackAbi } from 'generated' -export const MotionType = { +// Only motions currently supported to start +export const MotionTypeForms = { NodeOperatorIncreaseLimit: 'NodeOperatorIncreaseLimit', - LEGOTopUp: 'LEGOTopUp', AllowedRecipientTopUpTrpLdo: 'AllowedRecipientTopUpTrpLdo', LegoLDOTopUp: 'LegoLDOTopUp', LegoDAITopUp: 'LegoDAITopUp', RccDAITopUp: 'RccDAITopUp', PmlDAITopUp: 'PmlDAITopUp', AtcDAITopUp: 'AtcDAITopUp', - GasFunderETHTopUp: 'GasFunderETHTopUp', StethRewardProgramAdd: 'StethRewardProgramAdd', StethRewardProgramRemove: 'StethRewardProgramRemove', StethRewardProgramTopUp: 'StethRewardProgramTopUp', StethGasSupplyAdd: 'StethGasSupplyAdd', StethGasSupplyRemove: 'StethGasSupplyRemove', StethGasSupplyTopUp: 'StethGasSupplyTopUp', +} as const +// intentionally +// eslint-disable-next-line @typescript-eslint/no-redeclare +export type MotionTypeForms = + typeof MotionTypeForms[keyof typeof MotionTypeForms] - // next motion types are retired - // we are keeping them here to display history data +// next motion types are retired +// we are keeping them here to display history data +export const MotionTypeDisplayOnly = { + LEGOTopUp: 'LEGOTopUp', + GasFunderETHTopUp: 'GasFunderETHTopUp', RewardProgramAdd: 'RewardProgramAdd', RewardProgramRemove: 'RewardProgramRemove', RewardProgramTopUp: 'RewardProgramTopUp', @@ -36,30 +43,16 @@ export const MotionType = { } as const // intentionally // eslint-disable-next-line @typescript-eslint/no-redeclare -export type MotionType = typeof MotionType[keyof typeof MotionType] +export type MotionTypeDisplayOnly = + typeof MotionTypeDisplayOnly[keyof typeof MotionTypeDisplayOnly] -// Only motions currently supported to start -export const MotionTypeForms = { - NodeOperatorIncreaseLimit: MotionType.NodeOperatorIncreaseLimit, - LEGOTopUp: MotionType.LEGOTopUp, - AllowedRecipientTopUpTrpLdo: MotionType.AllowedRecipientTopUpTrpLdo, - LegoLDOTopUp: MotionType.LegoLDOTopUp, - LegoDAITopUp: MotionType.LegoDAITopUp, - RccDAITopUp: MotionType.RccDAITopUp, - PmlDAITopUp: MotionType.PmlDAITopUp, - AtcDAITopUp: MotionType.AtcDAITopUp, - GasFunderETHTopUp: MotionType.GasFunderETHTopUp, - StethRewardProgramAdd: MotionType.StethRewardProgramAdd, - StethRewardProgramRemove: MotionType.StethRewardProgramRemove, - StethRewardProgramTopUp: MotionType.StethRewardProgramTopUp, - StethGasSupplyAdd: MotionType.StethGasSupplyAdd, - StethGasSupplyRemove: MotionType.StethGasSupplyRemove, - StethGasSupplyTopUp: MotionType.StethGasSupplyTopUp, +export const MotionType = { + ...MotionTypeForms, + ...MotionTypeDisplayOnly, } as const // intentionally // eslint-disable-next-line @typescript-eslint/no-redeclare -export type MotionTypeForms = - typeof MotionTypeForms[keyof typeof MotionTypeForms] +export type MotionType = typeof MotionType[keyof typeof MotionType] export const MotionStatus = { ACTIVE: 'ACTIVE', diff --git a/modules/motions/ui/MotionFormStartNew/Parts/StartNewLEGO.tsx b/modules/motions/ui/MotionFormStartNew/Parts/StartNewLEGO.tsx deleted file mode 100644 index c10febbc..00000000 --- a/modules/motions/ui/MotionFormStartNew/Parts/StartNewLEGO.tsx +++ /dev/null @@ -1,170 +0,0 @@ -import { utils } from 'ethers' - -import { useCallback, Fragment } from 'react' -import { useFieldArray, useFormContext } from 'react-hook-form' -import { useWeb3 } from 'modules/blockChain/hooks/useWeb3' -import { useLegoTokenOptions } from 'modules/motions/hooks/useLegoTokenOptions' - -import { ButtonIcon, Plus } from '@lidofinance/lido-ui' -import { PageLoader } from 'modules/shared/ui/Common/PageLoader' -import { InputControl } from 'modules/shared/ui/Controls/Input' -import { SelectControl, Option } from 'modules/shared/ui/Controls/Select' -import { - Fieldset, - MessageBox, - RemoveItemButton, - FieldsWrapper, - FieldsHeader, - FieldsHeaderDesc, -} from '../CreateMotionFormStyle' - -import { ContractEvmLEGOTopUp } from 'modules/blockChain/contracts' -import { MotionType } from 'modules/motions/types' -import { createMotionFormPart } from './createMotionFormPart' -import { validateToken } from 'modules/tokens/utils/validateToken' -import { estimateGasFallback } from 'modules/motions/utils/estimateGasFallback' -import { TRANSITION_LIMITS, tokenLimitError } from 'modules/motions/constants' - -type TokenData = { - address: string - amount: string -} - -export const formParts = createMotionFormPart({ - motionType: MotionType.LEGOTopUp, - populateTx: async ({ evmScriptFactory, formData, contract }) => { - const encodedCallData = new utils.AbiCoder().encode( - ['address[]', 'uint256[]'], - [ - formData.tokens.map(t => utils.getAddress(t.address)), - formData.tokens.map(t => utils.parseEther(t.amount)), - ], - ) - const gasLimit = await estimateGasFallback( - contract.estimateGas.createMotion(evmScriptFactory, encodedCallData), - ) - const tx = await contract.populateTransaction.createMotion( - evmScriptFactory, - encodedCallData, - { gasLimit }, - ) - return tx - }, - getDefaultFormData: () => ({ - tokens: [{ address: '', amount: '' }] as TokenData[], - }), - Component: function StartNewMotionMotionFormLego({ - fieldNames, - submitAction, - }) { - const { chainId, walletAddress } = useWeb3() - const tokenOptions = useLegoTokenOptions() - const fieldsArr = useFieldArray({ name: fieldNames.tokens }) - const trustedCaller = ContractEvmLEGOTopUp.useSwrWeb3('trustedCaller', []) - const isTrustedCallerConnected = trustedCaller.data === walletAddress - - const handleAddToken = useCallback( - () => fieldsArr.append({ address: '', amount: '' }), - [fieldsArr], - ) - - const handleRemoveToken = useCallback( - (i: number) => fieldsArr.remove(i), - [fieldsArr], - ) - - const { watch } = useFormContext() - const selectedTokens: TokenData[] = watch(fieldNames.tokens) - - const getFilteredOptions = (fieldIdx: number) => { - const thatAddress = selectedTokens[fieldIdx].address - const selectedAddresses = selectedTokens.map(({ address }) => address) - return tokenOptions.filter( - ({ value }) => - !selectedAddresses.includes(value) || value === thatAddress, - ) - } - - const getTokenName = (fieldIdx: number) => { - return tokenOptions.find( - ({ value }) => value === selectedTokens[fieldIdx].address, - )?.label - } - - if (trustedCaller.initialLoading) { - return - } - - if (!isTrustedCallerConnected) { - return You should be connected as trusted caller - } - - return ( - <> - {fieldsArr.fields.map((item, i) => ( - - - - Token #{i + 1} - {fieldsArr.fields.length > 1 && ( - handleRemoveToken(i)}> - Remove token - - )} - -
- - {getFilteredOptions(i).map(({ label, value }, j) => ( - -
- -
- { - const check1 = validateToken(value) - if (typeof check1 === 'string') { - return check1 - } - const { address } = selectedTokens[i] - const limit = TRANSITION_LIMITS[chainId][address] - if (Number(value) > limit) { - return tokenLimitError(getTokenName(i), limit) - } - return true - }, - }} - /> -
-
-
- ))} - - {fieldsArr.fields.length < tokenOptions.length && ( -
- } - color="secondary" - /> -
- )} - - {submitAction} - - ) - }, -}) diff --git a/modules/motions/ui/MotionFormStartNew/Parts/index.ts b/modules/motions/ui/MotionFormStartNew/Parts/index.ts index 72acff3a..0b6856bf 100644 --- a/modules/motions/ui/MotionFormStartNew/Parts/index.ts +++ b/modules/motions/ui/MotionFormStartNew/Parts/index.ts @@ -1,7 +1,6 @@ import { MotionTypeForms } from 'modules/motions/types' import * as formNodeOperators from './StartNewNodeOperators' -import * as formLEGO from './StartNewLEGO' import * as formAllowedRecipientAdd from './StartNewAllowedRecipientAdd' import * as formAllowedRecipientRemove from './StartNewAllowedRecipientRemove' import * as formAllowedRecipientTopUp from './StartNewAllowedRecipientTopUp' @@ -9,7 +8,6 @@ import * as StartNewTopUpWithLimits from './StartNewTopUpWithLimits' export const formParts = { [MotionTypeForms.NodeOperatorIncreaseLimit]: formNodeOperators.formParts, - [MotionTypeForms.LEGOTopUp]: formLEGO.formParts, [MotionTypeForms.AllowedRecipientTopUpTrpLdo]: formAllowedRecipientTopUp.formParts({ registryType: MotionTypeForms.AllowedRecipientTopUpTrpLdo, @@ -29,9 +27,6 @@ export const formParts = { [MotionTypeForms.AtcDAITopUp]: StartNewTopUpWithLimits.formParts({ registryType: MotionTypeForms.AtcDAITopUp, }), - [MotionTypeForms.GasFunderETHTopUp]: StartNewTopUpWithLimits.formParts({ - registryType: MotionTypeForms.GasFunderETHTopUp, - }), [MotionTypeForms.StethRewardProgramAdd]: formAllowedRecipientAdd.formParts({ registryType: MotionTypeForms.StethRewardProgramAdd, }), diff --git a/modules/motions/utils/getContractMethodParams.ts b/modules/motions/utils/getContractMethodParams.ts deleted file mode 100644 index 1d38bfd2..00000000 --- a/modules/motions/utils/getContractMethodParams.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { get } from 'lodash' -import { CHAINS } from '@lido-sdk/constants' -import { EvmAddressesByChain } from '../evmAddresses' - -const ACCESS_LISTS_MAP = { - [EvmAddressesByChain[CHAINS.Mainnet].LEGOTopUp]: { - enact: { - type: 2, - accessList: { - '0x3e40D73EB977Dc6a537aF587D48316feE66E9C8c': [ - '0xebb05b386a8d34882b8711d156f463690983dc47815980fb82aeeff1aa43579e', - '0x665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea', - '0xdee64df20d65e53d7f51cb6ab6d921a0a6a638a91e942e1d8d02df28e31c038e', - ], - }, - }, - } as const, - [EvmAddressesByChain[CHAINS.Goerli].LEGOTopUp]: { - enact: { - type: 2, - accessList: { - '0x4333218072d5d7008546737786663c38b4d561a4': [ - '0xebb05b386a8d34882b8711d156f463690983dc47815980fb82aeeff1aa43579e', - '0x665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea', - '0xdee64df20d65e53d7f51cb6ab6d921a0a6a638a91e942e1d8d02df28e31c038e', - ], - }, - }, - } as const, -} as const - -export function getContractMethodParams(contract: string, method: string) { - return get(ACCESS_LISTS_MAP, [contract, method], {}) -} diff --git a/modules/motions/utils/getMotionTypeDisplayName.ts b/modules/motions/utils/getMotionTypeDisplayName.ts index 03f6b0c6..cfc339f3 100644 --- a/modules/motions/utils/getMotionTypeDisplayName.ts +++ b/modules/motions/utils/getMotionTypeDisplayName.ts @@ -7,14 +7,12 @@ export const MotionTypeDisplayNames: Record< > = { [MotionType.NodeOperatorIncreaseLimit]: 'Increase node operator staking limit', - [MotionType.LEGOTopUp]: 'Top up LEGO', [MotionType.AllowedRecipientTopUpTrpLdo]: 'Top up LDO TRP', [MotionType.LegoLDOTopUp]: 'Top up LEGO LDO', [MotionType.LegoDAITopUp]: 'Top up LEGO DAI', [MotionType.RccDAITopUp]: 'Top up RCC DAI', [MotionType.PmlDAITopUp]: 'Top up PML DAI', [MotionType.AtcDAITopUp]: 'Top up ATC DAI', - [MotionType.GasFunderETHTopUp]: 'Top up Gas Funder ETH', [MotionType.StethRewardProgramAdd]: 'Add stETH reward program', [MotionType.StethRewardProgramRemove]: 'Remove stETH reward program', [MotionType.StethRewardProgramTopUp]: 'Top up stETH reward programs', @@ -25,6 +23,8 @@ export const MotionTypeDisplayNames: Record< // next motion types are retired // we are keeping them here to display history data + [MotionType.LEGOTopUp]: 'Top up LEGO', + [MotionType.GasFunderETHTopUp]: 'Top up Gas Funder ETH', [MotionType.RewardProgramAdd]: 'Add reward program', [MotionType.RewardProgramRemove]: 'Remove reward program', [MotionType.RewardProgramTopUp]: 'Top up reward program', diff --git a/modules/motions/utils/index.ts b/modules/motions/utils/index.ts index a1130a20..22507bcc 100644 --- a/modules/motions/utils/index.ts +++ b/modules/motions/utils/index.ts @@ -2,7 +2,6 @@ export * from './checkInputsGreaterThanLimit' export * from './estimateGasFallback' export * from './formatMotionDataOnchain' export * from './formatMotionDataSubgraph' -export * from './getContractMethodParams' export * from './getEventMotionCanceled' export * from './getEventMotionCreation' export * from './getEventsAllowedRecipientAdded'