contracts update
This commit is contained in:
+31
-14
@@ -3,7 +3,10 @@ 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: () => ({
|
||||
@@ -15,8 +18,13 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
actions: {
|
||||
async init() {
|
||||
console.log("-----------init rewardlocker-------------");
|
||||
const walletStore = useWalletStore();
|
||||
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
||||
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
|
||||
@@ -25,34 +33,43 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
* @returns Rewards for specific token and specific round
|
||||
*/
|
||||
async getRewards(walletAddress, roundNumber, tokenAddress) {
|
||||
return await this.contract.methods.rewards(walletAddress, roundNumber, tokenAddress).call();
|
||||
return await this.contract.read.rewards([walletAddress, roundNumber, tokenAddress]);
|
||||
},
|
||||
async getRewardsForAllToken(roundNumber) {
|
||||
console.log("getRewardsForAllToken");
|
||||
const tokenStore = useTokenStore();
|
||||
const walletStore = useWalletStore();
|
||||
const calls = [];
|
||||
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));
|
||||
}
|
||||
const multicallStore = useMultiCallStore();
|
||||
return await multicallStore.aggregate(calls);
|
||||
// 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.methods.getSacrificedTokenCoefficient(roundNumber, sacrificedToken).call();
|
||||
return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]);
|
||||
},
|
||||
async lastCompletedRound() {
|
||||
return await this.contract.methods.lastCompletedRound().call();
|
||||
return await this.contract.read.lastCompletedRound();
|
||||
},
|
||||
async claim(round) {
|
||||
const walletStore = useWalletStore();
|
||||
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.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.methods.getTotalRewardsOf(address, rounds).call();
|
||||
return await this.contract.read.getTotalRewardsOf([address, rounds]);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user