-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix balance related blockers for migration #612
Changes from all commits
a16a96a
8d6cd21
592ebb5
f720fb6
0f2aa1b
0361cb1
116ce00
a9483d1
0fc7f06
97a91ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,31 +36,40 @@ 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; | ||
}, | ||
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) | ||
) { | ||
Comment on lines
+53
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensuring we don't calculate funds not on chains irrelevant to the agent |
||
return acc + Number(balance); | ||
} | ||
return acc; | ||
}, | ||
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 ( | ||
<CardSection | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,24 +59,26 @@ 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 = | ||
requiredStakedOlas - | ||
sum([ | ||
masterSafeBalanceOnHomeChain[TokenSymbol.OLAS], | ||
totalStakedOlasBalanceOnHomeChain, | ||
]); | ||
Comment on lines
+66
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed this condition, may be breaking due to suspension or eviction |
||
|
||
const homeChainId = selectedAgentConfig.evmHomeChainId; | ||
const nativeTokenSymbol = getNativeTokenSymbol(homeChainId); | ||
const requiredNativeTokenDeposit = isInitialFunded | ||
? 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 ( | ||
<CustomAlert | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine to aggregate olas across potential chains for display balance