From 47dce9e27ad0f08559539e4daa89803fc5b87f69 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Fri, 27 Sep 2024 11:07:54 -0400 Subject: [PATCH 1/5] feat: filter out leaving gateways for total count in header --- src/components/Header.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 142f564..c3d94d7 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -34,7 +34,7 @@ const Header = () => { {gatewaysLoading ? ( ) : gateways ? ( - Object.keys(gateways).length + Object.values(gateways).filter((g) => g.status === "joined").length ) : ( NBSP )} From fa4c214f48e0220041bd7931c66e7df93c6c323b Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Fri, 27 Sep 2024 11:15:25 -0400 Subject: [PATCH 2/5] feat: show "N/A" for streak column for gateways that are leaving --- src/pages/Gateways/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pages/Gateways/index.tsx b/src/pages/Gateways/index.tsx index 127cdf1..a0e8dc2 100644 --- a/src/pages/Gateways/index.tsx +++ b/src/pages/Gateways/index.tsx @@ -69,6 +69,8 @@ const Gateways = () => { passedEpochCount, totalEpochCount, streak: + gateway.status == "leaving" ? + Number.NEGATIVE_INFINITY : gateway.stats.failedConsecutiveEpochs > 0 ? -gateway.stats.failedConsecutiveEpochs : gateway.stats.passedConsecutiveEpochs, @@ -180,6 +182,10 @@ const Gateways = () => { return ''; } + if (streak === Number.NEGATIVE_INFINITY) { + return 'N/A'; + } + const colorClasses = streak > 0 ? 'border-streak-up/[.56] bg-streak-up/[.1] text-streak-up' From 99125b28044f80d54a2ad7a7b029cf27156ac660 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Fri, 27 Sep 2024 11:25:02 -0400 Subject: [PATCH 3/5] feat: filter out leaving gateways from staking table --- src/pages/Staking/DelegateStakeTable.tsx | 90 +++++++++++++----------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/pages/Staking/DelegateStakeTable.tsx b/src/pages/Staking/DelegateStakeTable.tsx index 34f6e90..e20eeb4 100644 --- a/src/pages/Staking/DelegateStakeTable.tsx +++ b/src/pages/Staking/DelegateStakeTable.tsx @@ -60,53 +60,57 @@ const DelegateStake = () => { const stakeableGateways: Array = !gateways || !protocolBalance ? [] - : Object.entries(gateways).reduce((acc, [owner, gateway]) => { - if (gateway.settings.allowDelegatedStaking) { - const passedEpochCount = gateway.stats.passedEpochCount; - const totalEpochCount = (gateway.stats as any).totalEpochCount; + : Object.entries(gateways) + .filter((g) => g[1].status === 'joined') + .reduce((acc, [owner, gateway]) => { + if (gateway.settings.allowDelegatedStaking) { + const passedEpochCount = gateway.stats.passedEpochCount; + const totalEpochCount = (gateway.stats as any).totalEpochCount; - return [ - ...acc, - { - label: gateway.settings.label, - domain: gateway.settings.fqdn, - owner, - streak: - gateway.stats.failedConsecutiveEpochs > 0 - ? -gateway.stats.failedConsecutiveEpochs - : gateway.stats.passedConsecutiveEpochs, + return [ + ...acc, + { + label: gateway.settings.label, + domain: gateway.settings.fqdn, + owner, + streak: + gateway.stats.failedConsecutiveEpochs > 0 + ? -gateway.stats.failedConsecutiveEpochs + : gateway.stats.passedConsecutiveEpochs, - rewardShareRatio: gateway.settings.allowDelegatedStaking - ? gateway.settings.delegateRewardShareRatio - : -1, - performance: - totalEpochCount > 0 - ? gateway.stats.passedEpochCount / totalEpochCount + rewardShareRatio: gateway.settings.allowDelegatedStaking + ? gateway.settings.delegateRewardShareRatio : -1, - passedEpochCount, - totalEpochCount, - totalDelegatedStake: new mIOToken(gateway.totalDelegatedStake) - .toIO() - .valueOf(), - operatorStake: new mIOToken(gateway.operatorStake) - .toIO() - .valueOf(), - totalStake: new mIOToken( - gateway.totalDelegatedStake + gateway.operatorStake, - ) - .toIO() - .valueOf(), + performance: + totalEpochCount > 0 + ? gateway.stats.passedEpochCount / totalEpochCount + : -1, + passedEpochCount, + totalEpochCount, + totalDelegatedStake: new mIOToken( + gateway.totalDelegatedStake, + ) + .toIO() + .valueOf(), + operatorStake: new mIOToken(gateway.operatorStake) + .toIO() + .valueOf(), + totalStake: new mIOToken( + gateway.totalDelegatedStake + gateway.operatorStake, + ) + .toIO() + .valueOf(), - eay: calculateGatewayRewards( - new mIOToken(protocolBalance).toIO(), - Object.keys(gateways).length, - gateway, - ).EAY, - }, - ]; - } - return acc; - }, [] as Array); + eay: calculateGatewayRewards( + new mIOToken(protocolBalance).toIO(), + Object.keys(gateways).length, + gateway, + ).EAY, + }, + ]; + } + return acc; + }, [] as Array); setStakeableGateways(stakeableGateways); }, [gateways, protocolBalance, walletAddress]); From 737a442da1ad7fc5b0b1e12d63e2ff6caf844cf4 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Fri, 27 Sep 2024 14:54:14 -0400 Subject: [PATCH 4/5] feat: disable weights and use N/A for values when viewing a gateway that is leaving; additional fixes for rewards calculations using only joined gateways --- src/hooks/useRewardsInfo.ts | 19 ++++--- src/pages/Gateway/PropertyDisplayPanel.tsx | 52 +++++++++++++------ src/pages/Gateway/index.tsx | 59 ++++++++++++---------- src/pages/Staking/DelegateStakeTable.tsx | 2 +- 4 files changed, 80 insertions(+), 52 deletions(-) diff --git a/src/hooks/useRewardsInfo.ts b/src/hooks/useRewardsInfo.ts index ff5528f..3bdefdb 100644 --- a/src/hooks/useRewardsInfo.ts +++ b/src/hooks/useRewardsInfo.ts @@ -7,17 +7,22 @@ import { import useGateways from './useGateways'; import useProtocolBalance from './useProtocolBalance'; -const useRewardsInfo = ( - gateway: AoGateway | undefined, - userStake: number -) => { +const useRewardsInfo = (gateway: AoGateway | undefined, userStake: number) => { const { data: gateways } = useGateways(); const { data: protocolBalance } = useProtocolBalance(); let res: UserRewards | undefined = undefined; - if (gateways && gateway && protocolBalance && protocolBalance > 0 && !isNaN(userStake)) { - const numGateways = gateways ? Object.keys(gateways).length : 0; + if ( + gateways && + gateway && + protocolBalance && + protocolBalance > 0 && + !isNaN(userStake) + ) { + const numGateways = gateways + ? Object.values(gateways).filter((g) => g.status == 'joined').length + : 0; const gatewayRewards = calculateGatewayRewards( new mIOToken(protocolBalance).toIO(), numGateways, @@ -27,7 +32,7 @@ const useRewardsInfo = ( const userRewards = calculateUserRewards( gatewayRewards, new IOToken(Math.abs(userStake)), - userStake < 0 + userStake < 0, ); res = userRewards; } diff --git a/src/pages/Gateway/PropertyDisplayPanel.tsx b/src/pages/Gateway/PropertyDisplayPanel.tsx index b51b565..db973a1 100644 --- a/src/pages/Gateway/PropertyDisplayPanel.tsx +++ b/src/pages/Gateway/PropertyDisplayPanel.tsx @@ -13,16 +13,14 @@ const DisplayRow = ({ rightComponent, }: { label: string; - value: string | number | boolean | undefined; + value: React.ReactNode | string | number | boolean | undefined; type?: string; rightComponent?: React.ReactNode; }) => { return ( <>
-
- {label} -
+
{label}
{value === undefined ? ( @@ -79,17 +77,23 @@ const PropertyDisplayPanel = ({ ? `${gateway.settings.protocol}://${gateway.settings.fqdn}:${gateway.settings.port}` : undefined; + const gatewayLeaving = gateway?.status == 'leaving'; + const conditionalRows = gateway?.settings.allowDelegatedStaking ? [ { label: 'Reward Share Ratio:', - value: `${gateway?.settings.delegateRewardShareRatio}%`, + value: gatewayLeaving + ? 'N/A' + : `${gateway?.settings.delegateRewardShareRatio}%`, }, { label: `Minimum Delegated Stake (${ticker}):`, - value: new mIOToken(gateway?.settings.minDelegatedStake || 0) - .toIO() - .valueOf(), + value: gatewayLeaving + ? 'N/A' + : new mIOToken(gateway?.settings.minDelegatedStake || 0) + .toIO() + .valueOf(), }, ] : []; @@ -109,21 +113,37 @@ const PropertyDisplayPanel = ({ type: 'tx', }, { - label: `Gateway Stake (${ticker}):`, - value: gateway?.operatorStake - ? new mIOToken(gateway?.operatorStake).toIO().valueOf() - : undefined, + label: `Gateway Stake abc (${ticker}):`, + value: + gateway?.operatorStake != undefined + ? new mIOToken(gateway?.operatorStake).toIO().valueOf() + : undefined, + }, + { + label: 'Status:', + value: + gateway?.status == 'leaving' ? ( +
leaving
+ ) : ( + gateway?.status + ), }, - { label: 'Status:', value: gateway?.status }, { label: 'Note:', value: gateway?.settings.note }, { label: `Total Delegated Stake (${ticker}):`, - value: new mIOToken(gateway?.totalDelegatedStake || 0).toIO().valueOf(), + value: gatewayLeaving + ? 'N/A' + : gateway?.totalDelegatedStake == undefined + ? undefined + : new mIOToken(gateway.totalDelegatedStake).toIO().valueOf(), + }, + { + label: 'Reward Auto Stake:', + value: gatewayLeaving ? 'N/A' : gateway?.settings.autoStake, }, - { label: 'Reward Auto Stake:', value: gateway?.settings.autoStake }, { label: 'Delegated Staking:', - value: gateway?.settings.allowDelegatedStaking, + value: gatewayLeaving ? 'N/A' : gateway?.settings.allowDelegatedStaking, rightComponent: gateway?.settings.allowDelegatedStaking ? (
- } - > - - - - } - value={ - operatorRewards - ? `${(operatorRewards.EAY * 100).toFixed(2)}%` - : undefined - } - /> + + {gateway?.status === 'joined' && ( + + Operator EAY{' '} + +

{EAY_TOOLTIP_TEXT}

+ + {OPERATOR_EAY_TOOLTIP_FORMULA} + + + } + > + +
+ + } + value={ + operatorRewards != undefined + ? `${(operatorRewards.EAY * 100).toFixed(2)}%` + : undefined + } + /> + )} {/* */} - {gateway?.weights && ( + {gateway?.weights && gateway?.status === 'joined' && (
Weights
@@ -486,7 +489,7 @@ const Gateway = () => { >
{title}:
- {value ? value.toFixed(3) : } + {value !== undefined ? value.toFixed(3) : }
))} diff --git a/src/pages/Staking/DelegateStakeTable.tsx b/src/pages/Staking/DelegateStakeTable.tsx index e20eeb4..edf9b73 100644 --- a/src/pages/Staking/DelegateStakeTable.tsx +++ b/src/pages/Staking/DelegateStakeTable.tsx @@ -103,7 +103,7 @@ const DelegateStake = () => { eay: calculateGatewayRewards( new mIOToken(protocolBalance).toIO(), - Object.keys(gateways).length, + Object.values(gateways).filter(g => g.status == "joined").length, gateway, ).EAY, }, From 875c3560652ff9dabdc87ce39077e09094a42adc Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Mon, 30 Sep 2024 11:03:56 -0400 Subject: [PATCH 5/5] chore: set staging build to use testnet --- .github/workflows/build_and_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 938370e..668ede1 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -49,6 +49,7 @@ jobs: VITE_SENTRY_DSN_PROJECT_URI: ${{ secrets.SENTRY_DSN_PROJECT_URI }} VITE_SENTRY_DSN_PROJECT_ID: ${{ secrets.SENTRY_DSN_PROJECT_ID }} VITE_GITHUB_HASH: ${{ github.sha }} + VITE_IO_PROCESS_ID: ${{ secrets.IO_PROCESS_ID }} # ao infra settings VITE_AO_CU_URL: ${{ vars.VITE_AO_CU_URL }} - name: Add CNAME Record