4 Commits
Author SHA1 Message Date
butterscotch a2f8b90cdd comments: proposal how to format output to show fraction. 2023-10-19 16:23:50 +03:00
butterscotch a719ee5989 comments: rewardlocker.js 2023-10-18 21:36:41 +03:00
butterscotch 5e6f373293 comments: sacrifice.js 2023-10-18 21:35:54 +03:00
butterscotch 0b9e14c628 comments: cycle.js 2023-10-18 21:34:04 +03:00
4 changed files with 31 additions and 7 deletions
+9
View File
@@ -29,6 +29,15 @@ export function formatNumber(number) {
return formattedWithOptions; 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) { export function getAddressShortName(address) {
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6"; // const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
const addressBegin = address.substring(0, 6); const addressBegin = address.substring(0, 6);
+8 -1
View File
@@ -91,7 +91,10 @@ export const useCycleStore = defineStore("cycles", {
async updateCurrentCycle(sacrificedToken) { async updateCurrentCycle(sacrificedToken) {
console.log("updateCurrentCycle"); console.log("updateCurrentCycle");
const memeBurnerStore = useMemeburnerStore(); 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 data = await memeBurnerStore.getSacrificedCycle(this.currentCycle);
var tokenTotalSacrificed = await rewardLockerStore.getTotalSacrificeRewardsForAllToken(this.currentCycle);
console.log("this.currentCycle", this.currentCycle); console.log("this.currentCycle", this.currentCycle);
console.log("this.cycles", this.cycles); console.log("this.cycles", this.cycles);
if (this.cycles[this.currentCycle]) { if (this.cycles[this.currentCycle]) {
@@ -99,6 +102,8 @@ export const useCycleStore = defineStore("cycles", {
(tokenData) => tokenData.contractAddress === sacrificedToken (tokenData) => tokenData.contractAddress === sacrificedToken
); );
this.cycles[this.currentCycle].token[tokenIndex].amount = data[tokenIndex].result[1]; 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]; const sacrificeClanReward = rewardData[index].result[1];
let clanwin = 0n; let clanwin = 0n;
if (cycleNumber !== this.currentCycle) { 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); console.log("clanwin", clanwin);
} }
const sacrificeRewards = sacrificeClanReward; const sacrificeRewards = sacrificeClanReward;
@@ -208,6 +214,7 @@ export const useCycleStore = defineStore("cycles", {
const array = []; const array = [];
const rewardLockerStore = useRewardLockerStore(); const rewardLockerStore = useRewardLockerStore();
const lastCompletedCycle = await rewardLockerStore.lastCompletedCycle(); 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++) { for (let index = 0; index <= Number(lastCompletedCycle); index++) {
array.push(index); array.push(index);
} }
+8 -2
View File
@@ -32,7 +32,8 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
*/ */
async getRewards(walletAddress, cycleNumber, tokenAddress) { async getRewards(walletAddress, cycleNumber, tokenAddress) {
try { 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) { } catch (error) {
console.error("getRewards", error); console.error("getRewards", error);
} }
@@ -117,6 +118,10 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
async getStaked(address) { async getStaked(address) {
return await this.contract.read.staked([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() { async orderUnstake() {
return await this.contract.write.orderUnstake(); return await this.contract.write.orderUnstake();
}, },
@@ -130,7 +135,8 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
const fromAddress = walletStore.address; const fromAddress = walletStore.address;
const spender = this.config.contractAddress; 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 decimals = tokenStore.getToken(walletStore.memeToken.contractAddress).decimals;
const value = BigInt(tokenNumber) * 10n ** decimals; const value = BigInt(tokenNumber) * 10n ** decimals;
const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]); const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]);
+6 -4
View File
@@ -9,7 +9,7 @@ import { useRewardLockerStore } from "@/stores/rewardlocker";
import { useTokenStore } from "@/stores/tokens"; import { useTokenStore } from "@/stores/tokens";
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core"; import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
import { showSuccessToast } from "@/helper/toast.js"; import { showSuccessToast } from "@/helper/toast.js";
import { formatNumber } from "@/helper/helper.js"; import { formatNumber, formatBigIntDivision } from "@/helper/helper.js";
export const useSacrificeStore = defineStore("sacrifice", { export const useSacrificeStore = defineStore("sacrifice", {
state: () => ({ state: () => ({
@@ -64,15 +64,17 @@ export const useSacrificeStore = defineStore("sacrifice", {
}); });
console.log("rewardData", rewardData); console.log("rewardData", rewardData);
//output //output
const outputSacrifice = rewardData.reduce((x, y) => { let outputSacrifice = rewardData.reduce((x, y) => {
return x + BigInt(y.data) / 10n ** token.decimals; return x + BigInt(y.data);
}, 0n); }, 0n);
outputSacrifice = formatBigIntDivision(outputSacrifice, 10n ** token.decimals);
console.log("outputSacrifice", outputSacrifice); console.log("outputSacrifice", outputSacrifice);
token.allowance = await tokenStore.allowance(); token.allowance = await tokenStore.allowance();
this.sacrificeState = 4; this.sacrificeState = 4;
showSuccessToast( showSuccessToast(
formatNumber(outputSacrifice), outputSacrifice,
"Success!", "Success!",
"You turned your meme into:", "You turned your meme into:",
"You can claim once the current cycle is finished and your clan bonus was calculated." "You can claim once the current cycle is finished and your clan bonus was calculated."