76 lines
2.8 KiB
JavaScript
76 lines
2.8 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 { useWalletStoreV2 } from "./walletV2";
|
|
import { ethers } from "ethers";
|
|
import { multicall, getContract } from "@wagmi/core";
|
|
|
|
|
|
export const useRewardLockerStore = defineStore("rewardlocker", {
|
|
state: () => ({
|
|
config: RewardLockerJson,
|
|
contract: null,
|
|
ethcontract: null,
|
|
}),
|
|
getters: {},
|
|
actions: {
|
|
async init() {
|
|
console.log("-----------init rewardlocker-------------");
|
|
const walletStore = useWalletStoreV2();
|
|
this.contract = getContract({
|
|
address: this.config.contractAddress,
|
|
abi: this.config.abi,
|
|
walletClient: walletStore.walletClient || walletStore.publicClient,
|
|
});
|
|
// 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.read.rewards([walletAddress, roundNumber, tokenAddress]);
|
|
},
|
|
async getRewardsForAllToken(roundNumber) {
|
|
console.log("getRewardsForAllToken");
|
|
const tokenStore = useTokenStore();
|
|
const walletStore = useWalletStoreV2();
|
|
const contracts = [];
|
|
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));
|
|
contracts.push({
|
|
...this.contract,
|
|
functionName: "rewards",
|
|
args: [walletStore.address, roundNumber, token.contractAddress],
|
|
});
|
|
}
|
|
const data = await multicall({
|
|
contracts,
|
|
});
|
|
// const multicallStore = useMultiCallStore();
|
|
return data
|
|
},
|
|
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
|
|
return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]);
|
|
},
|
|
async lastCompletedRound() {
|
|
return await this.contract.read.lastCompletedRound();
|
|
},
|
|
async claim(round) {
|
|
const walletStore = useWalletStoreV2();
|
|
// 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});
|
|
return await this.contract.write.claim([round]);
|
|
},
|
|
async getTotalRewardsOf(address, rounds) {
|
|
return await this.contract.read.getTotalRewardsOf([address, rounds]);
|
|
},
|
|
},
|
|
});
|