Skip to content

Commit

Permalink
Merge pull request #80 from ar-io/develop
Browse files Browse the repository at this point in the history
Release to Production
  • Loading branch information
kunstmusik authored Oct 1, 2024
2 parents 85e5880 + 68a1fa9 commit dfc755e
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 95 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Header = () => {
{gatewaysLoading ? (
<Placeholder className='h-[1.0625rem]'/>
) : gateways ? (
Object.keys(gateways).length
Object.values(gateways).filter((g) => g.status === "joined").length
) : (
NBSP
)}
Expand Down
19 changes: 12 additions & 7 deletions src/hooks/useRewardsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,7 +32,7 @@ const useRewardsInfo = (
const userRewards = calculateUserRewards(
gatewayRewards,
new IOToken(Math.abs(userStake)),
userStake < 0
userStake < 0,
);
res = userRewards;
}
Expand Down
52 changes: 36 additions & 16 deletions src/pages/Gateway/PropertyDisplayPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<div className="border-t border-grey-900">
<div className=" bg-grey-1000 px-6 py-3 text-xs text-low">
{label}
</div>
<div className=" bg-grey-1000 px-6 py-3 text-xs text-low">{label}</div>
</div>
<div className="flex flex-col content-center justify-center border-t border-grey-900 pl-6 text-sm text-low">
{value === undefined ? (
Expand Down Expand Up @@ -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(),
},
]
: [];
Expand All @@ -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' ? (
<div className="text-[#f00]">leaving</div>
) : (
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 ? (
<Button
className="mr-2"
Expand Down
59 changes: 31 additions & 28 deletions src/pages/Gateway/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ const Gateway = () => {
: undefined;

const operatorRewards =
gateway?.operatorStake && protocolBalance && gateways
gateway?.operatorStake != undefined && protocolBalance && gateways
? calculateOperatorRewards(
new mIOToken(protocolBalance).toIO(),
Object.keys(gateways).length,
Object.values(gateways).filter((g) => g.status == 'joined').length,
gateway,
)
: undefined;
Expand Down Expand Up @@ -446,34 +446,37 @@ const Gateway = () => {
: undefined
}
/>
<StatsBox
title={
<div className="flex gap-2">
Operator EAY{' '}
<Tooltip
message={
<div>
<p>{EAY_TOOLTIP_TEXT}</p>
<MathJax className="mt-4">
{OPERATOR_EAY_TOOLTIP_FORMULA}
</MathJax>
</div>
}
>
<InfoIcon className="size-4" />
</Tooltip>
</div>
}
value={
operatorRewards
? `${(operatorRewards.EAY * 100).toFixed(2)}%`
: undefined
}
/>

{gateway?.status === 'joined' && (
<StatsBox
title={
<div className="flex gap-2">
Operator EAY{' '}
<Tooltip
message={
<div>
<p>{EAY_TOOLTIP_TEXT}</p>
<MathJax className="mt-4">
{OPERATOR_EAY_TOOLTIP_FORMULA}
</MathJax>
</div>
}
>
<InfoIcon className="size-4" />
</Tooltip>
</div>
}
value={
operatorRewards != undefined
? `${(operatorRewards.EAY * 100).toFixed(2)}%`
: undefined
}
/>
)}
{/* <StatsBox title="Rewards Distributed" value={gateway?} /> */}
</div>

{gateway?.weights && (
{gateway?.weights && gateway?.status === 'joined' && (
<div className="w-full rounded-xl border border-transparent-100-16 text-sm">
<div className="px-6 py-4">
<div className="text-high">Weights</div>
Expand All @@ -486,7 +489,7 @@ const Gateway = () => {
>
<div className="grow text-xs text-low">{title}:</div>
<div className="text-right text-sm">
{value ? value.toFixed(3) : <Placeholder />}
{value !== undefined ? value.toFixed(3) : <Placeholder />}
</div>
</div>
))}
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Gateways/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'
Expand Down
90 changes: 47 additions & 43 deletions src/pages/Staking/DelegateStakeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,53 +60,57 @@ const DelegateStake = () => {
const stakeableGateways: Array<TableData> =
!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<TableData>);
eay: calculateGatewayRewards(
new mIOToken(protocolBalance).toIO(),
Object.values(gateways).filter(g => g.status == "joined").length,
gateway,
).EAY,
},
];
}
return acc;
}, [] as Array<TableData>);
setStakeableGateways(stakeableGateways);
}, [gateways, protocolBalance, walletAddress]);

Expand Down

0 comments on commit dfc755e

Please sign in to comment.