fill round update + notification update + visual fixes

This commit is contained in:
EmberSpirit
2023-10-08 22:44:14 +02:00
parent 5c7e176457
commit 68cd720c59
12 changed files with 239 additions and 165 deletions
+27 -80
View File
@@ -1,21 +1,20 @@
<template> <template>
<div class="blood-chart-wrapper" v-if="isMobile"> <div class="blood-chart-wrapper">
<div class="blood-arrow left"> <div class="blood-arrow left">
<img <img
class="swiper-arrow" class="swiper-arrow"
src="/assets/img/blood-arrow-left.png" src="/assets/img/blood-arrow-left.png"
alt="left-arrow" alt="left-arrow"
@click="swiperInstance.slidePrev()" @click="swiperInstance.slidePrev()"
v-if="token.length > 3" v-if="token?.length > 3"
/> />
</div> </div>
<swiper <swiper
v-if="isMobile"
class="blood-chart" class="blood-chart"
:slidesPerView="3" :slidesPerView="3"
:centeredSlides="false" :centeredSlides="false"
:initial-slide="0" :initial-slide="0"
:spaceBetween="35" :spaceBetween="IsMobile ? 35 : 0"
@swiper="onSwiper" @swiper="onSwiper"
> >
<swiper-slide class="blood-chart-element" v-for="coin in token" :key="coin.name"> <swiper-slide class="blood-chart-element" v-for="coin in token" :key="coin.name">
@@ -25,75 +24,6 @@
</div> </div>
<div class="blood-chart-coin-title low-mid-text">{{ coin.name }}</div> <div class="blood-chart-coin-title low-mid-text">{{ coin.name }}</div>
</div> </div>
<div class="blood-chart-element-body">
<div class="blood-chart-bar-wrapper">
<svg
class="waves"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 24 150 28"
preserveAspectRatio="none"
shape-rendering="auto"
>
<defs>
<path
id="gentle-wave"
d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z"
/>
</defs>
<g class="parallax">
<use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(139, 0, 0,0.7)" />
<use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(139, 0, 0,0.5)" />
<use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(139, 0, 0,0.3)" />
<use xlink:href="#gentle-wave" x="48" y="7" fill="#8B0000" />
</g>
</svg>
<div class="blood-chart-bar" :style="`height: ${getPercentage(coin.amount, props.data.goal)}%`">
<div class="wrapper">
<div><span class="dot"></span></div>
<div><span class="dot"></span></div>
<div><span class="dot"></span></div>
<div><span class="dot"></span></div>
<div><span class="dot"></span></div>
<div><span class="dot"></span></div>
</div>
<div class="blood-chart-bar-percentage">
{{ getPercentage(coin.amount, props.data.goal) }}%
</div>
</div>
</div>
</div>
<div class="blood-chart-element-footer">
<div class="blood-chart-amount">
<!-- {{ compactNumber(coin.amount) }} -->
{{ coin.amount.toFixed(2) }}
</div>
<div>$BLOOD</div>
</div>
</swiper-slide>
<!-- <button @click="swiperInstance.slidePrev()">left</button>
<button @click="swiperInstance.slideNext()">left</button> -->
</swiper>
<div class="blood-arrow right">
<img
class="swiper-arrow"
src="/assets/img/blood-arrow-right.png"
alt="left-arrow"
@click="swiperInstance.slideNext()"
v-if="token.length > 3"
/>
</div>
</div>
<div class="blood-chart-wrapper" v-else>
<div class="blood-chart">
<div class="blood-chart-element" v-for="coin in token" :key="coin.name">
<div class="blood-chart-element-header">
<div class="blood-chart-coin">
<img :src="getImageUrl(coin.vamplogo)" alt="logo" />
</div>
<div class="blood-chart-coin-title">{{ coin.name }}</div>
</div>
<div class="blood-chart-element-body"> <div class="blood-chart-element-body">
<div class="blood-chart-bar-wrapper"> <div class="blood-chart-bar-wrapper">
<svg <svg
@@ -138,17 +68,29 @@
<div class="blood-chart-element-footer"> <div class="blood-chart-element-footer">
<div class="blood-chart-amount"> <div class="blood-chart-amount">
<!-- {{ compactNumber(coin.amount) }} --> <!-- {{ compactNumber(coin.amount) }} -->
{{ coin.amount.toFixed(2) }} {{ coin.amountInBLD.toFixed(2) }}
</div>
<div class="blood-chart-coin">$BLOOD</div>
</div> </div>
<div>$BLOOD</div>
</div> </div>
</swiper-slide>
<!-- <button @click="swiperInstance.slidePrev()">left</button>
<button @click="swiperInstance.slideNext()">left</button> -->
</swiper>
<div class="blood-arrow right">
<img
class="swiper-arrow"
src="/assets/img/blood-arrow-right.png"
alt="left-arrow"
@click="swiperInstance.slideNext()"
v-if="token?.length > 3"
/>
</div> </div>
</div> </div>
</template> </template>
<script setup> <script setup>
import { computed, ref, inject } from "vue"; import { computed, ref, inject, onMounted } from "vue";
import { getPercentage, compactNumber } from "@/helper/helper.js"; import { getPercentage, compactNumber } from "@/helper/helper.js";
import { useMemeburnerStore } from "@/stores/memeburner"; import { useMemeburnerStore } from "@/stores/memeburner";
import { Swiper, SwiperSlide } from "swiper/vue"; import { Swiper, SwiperSlide } from "swiper/vue";
@@ -164,9 +106,12 @@ const memeBurnerStore = useMemeburnerStore();
const props = defineProps({ const props = defineProps({
data: Object, data: Object,
}); });
const isMobile = inject("isMobile");
console.log(props.data); onMounted(() => {
console.log("bloodchart-data", props.data);
});
const isMobile = inject("isMobile");
const swiperInstance = ref(); const swiperInstance = ref();
@@ -229,8 +174,9 @@ function getPercentageBloodChart(amount, goal) {
.blood-chart-element .blood-chart-element
height: 100% height: 100%
width: 80px width: 80px
align-items: center
@media (min-width: 992px) @media (min-width: 992px)
width: 60px width: 100px
display: flex display: flex
flex-direction: column flex-direction: column
@@ -257,6 +203,7 @@ function getPercentageBloodChart(amount, goal) {
.blood-chart-element-body .blood-chart-element-body
background-color: rgba(233, 233, 233, 0.2) background-color: rgba(233, 233, 233, 0.2)
flex: 0 0 500px flex: 0 0 500px
width: 60px
border-radius: 8px 8px 40px 40px border-radius: 8px 8px 40px 40px
text-align: left text-align: left
overflow: hidden overflow: hidden
+2 -2
View File
@@ -100,6 +100,6 @@ function openUnstake() {
display: flex display: flex
text-align: center text-align: center
gap: 16px gap: 16px
div // div
flex: 1 1 50% // flex: 1 1 50%
</style> </style>
+23 -8
View File
@@ -130,22 +130,29 @@ async function stakeAndClaimAllRounds() {
try { try {
const unclaimedRewards = walletStore.memeToken?.unclaimedRewards; const unclaimedRewards = walletStore.memeToken?.unclaimedRewards;
stateClaim.value = 2; stateClaim.value = 2;
console.log("tokenNumber.value", tokenNumber.value); const coefficient = (10000 * tokenNumber.value) / unclaimedRewards;
console.log("walletStore.memeToken?.unclaimedRewards", walletStore.memeToken?.unclaimedRewards);
const coefficient = (10000 * tokenNumber.value) / walletStore.memeToken?.unclaimedRewards;
var hash = await rewardLockerStore.stakeAndClaimAllRounds(coefficient); var hash = await rewardLockerStore.stakeAndClaimAllRounds(coefficient);
stateClaim.value = 3; stateClaim.value = 3;
const data = await waitForTransaction({ const data = await waitForTransaction({
hash: hash, hash: hash,
}); });
stateClaim.value = 4; stateClaim.value = 4;
await walletStore.loadWalletData(); var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0xd0813ff03c470dcc7baa9ce36914dc2febdfd276d639deffaac383fd3db42ba3"
);
});
//
console.log("rewardData", rewardData);
//ClaimedReward (address staker, uint256 reward)
const outputClaim = Number(rewardData.topics[2]) / Math.pow(10, tokenStore.memeToken.decimals);
showSuccessToast( showSuccessToast(
unclaimedRewards, outputClaim.toFixed(5),
"Success!", "Success!",
"You just claimed and staked", "You just claimed and staked",
"Join the next cycle to increase your rewards and win with your clan" "Join the next cycle to increase your rewards and win with your clan"
); );
await walletStore.loadWalletData();
} catch (error) { } catch (error) {
stateClaim.value = 0; stateClaim.value = 0;
console.error(error); console.error(error);
@@ -161,14 +168,22 @@ async function claimAll() {
const data = await waitForTransaction({ const data = await waitForTransaction({
hash: hash, hash: hash,
}); });
console.log("data", data); var rewardData = data.logs.find((logObject) => {
await walletStore.loadWalletData(); return logObject.topics.find(
(topic) => topic === "0xd0813ff03c470dcc7baa9ce36914dc2febdfd276d639deffaac383fd3db42ba3"
);
});
//
console.log("rewardData", rewardData);
//ClaimedReward (address staker, uint256 reward)
const outputClaim = Number(rewardData.topics[2]) / Math.pow(10, tokenStore.memeToken.decimals);
showSuccessToast( showSuccessToast(
walletStore.memeToken?.unclaimedRewards, outputClaim.toFixed(5),
"Success!", "Success!",
"You just claimed", "You just claimed",
"Join the next cycle to increase your rewards and win with your clan." "Join the next cycle to increase your rewards and win with your clan."
); );
await walletStore.loadWalletData();
} catch (error) { } catch (error) {
state.value = 0; state.value = 0;
console.error(error); console.error(error);
+41 -19
View File
@@ -100,24 +100,19 @@
<img src="/assets/img/moon.png" alt="moon" /> <img src="/assets/img/moon.png" alt="moon" />
</div> </div>
</div> </div>
<div class="sacrifice-fees-info-wrapper">
<div class="sacrifice-fees-img">
<img src="/assets/img/fuel-noozle.png" alt="fuel noozle" />
</div>
<div class="sacrifice-fees-body">
<div class="sacrifice-fees-body-header mid-text">
<div class="sacrifice-fees-body-header-title">Gas Subsidy</div>
<div class="sacrifice-fees-body-header-amount">≤30 Gwei</div>
</div>
<div class="sacrifice-fees-body-subheader">The clan pays your transaction.</div>
</div>
</div>
<div class="sacrifice-buttons-function-wrapper"> <div class="sacrifice-buttons-function-wrapper">
<template v-if="walletStore.connected"> <template v-if="walletStore.connected">
<div class="btn btn-immortal sub-header" disabled v-if="stateComputed === 0">Enter Amount</div> <div class="btn btn-immortal sub-header" disabled v-if="stateComputed === 0">Enter Amount</div>
<div <div
class="btn btn-immortal sub-header" class="btn btn-immortal sub-header"
v-if=" disabled
v-else-if="tokenNumber > activeWalletToken?.balanceOf"
>
Insufficient Balance
</div>
<div
class="btn btn-immortal sub-header"
v-else-if="
activeToken.allowance > 0 && activeToken.allowance > 0 &&
activeToken.allowance >= tokenNumber && activeToken.allowance >= tokenNumber &&
(stateComputed === 1 || stateComputed === 4) (stateComputed === 1 || stateComputed === 4)
@@ -128,7 +123,7 @@
</div> </div>
<div <div
class="btn btn-immortal sub-header" class="btn btn-immortal sub-header"
v-if=" v-else-if="
(!activeToken.allowance || activeToken.allowance < tokenNumber) && (!activeToken.allowance || activeToken.allowance < tokenNumber) &&
(stateComputed === 1 || stateComputed === 4) (stateComputed === 1 || stateComputed === 4)
" "
@@ -152,6 +147,7 @@
<script setup> <script setup>
import { ref, defineProps, watch, inject, nextTick, onMounted, onBeforeUnmount, computed, markRaw } from "vue"; import { ref, defineProps, watch, inject, nextTick, onMounted, onBeforeUnmount, computed, markRaw } from "vue";
import { useWalletStoreV2 } from "@/stores/walletV2"; import { useWalletStoreV2 } from "@/stores/walletV2";
import { useRoundsStore } from "@/stores/rounds";
import { useTokenStore } from "@/stores/tokens"; import { useTokenStore } from "@/stores/tokens";
import { useMemeburnerStore } from "@/stores/memeburner"; import { useMemeburnerStore } from "@/stores/memeburner";
import { useUniswapStore } from "@/stores/uniswap"; import { useUniswapStore } from "@/stores/uniswap";
@@ -163,6 +159,7 @@ import TokenLogo from "@/components/TokenLogo.vue";
import StakeSuccessToast from "@/components/toasts/StakeSuccessToast.vue"; import StakeSuccessToast from "@/components/toasts/StakeSuccessToast.vue";
import { useToast } from "vue-toastification"; import { useToast } from "vue-toastification";
const roundStore = useRoundsStore();
const toast = useToast(); const toast = useToast();
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core"; import { waitForTransaction, readContract, watchBlockNumber, multicall } from "@wagmi/core";
@@ -294,12 +291,20 @@ async function sacrificeToken(amount) {
state.value = 3; state.value = 3;
const data = await waitForTransaction({ const data = await waitForTransaction({
hash: hash, hash: hash,
onReplaced: (transaction) => console.log("check transaction canceled", transaction),
}); });
console.log("data", data); console.log("data", data);
var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0x5e60ccd3c81486143d815dce24867a494d7fee585a0a44282cf479b19a5186ee"
);
});
const outputSacrifice = Number(rewardData.data) / Math.pow(10, activeToken.value.decimals);
//activeToken is bad here, because it could change during async request
activeToken.value.allowance = await tokenStore.allowance(); activeToken.value.allowance = await tokenStore.allowance();
state.value = 4; state.value = 4;
console.log("state.value = 4"); console.log("state.value = 4");
const outputSacrifice = output.value;
showSuccessToast( showSuccessToast(
outputSacrifice?.toFixed(5), outputSacrifice?.toFixed(5),
"Success!", "Success!",
@@ -307,6 +312,7 @@ async function sacrificeToken(amount) {
"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."
); );
await walletStore.loadWalletData(); await walletStore.loadWalletData();
await roundStore.fillRound(roundStore.currentRound, true);
} catch (error) { } catch (error) {
state.value = 0; state.value = 0;
console.error(error); console.error(error);
@@ -327,6 +333,8 @@ async function approveToken(amount) {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
throw new Error(error); throw new Error(error);
} finally {
state.value = 0;
} }
} }
@@ -344,17 +352,27 @@ async function getRewardsFor(value) {
const rewardsForResult = await memeburnerStore.getRewardFor( const rewardsForResult = await memeburnerStore.getRewardFor(
BigInt(value * Math.pow(10, activeToken.value.decimals)) BigInt(value * Math.pow(10, activeToken.value.decimals))
); );
const rewardsForResultNumber = Number(rewardsForResult[0]) / Math.pow(10, tokenStore.activeToken.decimals); // const rewardsForResultNumber = Number(rewardsForResult[0]) / Math.pow(10, tokenStore.activeToken.decimals) + Number(rewardsForResult[1]) / Math.pow(10, tokenStore.activeToken.decimals);
const rewardsForResultNumber = rewardsForResult.reduce((x, y) => {
return x + Number(y) / Math.pow(10, tokenStore.activeToken.decimals);
}, 0);
var quoteRewards = await uniswapStore.quoteExactInputSingle( var quoteRewards = await uniswapStore.quoteExactInputSingle(
tokenNumber.value * Math.pow(10, tokenStore.activeToken.decimals) tokenNumber.value * Math.pow(10, tokenStore.activeToken.decimals)
); );
console.log("quoteRewards", quoteRewards);
let variant = "sacrifice"; let variant = "sacrifice";
if (quoteRewards.result) { if (quoteRewards.result) {
console.log("quoteRewards", quoteRewards); console.log("quoteRewards", quoteRewards);
const quoteRewardsNumber = Number(quoteRewards.amount) / Math.pow(10, tokenStore.activeToken.decimals); const quoteRewardsNumber = Number(quoteRewards.amount) / Math.pow(10, tokenStore.activeToken.decimals);
if (quoteRewardsNumber * 0.995 > rewardsForResultNumber) { if (quoteRewardsNumber * 0.995 > rewardsForResultNumber) {
variant = "buy"; variant = "buy";
console.log("use Buy-function", { quoteRewardsNumber: quoteRewardsNumber, rewardsForResultNumber });
} else {
console.log("use sacrifice-function", {
quoteRewardsNumber: quoteRewardsNumber,
rewardsForResultNumber,
});
} }
} else { } else {
/** /**
@@ -364,7 +382,7 @@ async function getRewardsFor(value) {
// //
newOutput = rewardsForResultNumber; newOutput = rewardsForResultNumber;
} }
console.log("variant", variant);
const amountDecimal = BigInt(value * Math.pow(10, tokenStore.activeToken.decimals)); const amountDecimal = BigInt(value * Math.pow(10, tokenStore.activeToken.decimals));
console.log("amountDecimal", amountDecimal); console.log("amountDecimal", amountDecimal);
if (!walletStore.connected || (walletStore.connected && activeToken.value.allowance < tokenNumber.value)) { if (!walletStore.connected || (walletStore.connected && activeToken.value.allowance < tokenNumber.value)) {
@@ -402,21 +420,25 @@ async function getRewardsFor(value) {
account: walletStore.address, account: walletStore.address,
}); });
const amountBuyNumber = Number(amountBuy) / Math.pow(10, tokenStore.activeToken.decimals); const amountBuyNumber = Number(amountBuy) / Math.pow(10, tokenStore.activeToken.decimals);
const amountSacrificeNumber = Number(amountSacrifice) / Math.pow(10, tokenStore.activeToken.decimals); const amountSacrificeNumber = Number(amountSacrifice) / Math.pow(10, tokenStore.activeToken.decimals);
console.log("sacrificeMemeAndBuyBLOOD", amountBuyNumber);
console.log("sacrificeMeme", amountSacrificeNumber);
if (amountBuyNumber * 0.995 > amountSacrificeNumber) { if (amountBuyNumber * 0.995 > amountSacrificeNumber) {
variant = "buy"; variant = "buy";
newOutput = amountBuyNumber; newOutput = amountBuyNumber;
console.log("use buy after comparison sacrificeMemeAndBuyBLOOD and sacrificeMeme");
} else { } else {
variant = "sacrifice"; variant = "sacrifice";
newOutput = amountSacrificeNumber; newOutput = amountSacrificeNumber;
console.log("use sacrifice after comparison sacrificeMemeAndBuyBLOOD and sacrificeMeme");
} }
} }
output.value = newOutput; output.value = newOutput;
return { ouput: newOutput, variant: variant }; return { ouput: newOutput, variant: variant };
} catch (error) { } catch (error) {
console.log("error", error); console.error("getRewardsFor", error);
} finally { } finally {
loading.value = false; loading.value = false;
} }
+45 -12
View File
@@ -55,7 +55,7 @@
v-model="tokenNumber" v-model="tokenNumber"
@close="stakeMenu = false" @close="stakeMenu = false"
:stake="stake" :stake="stake"
:amount="walletStore.memeToken.balanceOf" :amount="walletStore.memeToken?.balanceOf"
v-if="stakeMenu & !unstakeMenu" v-if="stakeMenu & !unstakeMenu"
> >
<template v-slot:body> <template v-slot:body>
@@ -79,7 +79,7 @@
</div> </div>
</template> </template>
<template v-slot:message-end> <template v-slot:message-end>
<div class="input-balance">Balance: {{ walletStore.memeToken.balanceOf }}</div> <div class="input-balance">Balance: {{ walletStore.memeToken?.balanceOf }}</div>
</template> </template>
</stake-menu> </stake-menu>
<div class="unstake-menu" v-else-if="stakeMenu & unstakeMenu"> <div class="unstake-menu" v-else-if="stakeMenu & unstakeMenu">
@@ -87,10 +87,16 @@
To prevent users from farming rewards you can claim your stake next cycle. To prevent users from farming rewards you can claim your stake next cycle.
</div> </div>
<div class="unstake-menu-actions"> <div class="unstake-menu-actions">
<div class="btn btn-immortal stake-button" v-if="!loading" @click="orderUnstake"> <div class="btn btn-immortal stake-button" v-if="stateStake <= 1" @click="orderUnstake">
Unstake Next Cycle Unstake Next Cycle
</div> </div>
<div class="btn btn--disabled" v-else>Sign Transaction</div> <div class="btn btn--disabled mid-mid-text text-center" v-else-if="stateStake === 2">
Sign Transaction
</div>
<div class="btn btn--disabled mid-mid-text text-center" v-else-if="stateStake === 3">
<loading-component></loading-component>
</div>
<div <div
class="btn transparent small-text cancel-button text-center" class="btn transparent small-text cancel-button text-center"
@click="stakeMenu = false" @click="stakeMenu = false"
@@ -175,7 +181,7 @@ function openUnstake() {
} }
async function orderUnstake() { async function orderUnstake() {
loading.value = true; try {
state.value = 2; state.value = 2;
var hash = await rewardLockerStore.orderUnstake(); var hash = await rewardLockerStore.orderUnstake();
state.value = 3; state.value = 3;
@@ -183,9 +189,26 @@ async function orderUnstake() {
hash: hash, hash: hash,
}); });
state.value = 4; state.value = 4;
var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0xd0813ff03c470dcc7baa9ce36914dc2febdfd276d639deffaac383fd3db42ba3"
);
});
console.log("rewardData", rewardData);
const outputClaim = Number(rewardData.topics[2]) / Math.pow(10, tokenStore.memeToken.decimals);
showSuccessToast(
outputClaim.toFixed(5),
"Success!",
"You just unstaked",
"You can claim your stake next cycle."
);
await walletStore.loadWalletData(); await walletStore.loadWalletData();
showSuccessToast(); } catch (error) {
loading.value = false; console.error("orderUnstake", error);
} finally {
state.value = 0;
}
} }
async function stakeToken() { async function stakeToken() {
@@ -196,33 +219,43 @@ async function stakeToken() {
const data = await waitForTransaction({ const data = await waitForTransaction({
hash: hash, hash: hash,
}); });
var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0xf496bf2b14b1d178412b6f7a745900105b49b38b315cfdfbfabad31a6f995c6f"
);
});
//
console.log("rewardData", rewardData);
const outputClaim = Number(rewardData.topics[3]) / Math.pow(10, tokenStore.memeToken.decimals);
console.log("data", data); console.log("data", data);
state.value = 4; state.value = 4;
await walletStore.loadWalletData(); await walletStore.loadWalletData();
showSuccessToast( showSuccessToast(
tokenNumber.value, outputClaim.toFixed(5),
"Success!", "Success!",
"You just staked", "You just staked",
"Your next sacrifice will get an extra staking bonus as a reward." "Your next sacrifice will get an extra staking bonus as a reward."
); );
//reload data //reload data
} catch (error) { } catch (error) {
state.value = 0;
console.error(error); console.error(error);
throw new Error(error); throw new Error(error);
} finally {
state.value = 0;
} }
} }
const stateStake = computed(() => { const stateStake = computed(() => {
let returnState = 0; let returnState = 0;
if (tokenNumber.value === null || tokenNumber.value === "" || tokenNumber.value === 0) { if (state.value === 2) {
returnState = 0;
} else if (state.value === 2) {
returnState = 2; returnState = 2;
} else if (state.value === 3) { } else if (state.value === 3) {
returnState = 3; returnState = 3;
} else if (tokenNumber.value !== null || tokenNumber.value !== "" || tokenNumber.value > 0) { } else if (tokenNumber.value !== null || tokenNumber.value !== "" || tokenNumber.value > 0) {
returnState = 1; returnState = 1;
} else if (tokenNumber.value === null || tokenNumber.value === "" || tokenNumber.value === 0) {
returnState = 0;
} }
return returnState; return returnState;
}); });
+45 -2
View File
@@ -106,6 +106,7 @@ import RewardsWrapper from "@/components/RewardsWrapper.vue";
import { inject, ref, onMounted, computed } from "vue"; import { inject, ref, onMounted, computed } from "vue";
import { useRewardLockerStore } from "@/stores/rewardlocker"; import { useRewardLockerStore } from "@/stores/rewardlocker";
import { useWalletStoreV2 } from "@/stores/walletV2"; import { useWalletStoreV2 } from "@/stores/walletV2";
import { useTokenStore } from "@/stores/tokens";
import { useRoundsStore } from "@/stores/rounds"; import { useRoundsStore } from "@/stores/rounds";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import StakeMenu from "@/components/StakeMenu.vue"; import StakeMenu from "@/components/StakeMenu.vue";
@@ -120,6 +121,8 @@ const isMobile = inject("isMobile");
const showPanel = inject("showPanel"); const showPanel = inject("showPanel");
const rewardLockerStore = useRewardLockerStore(); const rewardLockerStore = useRewardLockerStore();
const walletStore = useWalletStoreV2(); const walletStore = useWalletStoreV2();
const tokenStore = useTokenStore();
const roundStore = useRoundsStore(); const roundStore = useRoundsStore();
const { address } = storeToRefs(walletStore); const { address } = storeToRefs(walletStore);
const router = useRouter(); const router = useRouter();
@@ -132,10 +135,34 @@ const tokenNumber = ref(null);
const stateClaim = ref(0); const stateClaim = ref(0);
async function stakeAndClaim() { async function stakeAndClaim() {
try {
console.log(tokenNumber.value); console.log(tokenNumber.value);
console.log(getCurrentRoundData.value.rewards_total); console.log(getCurrentRoundData.value.rewards_total);
const coefficient = (10000 * tokenNumber.value) / getCurrentRoundData.value.rewards_total; const coefficient = (10000 * tokenNumber.value) / getCurrentRoundData.value.rewards_total;
var result = await rewardLockerStore.stakeAndClaimRound(coefficient, roundStore.activeRound); var hash = await rewardLockerStore.stakeAndClaimRound(coefficient, roundStore.activeRound);
const data = await waitForTransaction({
hash: hash,
});
//ClaimedReward (address staker, uint256 reward)
var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0xf86340d97020c624010a208b733db95795281fbc45cb6e6a40d161f91fa3e4a0"
);
});
//
console.log("rewardData", rewardData);
const outputClaim = Number(rewardData.topics[2]) / Math.pow(10, tokenStore.memeToken.decimals);
showSuccessToast(
outputClaim.toFixed(5),
"Success!",
"You just claimed and staked",
"Join the next cycle to increase your rewards and win with your clan."
);
const walletStore = useWalletStoreV2();
await walletStore.loadWalletData();
} catch (error) {
console.error("stakeAndClaim", error);
}
} }
function openStake() { function openStake() {
@@ -157,7 +184,23 @@ async function claimRewards() {
hash: hash, hash: hash,
}); });
stateClaim.value = 4; stateClaim.value = 4;
//reload // ClaimedReward (address staker, uint256 reward)
var rewardData = data.logs.find((logObject) => {
return logObject.topics.find(
(topic) => topic === "0xd0813ff03c470dcc7baa9ce36914dc2febdfd276d639deffaac383fd3db42ba3"
);
});
//
console.log("rewardData", rewardData);
const outputClaim = Number(rewardData.topics[2]) / Math.pow(10, tokenStore.memeToken.decimals);
showSuccessToast(
outputClaim.toFixed(5),
"Success!",
"You just claimed",
"Join the next cycle to increase your rewards and win with your clan."
);
await roundStore.fillRound(activeRound.value, true); await roundStore.fillRound(activeRound.value, true);
await walletStore.loadWalletData(); await walletStore.loadWalletData();
} catch (error) { } catch (error) {
-6
View File
@@ -33,7 +33,6 @@ export const useMemeburnerStore = defineStore("memeburner", {
tokenStore.activeToken.contractAddress, tokenStore.activeToken.contractAddress,
amount, amount,
]); ]);
console.log("tokenStore.activeToken.contractAddress", tokenStore.activeToken.contractAddress);
console.log("amount", amount); console.log("amount", amount);
console.log("rewards", rewards); console.log("rewards", rewards);
return rewards; return rewards;
@@ -57,8 +56,6 @@ export const useMemeburnerStore = defineStore("memeburner", {
const contracts = []; const contracts = [];
for (let index = 0; index < tokenStore.sacrificeToken.length; index++) { for (let index = 0; index < tokenStore.sacrificeToken.length; index++) {
const token = tokenStore.sacrificeToken[index]; const token = tokenStore.sacrificeToken[index];
console.log("token.contractAddress", token.contractAddress);
console.log("roundnumber", roundnumber);
// contracts.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress)); // contracts.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
contracts.push({ contracts.push({
...this.contract, ...this.contract,
@@ -84,9 +81,6 @@ export const useMemeburnerStore = defineStore("memeburner", {
} }
this.loading = true; this.loading = true;
const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals)); const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals));
console.log("this.contract", this.contract);
console.log("amountDecimal", amountDecimal.toString());
console.log("tokenStore.activeToken.contractAddress", tokenStore.activeToken.contractAddress);
var hash = await this.contract.write.sacrificeMeme([ var hash = await this.contract.write.sacrificeMeme([
tokenStore.activeToken.contractAddress, tokenStore.activeToken.contractAddress,
amountDecimal.toString(), amountDecimal.toString(),
+29 -7
View File
@@ -58,6 +58,29 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
// const multicallStore = useMultiCallStore(); // const multicallStore = useMultiCallStore();
return data; return data;
}, },
async getTotalSacrificeRewardsForAllToken(roundNumber) {
try {
const tokenStore = useTokenStore();
const contracts = [];
for (let index = 0; index < tokenStore.sacrificeToken.length; index++) {
const token = tokenStore.sacrificeToken[index];
// calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
contracts.push({
...this.contract,
functionName: "getTotalSacrificeRewardsForToken",
args: [roundNumber, token.contractAddress],
});
}
const data = await multicall({
contracts,
});
// const multicallStore = useMultiCallStore();
return data;
} catch (error) {
throw new Error(error)
}
},
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) { async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
try { try {
return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]); return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]);
@@ -106,7 +129,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
return await this.contract.read.getTotalRewardsOf([address, rounds]); return await this.contract.read.getTotalRewardsOf([address, rounds]);
} catch (error) { } catch (error) {
console.error("getTotalRewards", error); console.error("getTotalRewards", error);
throw new Error(error);
} }
}, },
async getStaked(address) { async getStaked(address) {
@@ -114,6 +137,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
return await this.contract.read.staked([address]); return await this.contract.read.staked([address]);
} catch (error) { } catch (error) {
console.error("getStaked", error); console.error("getStaked", error);
throw new Error(error);
} }
}, },
async orderUnstake() { async orderUnstake() {
@@ -121,6 +145,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
return await this.contract.write.orderUnstake(); return await this.contract.write.orderUnstake();
} catch (error) { } catch (error) {
console.error("orderUnstake", error); console.error("orderUnstake", error);
throw new Error(error)
} }
}, },
async unstake(unstakeRound) { async unstake(unstakeRound) {
@@ -128,6 +153,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
return await this.contract.write.unstake([unstakeRound]); return await this.contract.write.unstake([unstakeRound]);
} catch (error) { } catch (error) {
console.error("unstake", error); console.error("unstake", error);
throw new Error(error);
} }
}, },
async stakeBloodline(tokenNumber) { async stakeBloodline(tokenNumber) {
@@ -139,7 +165,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
const spender = this.config.contractAddress; const spender = this.config.contractAddress;
const deadline = Date.now() + 20 * 60; const deadline = Date.now() + 20 * 60;
const decimals = tokenStore.getToken(walletStore.memeToken.contractAddress).decimals; const decimals = tokenStore.getToken(walletStore.memeToken.contractAddress).decimals;
const value = (tokenNumber * Math.pow(10, decimals)).toString(); const value = BigInt(tokenNumber * Math.pow(10, decimals))
const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]); const nonce = await tokenStore.memeToken.contract.read.nonces([fromAddress]);
console.log("nonce", nonce); console.log("nonce", nonce);
const { types, message, domain, primaryType } = createPermitObject( const { types, message, domain, primaryType } = createPermitObject(
@@ -171,9 +197,7 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
const data = await waitForTransaction({ const data = await waitForTransaction({
hash: hash, hash: hash,
}); });
const walletStore = useWalletStoreV2(); return hash;
await walletStore.loadWalletData();
// todo reload roundData and wallet data
}, },
async stakeAndClaimAllRounds(stakeCoefficient) { async stakeAndClaimAllRounds(stakeCoefficient) {
console.log("stakeAndClaimAllRounds"); console.log("stakeAndClaimAllRounds");
@@ -181,8 +205,6 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
const roundsStore = useRoundsStore(); const roundsStore = useRoundsStore();
const rounds = await roundsStore.getFinshedRoundNumbers(); const rounds = await roundsStore.getFinshedRoundNumbers();
const addresses = tokenStore.sacrificeToken.map((obj) => obj.contractAddress); const addresses = tokenStore.sacrificeToken.map((obj) => obj.contractAddress);
console.log({ stakeCoefficient, rounds, addresses });
console.log("stakeCoefficient", stakeCoefficient);
var stakeCoefficientInt = Math.round(stakeCoefficient); var stakeCoefficientInt = Math.round(stakeCoefficient);
const hash = await this.contract.write.stakeAndClaim([stakeCoefficientInt, rounds, addresses]); const hash = await this.contract.write.stakeAndClaim([stakeCoefficientInt, rounds, addresses]);
return hash; return hash;
+4 -5
View File
@@ -26,8 +26,6 @@ export const useRoundsStore = defineStore("rounds", {
} }
}, },
getCurrentRoundData() { getCurrentRoundData() {
console.log("this.rounds", this.rounds);
console.log("this.rounds[this.activeRound]", this.rounds[this.activeRound]);
return this.rounds[this.activeRound]; return this.rounds[this.activeRound];
}, },
}, },
@@ -95,13 +93,13 @@ export const useRoundsStore = defineStore("rounds", {
// } else // } else
if (!this.rounds[roundNumber]?.goal || refillRound) { if (!this.rounds[roundNumber]?.goal || refillRound) {
console.log("round not filled --> fill round"); console.log("round not filled --> fill round");
console.log("vor error");
var data = await memeBurnerStore.getSacrificedRound(roundNumber); var data = await memeBurnerStore.getSacrificedRound(roundNumber);
let rewardData = null; let rewardData = null;
if (walletStore.connected) { if (walletStore.connected) {
rewardData = await rewardLockerStore.getRewardsForAllToken(roundNumber); rewardData = await rewardLockerStore.getRewardsForAllToken(roundNumber);
} }
const tokenTotalSacrificed = await rewardLockerStore.getTotalSacrificeRewardsForAllToken(roundNumber);
var goal = await memeBurnerStore.getGoal(roundNumber); var goal = await memeBurnerStore.getGoal(roundNumber);
console.log("goal", goal); console.log("goal", goal);
var tokenArray = []; var tokenArray = [];
@@ -124,6 +122,7 @@ export const useRoundsStore = defineStore("rounds", {
tokenData.vampname = token.vamp.name; tokenData.vampname = token.vamp.name;
// tokenData.amount = data[index].result[1]; // tokenData.amount = data[index].result[1];
tokenData.amount = Number(data[index].result[1]) / Math.pow(10, token.decimals); tokenData.amount = Number(data[index].result[1]) / Math.pow(10, token.decimals);
tokenData.amountInBLD = Number(tokenTotalSacrificed[index].result) / Math.pow(10, token.decimals);
// tokenData.getAmountToReachGoal = // tokenData.getAmountToReachGoal =
// Number(await memeBurnerStore.getAmountToReachGoal(token.contractAddress)) / // Number(await memeBurnerStore.getAmountToReachGoal(token.contractAddress)) /
// Math.pow(10, token.decimals); // Math.pow(10, token.decimals);
@@ -133,11 +132,11 @@ export const useRoundsStore = defineStore("rounds", {
const stakeReward = Number(rewardData[index].result[0]); const stakeReward = Number(rewardData[index].result[0]);
const sacrificeClanReward = Number(rewardData[index].result[1]); const sacrificeClanReward = Number(rewardData[index].result[1]);
let clanwin = 0; let clanwin = 0;
if (this.activeRound !== this.currentRound) { if (roundNumber !== this.currentRound) {
clanwin = (Number(coefficent) / 10000 - 1) * sacrificeClanReward; clanwin = (Number(coefficent) / 10000 - 1) * sacrificeClanReward;
console.log("clanwin", clanwin); console.log("clanwin", clanwin);
} }
const sacrificeRewards = Number(sacrificeClanReward) - clanwin; const sacrificeRewards = Number(sacrificeClanReward);
tokenData.rewards_ges = Number( tokenData.rewards_ges = Number(
rewardData[index].result[1] / BigInt(Math.pow(10, token.decimals)) + rewardData[index].result[1] / BigInt(Math.pow(10, token.decimals)) +
+3 -3
View File
@@ -44,18 +44,18 @@ export const useUniswapStore = defineStore("uniswap", {
const memeBurnerStore = useMemeburnerStore(); const memeBurnerStore = useMemeburnerStore();
var amountEthBase = await memeBurnerStore.getAmountETHBase(amount); var amountEthBase = await memeBurnerStore.getAmountETHBase(amount);
console.log("amountEthBase", amountEthBase); console.log("amountEthBase", amountEthBase);
console.log("123", { console.log("quoteExactInputSingle-parameter", {
token0: this.poolData.token0, token0: this.poolData.token0,
token1: this.poolData.token1, token1: this.poolData.token1,
fee: this.poolData.fee, fee: this.poolData.fee,
amountEthBase: amountEthBase, amountEthBase: amountEthBase[1],
pricelimit: 0, //sqrtPriceLimitX96 pricelimit: 0, //sqrtPriceLimitX96
}); });
const quotedAmountOut = await this.quoateV3Contract.read.quoteExactInputSingle([ const quotedAmountOut = await this.quoateV3Contract.read.quoteExactInputSingle([
this.poolData.token0, //bloodline this.poolData.token0, //bloodline
this.poolData.token1, //weth this.poolData.token1, //weth
this.poolData.fee, this.poolData.fee,
amountEthBase, amountEthBase[1],
0, //sqrtPriceLimitX96 0, //sqrtPriceLimitX96
]); ]);
return {result: true, amount: quotedAmountOut}; return {result: true, amount: quotedAmountOut};
+1 -2
View File
@@ -29,7 +29,6 @@ import { alchemyProvider } from "@wagmi/core/providers/alchemy";
export const useWalletStoreV2 = defineStore("walletV2", { export const useWalletStoreV2 = defineStore("walletV2", {
state: () => ({ state: () => ({
count: 0,
alchemy: null, alchemy: null,
connected: false, connected: false,
address: null, address: null,
@@ -40,7 +39,7 @@ export const useWalletStoreV2 = defineStore("walletV2", {
config: null, config: null,
chain: null, chain: null,
token: [], token: [],
initialized1: false, stateSacrifice: 0,
}), }),
getters: { getters: {
sacrificeToken: (state) => state.token.filter((obj) => { sacrificeToken: (state) => state.token.filter((obj) => {
+1 -1
View File
@@ -71,7 +71,7 @@
memes. memes.
</p> </p>
<div class="bloodline-container"> <div class="bloodline-container">
<div class="bloodline-border purple">Get up to +100% Clan Bonus <br />on your sacrifice.</div> <div class="bloodline-border purple">Get up to +25% Clan Bonus <br />on your sacrifice.</div>
</div> </div>
<blood-chart :data="roundsStore.rounds[roundsStore.activeRound]"></blood-chart> <blood-chart :data="roundsStore.rounds[roundsStore.activeRound]"></blood-chart>
</div> </div>