Skip to content
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

Release to production #69

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/modals/StakingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ const StakingModal = ({
tab == 0
? currentStake + parseFloat(amountToStake)
: currentStake - parseFloat(amountToUnstake);
const rewardsInfo = useRewardsInfo(gateway, newTotalStake);
const newStake = tab == 0 ? parseFloat(amountToStake) : -parseFloat(amountToUnstake);
const rewardsInfo = useRewardsInfo(gateway, newStake);
const EAY =
rewardsInfo && newTotalStake > 0
? (rewardsInfo.EAY * 100).toLocaleString('en-us', {
Expand Down Expand Up @@ -356,7 +357,7 @@ const StakingModal = ({

<DisplayRow
className="py-1"
label="EAY:"
label="Delegate EAY:"
value={EAY}
rightIcon={
<Tooltip
Expand Down
17 changes: 8 additions & 9 deletions src/hooks/useRewardsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@ 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 &&
userStake > 0
) {
if (gateways && gateway && protocolBalance && protocolBalance > 0 && !isNaN(userStake)) {
const numGateways = gateways ? Object.keys(gateways).length : 0;
const gatewayRewards = calculateGatewayRewards(
new mIOToken(protocolBalance).toIO(),
numGateways,
gateway,
);

const userRewards = calculateUserRewards(
gatewayRewards,
new IOToken(userStake),
new IOToken(Math.abs(userStake)),
userStake < 0
);
res = userRewards;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Staking/DelegateStakeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const DelegateStake = () => {
id: 'eay',
header: () => (
<div className="flex gap-1">
EAY
Delegate EAY
<Tooltip
message={
<div>
Expand All @@ -215,7 +215,7 @@ const DelegateStake = () => {
<div>
{row.original.eay < 0
? 'N/A'
: `${formatWithCommas(row.original.eay)}%`}
: `${formatWithCommas(row.original.eay * 100)}%`}
</div>
),
}),
Expand Down
9 changes: 6 additions & 3 deletions src/utils/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AoGateway, IOToken, mIOToken } from '@ar.io/sdk/web';

const EPOCHS_PER_YEAR = 365;
const EPOCH_DISTRIBUTION_RATIO = 0.0025; // 0.25%
const GATEWAY_REWARDS_RATIO = 0.95; // 95%
const EPOCH_DISTRIBUTION_RATIO = 0.0005; // 0.05%
const GATEWAY_REWARDS_RATIO = 0.9; // 90%
// const OBSERVER_REWARDS_RATIO = .05; // 5%

export interface GatewayRewards {
Expand Down Expand Up @@ -53,8 +53,11 @@ export const calculateGatewayRewards = (
export const calculateUserRewards = (
gatewayRewards: GatewayRewards,
userDelegatedStake: IOToken,
removingStake = false
): UserRewards => {
const delegatedStake = userDelegatedStake.valueOf();
const multiplier = removingStake ? -1 : 1;
const delegatedStake = userDelegatedStake.valueOf() * multiplier;

const stakeProportion =
delegatedStake /
(gatewayRewards.totalDelegatedStake.valueOf() + delegatedStake);
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/rewards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('rewards.ts', () => {
expect(result.totalDelegatedStake.valueOf()).toEqual(
new IOToken(50000).valueOf(),
);
expect(result.rewardsSharedPerEpoch.valueOf()).toBeCloseTo(197.91, 1);
expect(result.rewardsSharedPerEpoch.valueOf()).toBeCloseTo(37.5, 1);
expect(result.EEY).toBeCloseTo(0.004);
expect(result.EAY).toBeCloseTo(1.4447916691);
expect(result.EAY).toBeCloseTo(0.27375);
});
});

Expand Down
Loading