Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2f8b90cdd | ||
|
|
a719ee5989 | ||
|
|
5e6f373293 | ||
|
|
0b9e14c628 |
@@ -29,6 +29,15 @@ export function formatNumber(number) {
|
||||
return formattedWithOptions;
|
||||
}
|
||||
|
||||
// input type bigint
|
||||
export function formatBigIntDivision(nominator, denominator) {
|
||||
const integer = (nominator / denominator).toString();
|
||||
// pick how much digits after point to show
|
||||
const fraction = (nominator % denominator).toString().substring(0,10);
|
||||
// output type string
|
||||
return integer + '.' + fraction;
|
||||
}
|
||||
|
||||
export function getAddressShortName(address) {
|
||||
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
||||
const addressBegin = address.substring(0, 6);
|
||||
|
||||
@@ -91,7 +91,10 @@ export const useCycleStore = defineStore("cycles", {
|
||||
async updateCurrentCycle(sacrificedToken) {
|
||||
console.log("updateCurrentCycle");
|
||||
const memeBurnerStore = useMemeburnerStore();
|
||||
const rewardLockerStore = useRewardLockerStore();
|
||||
// TODO: Could be combined in one multicall and could be simplified to request data only for sacrificedToken
|
||||
var data = await memeBurnerStore.getSacrificedCycle(this.currentCycle);
|
||||
var tokenTotalSacrificed = await rewardLockerStore.getTotalSacrificeRewardsForAllToken(this.currentCycle);
|
||||
console.log("this.currentCycle", this.currentCycle);
|
||||
console.log("this.cycles", this.cycles);
|
||||
if (this.cycles[this.currentCycle]) {
|
||||
@@ -99,6 +102,8 @@ export const useCycleStore = defineStore("cycles", {
|
||||
(tokenData) => tokenData.contractAddress === sacrificedToken
|
||||
);
|
||||
this.cycles[this.currentCycle].token[tokenIndex].amount = data[tokenIndex].result[1];
|
||||
// was missed update totalSacrificeRewards for sacrificedToken
|
||||
this.cycles[this.currentCycle].token[tokenIndex].amountInBLD = tokenTotalSacrificed[tokenIndex].result;
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -158,7 +163,8 @@ export const useCycleStore = defineStore("cycles", {
|
||||
const sacrificeClanReward = rewardData[index].result[1];
|
||||
let clanwin = 0n;
|
||||
if (cycleNumber !== this.currentCycle) {
|
||||
clanwin = (coefficent / 10000n - 1n) * sacrificeClanReward;
|
||||
// previous version would not work due to missing remainder
|
||||
clanwin = (sacrificeClanReward * coefficent / 10000n) - sacrificeClanReward;
|
||||
console.log("clanwin", clanwin);
|
||||
}
|
||||
const sacrificeRewards = sacrificeClanReward;
|
||||
@@ -208,6 +214,7 @@ export const useCycleStore = defineStore("cycles", {
|
||||
const array = [];
|
||||
const rewardLockerStore = useRewardLockerStore();
|
||||
const lastCompletedCycle = await rewardLockerStore.lastCompletedCycle();
|
||||
// Question: cycle 0 doesn't exist, does it make sense to start from index 1?
|
||||
for (let index = 0; index <= Number(lastCompletedCycle); index++) {
|
||||
array.push(index);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
*/
|
||||
async getRewards(walletAddress, cycleNumber, tokenAddress) {
|
||||
try {
|
||||
return await this.contract.read.rewards([walletAddress, cycleNumber, tokenAddress]);
|
||||
// rewards function doesn't exist, getRewards instead
|
||||
return await this.contract.read.getRewards([walletAddress, cycleNumber, tokenAddress]);
|
||||
} catch (error) {
|
||||
console.error("getRewards", error);
|
||||
}
|
||||
@@ -117,6 +118,10 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
async getStaked(address) {
|
||||
return await this.contract.read.staked([address]);
|
||||
},
|
||||
async getUnstakeOrdered(address, cycleNumber) {
|
||||
// returns unstake amount of BDL ordered and ready to be unstaked in a cycleNumber
|
||||
return await this.contract.read.unstakeOrdered([cycleNumber,address]);
|
||||
},
|
||||
async orderUnstake() {
|
||||
return await this.contract.write.orderUnstake();
|
||||
},
|
||||
@@ -130,7 +135,8 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
|
||||
const fromAddress = walletStore.address;
|
||||
const spender = this.config.contractAddress;
|
||||
const deadline = Date.now() + 20 * 60;
|
||||
// timestamp is denominated in seconds
|
||||
const deadline = BigInt(Date.now()) / 1000n + 1200n;
|
||||
const decimals = tokenStore.getToken(walletStore.memeToken.contractAddress).decimals;
|
||||
const value = BigInt(tokenNumber) * 10n ** decimals;
|
||||
const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useRewardLockerStore } from "@/stores/rewardlocker";
|
||||
import { useTokenStore } from "@/stores/tokens";
|
||||
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
|
||||
import { showSuccessToast } from "@/helper/toast.js";
|
||||
import { formatNumber } from "@/helper/helper.js";
|
||||
import { formatNumber, formatBigIntDivision } from "@/helper/helper.js";
|
||||
|
||||
export const useSacrificeStore = defineStore("sacrifice", {
|
||||
state: () => ({
|
||||
@@ -64,15 +64,17 @@ export const useSacrificeStore = defineStore("sacrifice", {
|
||||
});
|
||||
console.log("rewardData", rewardData);
|
||||
//output
|
||||
const outputSacrifice = rewardData.reduce((x, y) => {
|
||||
return x + BigInt(y.data) / 10n ** token.decimals;
|
||||
let outputSacrifice = rewardData.reduce((x, y) => {
|
||||
return x + BigInt(y.data);
|
||||
}, 0n);
|
||||
outputSacrifice = formatBigIntDivision(outputSacrifice, 10n ** token.decimals);
|
||||
|
||||
console.log("outputSacrifice", outputSacrifice);
|
||||
token.allowance = await tokenStore.allowance();
|
||||
this.sacrificeState = 4;
|
||||
|
||||
showSuccessToast(
|
||||
formatNumber(outputSacrifice),
|
||||
outputSacrifice,
|
||||
"Success!",
|
||||
"You turned your meme into:",
|
||||
"You can claim once the current cycle is finished and your clan bonus was calculated."
|
||||
|
||||
Reference in New Issue
Block a user