From a16a96a708a3dffb20f8b04ca461afc8df2001aa Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 18 Dec 2024 14:40:11 +0000 Subject: [PATCH 1/8] fix: migration OLAS balance checks --- .../CantMigrateAlert.tsx | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx b/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx index 0cfbf281..ee81ae83 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx @@ -1,5 +1,5 @@ import { Flex, Typography } from 'antd'; -import { isEmpty, isNil } from 'lodash'; +import { isEmpty, isNil, sum } from 'lodash'; import { useMemo } from 'react'; import { CustomAlert } from '@/components/Alert'; @@ -14,10 +14,7 @@ import { } from '@/hooks/useBalanceContext'; import { useNeedsFunds } from '@/hooks/useNeedsFunds'; import { useServices } from '@/hooks/useServices'; -import { - useActiveStakingContractDetails, - useStakingContractContext, -} from '@/hooks/useStakingContractDetails'; +import { useStakingContractContext } from '@/hooks/useStakingContractDetails'; import { balanceFormat } from '@/utils/numberFormatters'; import { CantMigrateReason } from './useMigrate'; @@ -32,9 +29,10 @@ const AlertInsufficientMigrationFunds = ({ const { selectedAgentConfig } = useServices(); const { isAllStakingContractDetailsRecordLoaded } = useStakingContractContext(); - const { isServiceStaked } = useActiveStakingContractDetails(); - const { isLoaded: isBalanceLoaded, totalStakedOlasBalance } = - useBalanceContext(); + const { + isLoaded: isBalanceLoaded, + totalStakedOlasBalance: totalStakedOlasBalanceOnHomeChain, + } = useBalanceContext(); const { masterSafeBalances } = useMasterBalances(); const { serviceFundRequirements, isInitialFunded } = useNeedsFunds( stakingProgramIdToMigrateTo, @@ -45,7 +43,7 @@ const AlertInsufficientMigrationFunds = ({ TokenSymbol.OLAS ]; - const safeBalance = useMemo(() => { + const masterSafeBalanceOnHomeChain = useMemo(() => { if (!isBalanceLoaded) return; if (isNil(masterSafeBalances) || isEmpty(masterSafeBalances)) return; return masterSafeBalances.reduce( @@ -61,14 +59,15 @@ const AlertInsufficientMigrationFunds = ({ if (!isAllStakingContractDetailsRecordLoaded) return null; if (isNil(requiredStakedOlas)) return null; - if (isNil(safeBalance?.[TokenSymbol.OLAS])) return null; + if (isNil(masterSafeBalanceOnHomeChain?.[TokenSymbol.OLAS])) return null; - if (isNil(totalStakedOlasBalance)) return null; + if (isNil(totalStakedOlasBalanceOnHomeChain)) return null; - const requiredOlasDeposit = isServiceStaked - ? requiredStakedOlas - - (totalStakedOlasBalance + safeBalance[TokenSymbol.OLAS]) // when staked - : requiredStakedOlas - safeBalance[TokenSymbol.OLAS]; // when not staked + const requiredOlasDeposit = sum([ + masterSafeBalanceOnHomeChain[TokenSymbol.OLAS], + totalStakedOlasBalanceOnHomeChain, + -requiredStakedOlas, + ]); const homeChainId = selectedAgentConfig.evmHomeChainId; const nativeTokenSymbol = getNativeTokenSymbol(homeChainId); @@ -76,9 +75,9 @@ const AlertInsufficientMigrationFunds = ({ ? selectedAgentConfig.operatingThresholds[WalletOwnerType.Master][ WalletType.Safe ][CHAIN_CONFIG[selectedAgentConfig.evmHomeChainId].nativeToken.symbol] - - (safeBalance[nativeTokenSymbol] || 0) // is already funded allow minimal maintenance + (masterSafeBalanceOnHomeChain[nativeTokenSymbol] || 0) // is already funded allow minimal maintenance : (serviceFundRequirements[homeChainId]?.[nativeTokenSymbol] || 0) - - (safeBalance[nativeTokenSymbol] || 0); // otherwise require full initial funding requirements + (masterSafeBalanceOnHomeChain[nativeTokenSymbol] || 0); // otherwise require full initial funding requirements return ( Date: Wed, 18 Dec 2024 15:33:46 +0000 Subject: [PATCH 2/8] chore: delete comment --- frontend/components/MainPage/index.tsx | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/frontend/components/MainPage/index.tsx b/frontend/components/MainPage/index.tsx index 0e2be2e5..893010af 100644 --- a/frontend/components/MainPage/index.tsx +++ b/frontend/components/MainPage/index.tsx @@ -19,25 +19,6 @@ export const Main = () => { const isStakingContractSectionEnabled = useFeatureFlag( 'staking-contract-section', ); - // const { refetch: updateServicesState } = useServices(); - // const { - // updateBalances, - // isLoaded: isBalanceLoaded, - // setIsLoaded: setIsBalanceLoaded, - // } = useBalanceContext(); - - // TODO: reintroduce later, non critical - // useEffect(() => { - // if (!isBalanceLoaded) { - // updateServicesState?.().then(() => updateBalances()); - // setIsBalanceLoaded(true); - // } - // }, [ - // isBalanceLoaded, - // setIsBalanceLoaded, - // updateBalances, - // updateServicesState, - // ]); return ( Date: Wed, 18 Dec 2024 15:33:59 +0000 Subject: [PATCH 3/8] fix: balance section shouldn't check every chain/service --- .../MainPage/sections/OlasBalanceSection.tsx | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/frontend/components/MainPage/sections/OlasBalanceSection.tsx b/frontend/components/MainPage/sections/OlasBalanceSection.tsx index c4e3dfe3..9c1c2cae 100644 --- a/frontend/components/MainPage/sections/OlasBalanceSection.tsx +++ b/frontend/components/MainPage/sections/OlasBalanceSection.tsx @@ -26,7 +26,7 @@ const Balance = styled.span` `; export const MainOlasBalance = () => { - const { selectedService } = useServices(); + const { selectedService, selectedAgentConfig } = useServices(); const { isLoaded: isBalanceLoaded } = useBalanceContext(); const { masterWalletBalances } = useMasterBalances(); const { serviceStakedBalances, serviceWalletBalances } = useServiceBalances( @@ -36,10 +36,13 @@ export const MainOlasBalance = () => { const isBalanceBreakdownEnabled = useFeatureFlag('manage-wallet'); const displayedBalance = useMemo(() => { - // olas across master wallets, safes and eoa + // olas across master wallet -- safes and eoa -- on relevant chains for agent const masterWalletOlasBalance = masterWalletBalances?.reduce( - (acc, { symbol, balance }) => { - if (symbol === TokenSymbol.OLAS) { + (acc, { symbol, balance, evmChainId }) => { + if ( + symbol === TokenSymbol.OLAS && + selectedAgentConfig.requiresAgentSafesOn.includes(evmChainId) + ) { return acc + Number(balance); } return acc; @@ -47,10 +50,13 @@ export const MainOlasBalance = () => { 0, ); - // olas across all service wallets + // olas across all wallets owned by selected service const serviceWalletOlasBalance = serviceWalletBalances?.reduce( - (acc, { symbol, balance }) => { - if (symbol === TokenSymbol.OLAS) { + (acc, { symbol, balance, evmChainId }) => { + if ( + symbol === TokenSymbol.OLAS && + selectedAgentConfig.requiresAgentSafesOn.includes(evmChainId) + ) { return acc + Number(balance); } return acc; @@ -58,9 +64,12 @@ export const MainOlasBalance = () => { 0, ); - // olas staked across all services + // olas staked across services on relevant chains for agent const serviceStakedOlasBalance = serviceStakedBalances?.reduce( - (acc, { olasBondBalance, olasDepositBalance }) => { + (acc, { olasBondBalance, olasDepositBalance, evmChainId }) => { + if (!selectedAgentConfig.requiresAgentSafesOn.includes(evmChainId)) { + return acc; + } return acc + Number(olasBondBalance) + Number(olasDepositBalance); }, 0, @@ -73,7 +82,12 @@ export const MainOlasBalance = () => { ]); return balanceFormat(totalOlasBalance, 2); - }, [masterWalletBalances, serviceStakedBalances, serviceWalletBalances]); + }, [ + masterWalletBalances, + selectedAgentConfig.requiresAgentSafesOn, + serviceStakedBalances, + serviceWalletBalances, + ]); return ( Date: Wed, 18 Dec 2024 15:34:20 +0000 Subject: [PATCH 4/8] fix: correct the calculation for required deposit --- .../StakingContractSection/CantMigrateAlert.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx b/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx index ee81ae83..9ae75fcb 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/CantMigrateAlert.tsx @@ -63,11 +63,12 @@ const AlertInsufficientMigrationFunds = ({ if (isNil(totalStakedOlasBalanceOnHomeChain)) return null; - const requiredOlasDeposit = sum([ - masterSafeBalanceOnHomeChain[TokenSymbol.OLAS], - totalStakedOlasBalanceOnHomeChain, - -requiredStakedOlas, - ]); + const requiredOlasDeposit = + requiredStakedOlas - + sum([ + masterSafeBalanceOnHomeChain[TokenSymbol.OLAS], + totalStakedOlasBalanceOnHomeChain, + ]); const homeChainId = selectedAgentConfig.evmHomeChainId; const nativeTokenSymbol = getNativeTokenSymbol(homeChainId); From 0f2aa1babb2166a78765606175488bbd9b564b77 Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 18 Dec 2024 15:34:38 +0000 Subject: [PATCH 5/8] fix: show balances relevant to the service --- frontend/components/YourWalletPage/index.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/components/YourWalletPage/index.tsx b/frontend/components/YourWalletPage/index.tsx index 3a221f40..966f92d3 100644 --- a/frontend/components/YourWalletPage/index.tsx +++ b/frontend/components/YourWalletPage/index.tsx @@ -69,11 +69,18 @@ const Address = () => { }; const OlasBalance = () => { + const { selectedAgentConfig } = useServices(); const { totalStakedOlasBalance } = useBalanceContext(); const { masterWalletBalances } = useMasterBalances(); const masterSafeOlasBalance = masterWalletBalances - ?.filter((walletBalance) => walletBalance.symbol === TokenSymbol.OLAS) + ?.filter( + (walletBalance) => + walletBalance.symbol === TokenSymbol.OLAS && + selectedAgentConfig.requiresMasterSafesOn.includes( + walletBalance.evmChainId, + ), + ) .reduce((acc, balance) => acc + balance.balance, 0); const olasBalances = useMemo(() => { From 116ce00507124a68718eb4c9a432ed2a41c1e22e Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 18 Dec 2024 16:08:36 +0000 Subject: [PATCH 6/8] fix: remove unused evmHomeChainId from YourWalletPage component --- frontend/components/YourWalletPage/index.tsx | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/components/YourWalletPage/index.tsx b/frontend/components/YourWalletPage/index.tsx index 852cfc3f..c500bad3 100644 --- a/frontend/components/YourWalletPage/index.tsx +++ b/frontend/components/YourWalletPage/index.tsx @@ -75,7 +75,7 @@ const OlasBalance = () => { const { selectedAgentConfig } = useServices(); const { totalStakedOlasBalance } = useBalanceContext(); const { masterWalletBalances } = useMasterBalances(); - const { middlewareChain, evmHomeChainId } = useYourWallet(); + const { middlewareChain } = useYourWallet(); const masterSafeOlasBalance = masterWalletBalances ?.filter( diff --git a/package.json b/package.json index 86060bb8..5743c7e5 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "start:frontend": "cd frontend && yarn start", "test:frontend": "cd frontend && yarn test" }, - "version": "0.2.0-rc39", + "version": "0.2.0-rc43", "engine": { "node": ">=20", "yarn": ">=1.22.0", From a9483d1949972d77a5d999d0c3531d7adf8592d4 Mon Sep 17 00:00:00 2001 From: truemiller Date: Wed, 18 Dec 2024 17:34:57 +0000 Subject: [PATCH 7/8] fix: refactor MigrateButton to simplify service template retrieval and adjust deployment logic --- .../StakingContractSection/MigrateButton.tsx | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx b/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx index 65e50a9c..0a2f3907 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx @@ -3,16 +3,14 @@ import { isNil } from 'lodash'; import { useMemo } from 'react'; import { MiddlewareDeploymentStatus, ServiceTemplate } from '@/client'; -import { - getServiceTemplate, - SERVICE_TEMPLATES, -} from '@/constants/serviceTemplates'; +import { MechType } from '@/config/mechs'; +import { STAKING_PROGRAMS } from '@/config/stakingPrograms'; +import { SERVICE_TEMPLATES } from '@/constants/serviceTemplates'; import { Pages } from '@/enums/Pages'; import { StakingProgramId } from '@/enums/StakingProgram'; import { useBalanceContext } from '@/hooks/useBalanceContext'; import { useModals } from '@/hooks/useModals'; import { usePageState } from '@/hooks/usePageState'; -import { useService } from '@/hooks/useService'; import { useServices } from '@/hooks/useServices'; import { useActiveStakingContractDetails, @@ -36,21 +34,19 @@ export const MigrateButton = ({ isFetched: isServicesLoaded, selectedService, selectedAgentType, + selectedAgentConfig, overrideSelectedServiceStatus, } = useServices(); const serviceConfigId = isServicesLoaded && selectedService ? selectedService.service_config_id : ''; - const { service } = useService(serviceConfigId); const serviceTemplate = useMemo( () => - service - ? getServiceTemplate(service.hash) - : SERVICE_TEMPLATES.find( - (template) => template.agentType === selectedAgentType, - ), - [selectedAgentType, service], + SERVICE_TEMPLATES.find( + (template) => template.agentType === selectedAgentType, + ), + [selectedAgentType], ); const { setIsPaused: setIsBalancePollingPaused } = useBalanceContext(); @@ -131,10 +127,11 @@ export const MigrateButton = ({ const serviceConfigParams = { stakingProgramId: stakingProgramIdToMigrateTo, serviceTemplate, - deploy: true, + deploy: false, useMechMarketplace: - stakingProgramIdToMigrateTo === - StakingProgramId.PearlBetaMechMarketplace, + STAKING_PROGRAMS[selectedAgentConfig.evmHomeChainId][ + stakingProgramIdToMigrateTo + ].mechType === MechType.Marketplace, }; if (selectedService) { From 97a91ac7a705fa6e33f0357b4d03975a4b053b25 Mon Sep 17 00:00:00 2001 From: truemiller Date: Tue, 24 Dec 2024 13:16:06 +0000 Subject: [PATCH 8/8] fix: linter --- .../ManageStakingPage/StakingContractSection/MigrateButton.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx b/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx index 84f29334..9faf08cb 100644 --- a/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx +++ b/frontend/components/ManageStakingPage/StakingContractSection/MigrateButton.tsx @@ -3,8 +3,6 @@ import { isNil } from 'lodash'; import { useMemo } from 'react'; import { MiddlewareDeploymentStatus, ServiceTemplate } from '@/client'; -import { MechType } from '@/config/mechs'; -import { STAKING_PROGRAMS } from '@/config/stakingPrograms'; import { SERVICE_TEMPLATES } from '@/constants/serviceTemplates'; import { Pages } from '@/enums/Pages'; import { StakingProgramId } from '@/enums/StakingProgram'; @@ -35,7 +33,6 @@ export const MigrateButton = ({ isFetched: isServicesLoaded, selectedService, selectedAgentType, - selectedAgentConfig, overrideSelectedServiceStatus, } = useServices(); const serviceConfigId =