init functions for the storage
This commit is contained in:
+76
-11
@@ -2,35 +2,100 @@ import { defineStore } from "pinia";
|
||||
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import { useMultiCallStore } from "./multicall";
|
||||
import { useWalletStore } from "./wallet";
|
||||
import { useRoundsStore } from "@/stores/rounds";
|
||||
|
||||
export const useMemeburnerStore = defineStore("memeburner", {
|
||||
state: () => ({
|
||||
config: MemeBurnerJson,
|
||||
contract: null,
|
||||
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async init() {
|
||||
console.log("-----------init memeburner-------------");
|
||||
const walletStore = useWalletStore();
|
||||
const roundsStore = useRoundsStore();
|
||||
|
||||
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
||||
|
||||
|
||||
const websocketMemeBurner = new walletStore.web3socket.eth.Contract(
|
||||
this.config.abi,
|
||||
this.config.contractAddress
|
||||
);
|
||||
websocketMemeBurner.events
|
||||
.MemeSacrificed()
|
||||
.on("data", async (event) => {
|
||||
console.log("sacrificedAmount", event.returnValues.sacrificedAmount);
|
||||
console.log("sacrificedToken", event.returnValues.sacrificedToken);
|
||||
await roundsStore.updateCurrentRound(
|
||||
event.returnValues.sacrificedToken,
|
||||
event.returnValues.sacrificedAmount
|
||||
);
|
||||
})
|
||||
.on("error", (error) => console.log("MemeSacrificederror", error));
|
||||
},
|
||||
async getRewardsFor(amount) {
|
||||
const tokenStore = useTokenStore();
|
||||
var rewards = await this.contract.methods
|
||||
.getRewardFor(tokenStore.activeToken.contractAddress, amount)
|
||||
.call();
|
||||
return rewards;
|
||||
},
|
||||
async getCurrentRound() {
|
||||
return await this.contract.methods.currentRound().call();
|
||||
},
|
||||
async getGoal (roundnumber) {
|
||||
async getGoal(roundnumber) {
|
||||
return await this.contract.methods.rounds(roundnumber).call();
|
||||
},
|
||||
//returns participated, amount achieved
|
||||
async getSacrificedMeme(roundnumber, tokenAddress) {
|
||||
return await this.contract.methods.getSacrificedMeme(roundnumber, tokenAddress).call();
|
||||
},
|
||||
async getSacrificedRound(roundnumber) {
|
||||
console.log("getSacrificedRound", roundnumber);
|
||||
const tokenStore = useTokenStore();
|
||||
const calls = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
},
|
||||
async getAmountToReachGoal(tokenAddress) {
|
||||
return await this.contract.methods.getAmountToReachGoal(tokenAddress).call();
|
||||
},
|
||||
async getSacrificedRound(roundnumber) {
|
||||
console.log("getSacrificedRound", roundnumber);
|
||||
const tokenStore = useTokenStore();
|
||||
const calls = [];
|
||||
// const calls1 = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
console.log("token.contractAddress", token.contractAddress);
|
||||
console.log("roundnumber", roundnumber);
|
||||
var test = await this.getSacrificedMeme(roundnumber, token.contractAddress);
|
||||
console.log("test", test);
|
||||
calls.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
|
||||
}
|
||||
const multicallStore = useMultiCallStore();
|
||||
// calls1.push(this.contract.methods.getAmountToReachGoal(token.contractAddress));
|
||||
}
|
||||
console.log("this.contract", this.contract);
|
||||
const multicallStore = useMultiCallStore();
|
||||
return await multicallStore.aggregate(calls);
|
||||
|
||||
},
|
||||
async sacrificeMeme(amount) {
|
||||
const walletStore = useWalletStore();
|
||||
const tokenStore = useTokenStore();
|
||||
try {
|
||||
if (!amount || amount == 0) {
|
||||
//todo error
|
||||
console.error("amount is 0 or null or undefined");
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals));
|
||||
var reward = await this.contract.methods
|
||||
.sacrificeMeme(tokenStore.activeToken.contractAddress, amountDecimal)
|
||||
.send({ from: walletStore.address });
|
||||
console.log("reward", reward);
|
||||
tokenStore.activeToken.allowance = await this.allowance();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user