Skip to content

Commit

Permalink
fix: historical brib efficiency calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xeonus committed Oct 1, 2024
1 parent 5110277 commit b76499d
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 14 deletions.
17 changes: 12 additions & 5 deletions src/data/VotingIncentives/useGetEmissionPerVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useCoinGeckoSimpleTokenPrices} from "../coingecko/useCoinGeckoSimpleToke
import {useAuraGlobalStats} from "../aura/useAuraGlobalStats";
import balancerTokenAdminAbi from '../../constants/abis/balancerTokenAdmin.json';
import erc20Abi from '../../constants/abis/erc20.json';
import {AURA_TIMESTAMPS} from "../hidden-hand/constants";
import {AURA_TIMESTAMPS, HISTORICAL_AURA_PRICE, HISTORICAL_ROUND_BAL_PRICE} from "../hidden-hand/constants";
import {useGetHiddenHandVotingIncentives} from "../hidden-hand/useGetHiddenHandVotingIncentives";
import {ethers} from "ethers";
import {AURA_TOKEN_MAINNET, BALANCER_TOKEN_MAINNET} from "../aura/auraConstants";
Expand Down Expand Up @@ -77,11 +77,16 @@ export const useGetEmissionPerVote = (timestampCurrentRound: number) => {
}

// Find price from historical set
const auraTsPrice = historicalAuraCoinData?.find(el => el.time === unixToDate(timestampCurrentRound) ? el.value : 0)
const balTsPrice = historicalBALCoinData?.find(el => el.time === unixToDate(timestampCurrentRound) ? el.value : 0)
const auraTsPrice = historicalAuraCoinData?.find(el => el.time === unixToDate(timestampCurrentRound))?.value
?? HISTORICAL_AURA_PRICE.find(e => e.time === unixToDate(timestampCurrentRound, 'YYYY-MM-DD'))?.value
?? 0;

const auraPrice = auraTsPrice ? auraTsPrice.value : coinData.data[auraAddress].price
const balPrice = balTsPrice ? balTsPrice.value : coinData.data[balAddress].price
const balTsPrice = historicalBALCoinData?.find(el => el.time === unixToDate(timestampCurrentRound))?.value
?? HISTORICAL_ROUND_BAL_PRICE.find(e => e.time === unixToDate(timestampCurrentRound, 'YYYY-MM-DD'))?.value
?? 0;

const auraPrice = auraTsPrice ? auraTsPrice : coinData.data[auraAddress].price
const balPrice = balTsPrice ? balTsPrice : coinData.data[balAddress].price
console.log("Aura price: ", auraPrice, "- BAL price: ", balPrice);


Expand All @@ -98,6 +103,8 @@ export const useGetEmissionPerVote = (timestampCurrentRound: number) => {
let biweeklyBalEmissionFormatted = 145000 * 2
if (timestampCurrentRound < 1711975297 && timestampCurrentRound > 1680180097) {
biweeklyBalEmissionFormatted = 121929.98 * 2
} else if (timestampCurrentRound < 1680180097){
biweeklyBalEmissionFormatted = 145000 * 2
} else {
biweeklyBalEmissionFormatted = parseFloat(ethers.utils.formatEther(biweeklyBalEmission))
}
Expand Down
163 changes: 163 additions & 0 deletions src/data/hidden-hand/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2525,3 +2525,166 @@ export const HISTORICAL_AURA_PRICE = [
"time": "2024-06-24"
}
]

export const HISTORICAL_ROUND_BAL_PRICE = [
{
"value": 5.55,
"time": "2022-06-28"
},
{
"value": 4.91,
"time": "2022-07-12"
},
{
"value": 4.49,
"time": "2022-07-26"
},
{
"value": 6.27,
"time": "2022-08-09"
},
{
"value": 6.56,
"time": "2022-08-23"
},
{
"value": 7.17,
"time": "2022-09-06"
},
{
"value": 5.72,
"time": "2022-09-19"
},
{
"value": 5.04,
"time": "2022-10-03"
},
{
"value": 5.15,
"time": "2022-10-17"
},
{
"value": 6.91,
"time": "2022-10-31"
},
{
"value": 5.33,
"time": "2022-11-14"
},
{
"value": 5.96,
"time": "2022-11-28"
},
{
"value": 5.95,
"time": "2022-12-12"
},
{
"value": 5.61,
"time": "2022-12-26"
},
{
"value": 5.55,
"time": "2023-01-09"
},
{
"value": 6.84,
"time": "2023-01-23"
},
{
"value": 7.08,
"time": "2023-02-06"
},
{
"value": 6.56,
"time": "2023-02-20"
},
{
"value": 6.35,
"time": "2023-03-06"
},
{
"value": 6.56,
"time": "2023-03-20"
},
{
"value": 6.98,
"time": "2023-04-03"
},
{
"value": 7.22,
"time": "2023-04-17"
},
{
"value": 6.12,
"time": "2023-05-01"
},
{
"value": 5.5,
"time": "2023-05-15"
},
{
"value": 5.37,
"time": "2023-05-29"
},
{
"value": 4.46,
"time": "2023-06-12"
},
{
"value": 4.67,
"time": "2023-06-26"
},
{
"value": 4.57,
"time": "2023-07-10"
},
{
"value": 4.58,
"time": "2023-07-24"
},
{
"value": 4.23,
"time": "2023-08-07"
},
{
"value": 3.70,
"time": "2023-08-21"
},
{
"value": 3.34,
"time": "2023-09-04"
},
{
"value": 3.31,
"time": "2023-09-18"
},
{
"value": 3.32,
"time": "2023-10-02"
},
{
"value": 3.06,
"time": "2023-10-16"
},
{
"value": 3.44,
"time": "2023-10-30"
},
{
"value": 3.97,
"time": "2023-11-13"
},
{
"value": 3.81,
"time": "2023-11-27"
},
{
"value": 4.36,
"time": "2023-12-11"
},
{
"value": 4.27,
"time": "2023-12-25"
}
]
29 changes: 20 additions & 9 deletions src/pages/VotingIncentives/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function VotingIncentives() {
const { data: historicalPrices, loading: pricesLoading, error: pricesError } = useGetTokenSetHistoricalPrices(tokenAddresses, GqlChain.Mainnet);
const [correctedIncentives, setCorrectedIncentives] = useState<HiddenHandIncentives | null>(null);

console.log("auraHistoricalprice: ", auraHistoricalPrice)
//console.log("auraHistoricalprice: ", auraHistoricalPrice)

const {emissionValuePerVote, emissionsPerDollarSpent} = useGetEmissionPerVote(currentRoundNew);

Expand Down Expand Up @@ -133,12 +133,23 @@ export default function VotingIncentives() {
? curr : prev;
});

const correctedValue = bribe.amount * closestPrice.price;
// Check if the closest price is within 3 days of the proposal deadline
const timeDifference = Math.abs(new Date(closestPrice.date).getTime() - proposal.proposalDeadline * 1000);
const threeDaysInMilliseconds = 3 * 24 * 60 * 60 * 1000;

return {
...bribe,
value: correctedValue,
};
if (timeDifference <= threeDaysInMilliseconds) {
const correctedValue = bribe.amount * closestPrice.price;
return {
...bribe,
value: correctedValue,
};
} else {
// If no price within 3 days, use the original amount
return {
...bribe,
value: bribe.value,
};
}
}),
}));

Expand Down Expand Up @@ -223,8 +234,8 @@ export default function VotingIncentives() {
}
});

console.log("xAxisData", xAxisData)
console.log("priceData", priceData)
//console.log("xAxisData", xAxisData)
//console.log("priceData", priceData)
let historicalPrice = xAxisData.map((el) => {
const price = priceData.find(price => el === price.time);
const fallbackPrice = auraHistoricalPrice ? auraHistoricalPrice.find(price => el === price.time) : 0
Expand All @@ -237,7 +248,7 @@ export default function VotingIncentives() {
return 0; // Fallback value
}
});
console.log("historical aura price:", historicalPrice)
//console.log("historical aura price:", historicalPrice)

return (<>
{(!roundsData?.rounds
Expand Down

0 comments on commit b76499d

Please sign in to comment.