103 lines
4.9 KiB
JavaScript
103 lines
4.9 KiB
JavaScript
import { defineStore } from "pinia";
|
|
import { useMemeburnerStore } from "./memeburner";
|
|
import { useTokenStore } from "./tokens";
|
|
import { useRewardLockerStore } from "./rewardlocker";
|
|
|
|
|
|
export const useRoundsStore = defineStore("rounds", {
|
|
state: () => ({
|
|
rounds: [
|
|
],
|
|
activeRound: null,
|
|
currentRound: null
|
|
}),
|
|
getters: {
|
|
getCurrentRoundData() {
|
|
return this.rounds[this.activeRound];
|
|
}
|
|
},
|
|
actions: {
|
|
async init() {
|
|
//fill initial round
|
|
},
|
|
async updateCurrentRound(sacrificedToken, sacrificedAmount) {
|
|
const tokenStore = useTokenStore();
|
|
const memeBurnerStore = useMemeburnerStore();
|
|
var data = await memeBurnerStore.getSacrificedRound(this.currentRound)
|
|
console.log("data123", data);
|
|
var tokenIndex = this.rounds[this.currentRound].token.findIndex((tokenData) => tokenData.contractAddress === sacrificedToken);
|
|
this.rounds[this.currentRound].token[tokenIndex].amount = data[tokenIndex][1];
|
|
|
|
},
|
|
async fillRound() {
|
|
console.log("fillRound");
|
|
const memeBurnerStore = useMemeburnerStore();
|
|
const tokenStore = useTokenStore();
|
|
const rewardLockerStore = useRewardLockerStore();
|
|
|
|
// if (this.activeRound === this.currentRound) {
|
|
// console.log("activeRound is not completed");
|
|
// } else
|
|
if (!this.rounds[this.activeRound]) {
|
|
console.log("round not filled --> fill round");
|
|
console.log("vor error");
|
|
var data = await memeBurnerStore.getSacrificedRound(this.activeRound)
|
|
var rewardData = await rewardLockerStore.getRewardsForAllToken(this.activeRound);
|
|
var goal = await memeBurnerStore.getGoal(this.activeRound);
|
|
console.log("goal", goal);
|
|
console.log("this.activeRound", this.activeRound);
|
|
console.log("dataabc", data);
|
|
console.log("rewardData", rewardData);
|
|
console.log("pepecoin-rewards", rewardData[0]);
|
|
|
|
var tokenArray = []
|
|
var rewards_clan = BigInt(0);
|
|
var rewards_sacrifice = BigInt(0);
|
|
for (let index = 0; index < data.length; index++) {
|
|
var tokenData = {};
|
|
const token = tokenStore.token[index];
|
|
console.log("testabcv", token);
|
|
console.log("123abc", token.contractAddress);
|
|
var testcoef = await rewardLockerStore.getSacrificedTokenCoefficient(this.activeRound, token.contractAddress);
|
|
console.log("testcoef",);
|
|
console.log(`rewards ${token.name}`, BigInt(rewardData[index]));
|
|
console.log(`clanwin multiplier ${token.name}`, (testcoef / 10000));
|
|
const clanwin = BigInt((testcoef / 10000 -1) * rewardData[index]);
|
|
console.log(`clanwin ${token.name}`, clanwin);
|
|
const sacrificeRewards = BigInt(rewardData[index]) - clanwin;
|
|
console.log(`sacrifice rewards`, sacrificeRewards);
|
|
console.log("token", token);
|
|
tokenData.name = token.name;
|
|
tokenData.contractAddress = token.contractAddress;
|
|
tokenData.vamplogo = token.vamp.logo;
|
|
tokenData.vampname = token.vamp.name;
|
|
tokenData.amount = data[index][1];
|
|
tokenData.getAmountToReachGoal= await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
|
|
tokenData.rewards_ges = rewardData[index];
|
|
if (this.currentRound !== this.activeRound) {
|
|
tokenData.rewards_clan = clanwin;
|
|
console.log("clanwin", clanwin);
|
|
tokenData.rewards_sacrifice = sacrificeRewards;
|
|
rewards_clan = rewards_clan + BigInt(clanwin / BigInt(Math.pow(10, token.decimals)));
|
|
rewards_sacrifice =
|
|
rewards_sacrifice + BigInt(sacrificeRewards / BigInt(Math.pow(10, token.decimals)));;
|
|
}
|
|
tokenArray.push(tokenData);
|
|
}
|
|
|
|
console.log("Math.pow(10, tokenStore.memeToken.decimals)", Math.pow(10, tokenStore.memeToken.decimals));
|
|
console.log("goal", goal);
|
|
this.rounds[this.activeRound] = {
|
|
goal: goal,
|
|
rewards_clan: rewards_clan,
|
|
rewards_sacrifice: rewards_sacrifice,
|
|
token: tokenArray,
|
|
};
|
|
} else {
|
|
console.log("round already filled");
|
|
}
|
|
console.log("this.rounds123", this.rounds);
|
|
},
|
|
},
|
|
});
|