Files
ImmortalClanVue/src/stores/rewardlocker.js
T

59 lines
2.2 KiB
JavaScript

import { defineStore } from "pinia";
import RewardLockerJson from "@/assets/contracts/RewardLocker.json";
import { useTokenStore } from "./tokens";
import { useMultiCallStore } from "./multicall";
import { useWalletStore } from "./wallet";
import { ethers } from "ethers";
export const useRewardLockerStore = defineStore("rewardlocker", {
state: () => ({
config: RewardLockerJson,
contract: null,
ethcontract: null,
}),
getters: {},
actions: {
async init() {
console.log("-----------init rewardlocker-------------");
const walletStore = useWalletStore();
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
},
/*
* @param {*} walletAddress
* @param {*} roundNumber
* @param {*} tokenAddress
* @returns Rewards for specific token and specific round
*/
async getRewards(walletAddress, roundNumber, tokenAddress) {
return await this.contract.methods.rewards(walletAddress, roundNumber, tokenAddress).call();
},
async getRewardsForAllToken(roundNumber) {
console.log("getRewardsForAllToken");
const tokenStore = useTokenStore();
const walletStore = useWalletStore();
const calls = [];
for (let index = 0; index < tokenStore.token.length; index++) {
const token = tokenStore.token[index];
calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
}
const multicallStore = useMultiCallStore();
return await multicallStore.aggregate(calls);
},
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
return await this.contract.methods.getSacrificedTokenCoefficient(roundNumber, sacrificedToken).call();
},
async lastCompletedRound() {
return await this.contract.methods.lastCompletedRound().call();
},
async claim(round) {
const walletStore = useWalletStore();
// return await this.contract.methods.claim(round).call();
console.log(this.contract.methods.claim(round));
return await this.contract.methods.claim(round).send({from: walletStore.address, to: this.contractAddress});
},
async getTotalRewardsOf(address, rounds) {
return await this.contract.methods.getTotalRewardsOf(address, rounds).call();
},
},
});