contracts update

This commit is contained in:
Michel Fromme
2023-07-27 15:34:07 +02:00
parent 5157308745
commit 650df134d2
12 changed files with 14369 additions and 16715 deletions
+29 -26
View File
@@ -6,7 +6,7 @@ import { useWalletStore } from "./wallet";
import { useWalletStoreV2 } from "./walletV2";
import { useRoundsStore } from "@/stores/rounds";
import { multicall, getContract, fetchToken } from "@wagmi/core";
import { multicall, getContract, fetchToken, waitForTransaction } from "@wagmi/core";
export const useMemeburnerStore = defineStore("memeburner", {
@@ -21,15 +21,14 @@ export const useMemeburnerStore = defineStore("memeburner", {
console.log("-----------init memeburner-------------");
const walletStore = useWalletStoreV2();
// const roundsStore = useRoundsStore();
console.log("walletStore.walletClient", walletStore.walletClient);
// this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
this.contract = getContract({
address: this.config.contractAddress,
abi: this.config.abi,
PublicClient: walletStore.publicClient,
WalletClient: walletStore.walletClient,
});
abi: this.config.abi,
walletClient: walletStore.walletClient || walletStore.publicClient,
});
console.log("this.contract", this.contract);
// const websocketMemeBurner = new walletStore.web3socket.eth.Contract(
// this.config.abi,
// this.config.contractAddress
@@ -56,35 +55,36 @@ export const useMemeburnerStore = defineStore("memeburner", {
return rewards;
},
async getCurrentRound() {
return await this.contract.methods.currentRound().call();
return await this.contract.read.currentRound();
},
async getGoal(roundnumber) {
return await this.contract.methods.rounds(roundnumber).call();
return await this.contract.read.rounds([roundnumber]);
},
//returns participated, amount achieved
async getSacrificedMeme(roundnumber, tokenAddress) {
return await this.contract.methods.getSacrificedMeme(roundnumber, tokenAddress).call();
return await this.contract.read.getSacrificedMeme([roundnumber, tokenAddress]);
},
async getAmountToReachGoal(tokenAddress) {
return await this.contract.methods.getAmountToReachGoal(tokenAddress).call();
return await this.contract.read.getAmountToReachGoal([tokenAddress]);
},
async getSacrificedRound(roundnumber) {
console.log("getSacrificedRound", roundnumber);
const tokenStore = useTokenStore();
const calls = [];
// const calls1 = [];
const contracts = [];
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(token.name, test);
calls.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
// calls1.push(this.contract.methods.getAmountToReachGoal(token.contractAddress));
// contracts.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
contracts.push({ ...this.contract, functionName: "getSacrificedMeme", args: [roundnumber, token.contractAddress] });
}
console.log("this.contract", this.contract);
const multicallStore = useMultiCallStore();
return await multicallStore.aggregate(calls);
// console.log("this.contract", this.contract);
// const multicallStore = useMultiCallStore();
// return await multicallStore.aggregate(calls);
const data = await multicall({
contracts,
});
return data;
},
async sacrificeMeme(amount) {
const walletStore = useWalletStore();
@@ -97,11 +97,14 @@ export const useMemeburnerStore = defineStore("memeburner", {
}
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 tokenStore.allowance();
console.log("this.contract", this.contract);
var hash = await this.contract.write
.sacrificeMeme([tokenStore.activeToken.contractAddress, amountDecimal])
console.log("hash", hash);
const data = await waitForTransaction({
hash: hash,
});
tokenStore.activeToken.allowance = await tokenStore.allowance();
} catch (error) {
console.error(error);
} finally {
@@ -109,7 +112,7 @@ export const useMemeburnerStore = defineStore("memeburner", {
}
},
async getGoalInBLD(roundNumber) {
return await this.contract.methods.getGoalInBLD(roundNumber).call();
return await this.contract.read.getGoalInBLD([roundNumber]);
},
},
});
+31 -14
View File
@@ -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]);
},
},
});
+12 -10
View File
@@ -3,6 +3,7 @@ import { useMemeburnerStore } from "./memeburner";
import { useTokenStore } from "./tokens";
import { useRewardLockerStore } from "./rewardlocker";
import { useWalletStore } from "./wallet";
import { useWalletStoreV2 } from "./walletV2";
export const useRoundsStore = defineStore("rounds", {
@@ -34,7 +35,7 @@ export const useRoundsStore = defineStore("rounds", {
console.log("fillRound");
const memeBurnerStore = useMemeburnerStore();
const tokenStore = useTokenStore();
const walletStore = useWalletStore();
const walletStore = useWalletStoreV2();
const rewardLockerStore = useRewardLockerStore();
// if (this.activeRound === this.currentRound) {
@@ -51,7 +52,7 @@ export const useRoundsStore = defineStore("rounds", {
console.log("rewardData123", rewardData);
var goal = await memeBurnerStore.getGoal(this.activeRound);
console.log("goal", goal);
var tokenArray = []
var rewards_clan = BigInt(0);
var rewards_sacrifice = BigInt(0);
@@ -66,9 +67,10 @@ export const useRoundsStore = defineStore("rounds", {
tokenData.contractAddress = token.contractAddress;
tokenData.vamplogo = token.vamp.logo;
tokenData.vampname = token.vamp.name;
tokenData.amount = data[index][1];
tokenData.amount = data[index].result[1];
tokenData.getAmountToReachGoal= await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
if (this.currentRound !== this.activeRound && await walletStore.isConnected()) {
if (this.currentRound !== this.activeRound && walletStore.connected) {
console.log("rewarddata", rewardData);
const clanwin = BigInt((testcoef / 10000 - 1) * rewardData[index]);
const sacrificeRewards = BigInt(rewardData[index]) - clanwin;
tokenData.rewards_ges = rewardData[index];
@@ -80,17 +82,17 @@ export const useRoundsStore = defineStore("rounds", {
}
tokenArray.push(tokenData);
}
const goalInBLD = await memeBurnerStore.getGoalInBLD(this.activeRound);
this.rounds[this.activeRound] = {
goal: goal.goal,
goalInBLD: goalInBLD /Math.pow(10, tokenStore.memeToken.decimals),
expirationTimestamp: goal.expirationTimestamp,
goal: goal[0],
goalInBLD: goalInBLD / BigInt(Math.pow(10, tokenStore.memeToken.decimals)),
expirationTimestamp: goal[1],
rewards_clan: rewards_clan,
rewards_sacrifice: rewards_sacrifice,
rewards_total: rewards_clan + rewards_sacrifice,
rewards_sacrifice: rewards_sacrifice,
rewards_total: rewards_clan + rewards_sacrifice,
token: tokenArray,
};
console.log("this.rounds[this.activeRound]", this.rounds[this.activeRound]);
} else {
console.log("round already filled");
}
+3 -3
View File
@@ -78,9 +78,8 @@ export const useTokenStore = defineStore("token", {
token.contract = getContract({
address: token.contractAddress,
abi: token.abi,
PublicClient: walletStore.publicClient,
WalletClient: walletStore.walletClient
});
WalletClient: walletStore.walletClient || walletStore.publicClient,
});
contracts.push({...token.contract, functionName: "decimals"})
}
@@ -137,6 +136,7 @@ export const useTokenStore = defineStore("token", {
const decimals = this.activeToken.decimals;
allowance = BigInt(allowance / BigInt(Math.pow(10, decimals)));
console.log("allowance", allowance);
return allowance;
},
async approveToken(amount) {
+3 -4
View File
@@ -9,8 +9,6 @@ import {
getAccount,
getContract,
connect,
getWalletClient,
getPublicClient,
disconnect,
InjectedConnector,
watchAccount,
@@ -36,7 +34,8 @@ export const useWalletStoreV2 = defineStore("walletV2", {
client: null,
publicClient: null,
walletClient: null,
config: null
config: null,
chain: null,
}),
getters: {},
actions: {
@@ -50,6 +49,7 @@ export const useWalletStoreV2 = defineStore("walletV2", {
[goerli],
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
);
this.config = createConfig({
autoConnect: true,
@@ -79,7 +79,6 @@ export const useWalletStoreV2 = defineStore("walletV2", {
webSocketPublicClient,
});
this.publicClient = publicClient;
this.walletClient = await getWalletClient();
// await this.isConnected();
// const goerliKey = import.meta.env.VITE_GOERLI_KEY;
// if (this.connected) {