contract changes init
This commit is contained in:
+47
-38
@@ -3,46 +3,56 @@ import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import { useMultiCallStore } from "./multicall";
|
||||
import { useWalletStore } from "./wallet";
|
||||
import { useWalletStoreV2 } from "./walletV2";
|
||||
import { useRoundsStore } from "@/stores/rounds";
|
||||
|
||||
import { multicall, getContract, fetchToken } from "@wagmi/core";
|
||||
|
||||
|
||||
export const useMemeburnerStore = defineStore("memeburner", {
|
||||
state: () => ({
|
||||
config: MemeBurnerJson,
|
||||
contract: null,
|
||||
loading: false,
|
||||
|
||||
contract: null,
|
||||
loading: false,
|
||||
}),
|
||||
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 walletStore = useWalletStoreV2();
|
||||
// const roundsStore = useRoundsStore();
|
||||
|
||||
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));
|
||||
// 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,
|
||||
});
|
||||
|
||||
// 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) {
|
||||
async getRewardFor(amount) {
|
||||
const tokenStore = useTokenStore();
|
||||
var rewards = await this.contract.methods
|
||||
.getRewardFor(tokenStore.activeToken.contractAddress, amount)
|
||||
.call();
|
||||
// var rewards = await this.contract.methods
|
||||
// .getRewardFor(tokenStore.activeToken.contractAddress, amount)
|
||||
// .call();
|
||||
const rewards = await this.contract.read.getRewardFor([tokenStore.activeToken.contractAddress, amount]);
|
||||
console.log("rewards", rewards);
|
||||
return rewards;
|
||||
},
|
||||
async getCurrentRound() {
|
||||
@@ -54,10 +64,10 @@ export const useMemeburnerStore = defineStore("memeburner", {
|
||||
//returns participated, amount achieved
|
||||
async getSacrificedMeme(roundnumber, tokenAddress) {
|
||||
return await this.contract.methods.getSacrificedMeme(roundnumber, tokenAddress).call();
|
||||
},
|
||||
async getAmountToReachGoal(tokenAddress) {
|
||||
return await this.contract.methods.getAmountToReachGoal(tokenAddress).call();
|
||||
},
|
||||
},
|
||||
async getAmountToReachGoal(tokenAddress) {
|
||||
return await this.contract.methods.getAmountToReachGoal(tokenAddress).call();
|
||||
},
|
||||
async getSacrificedRound(roundnumber) {
|
||||
console.log("getSacrificedRound", roundnumber);
|
||||
const tokenStore = useTokenStore();
|
||||
@@ -68,9 +78,9 @@ export const useMemeburnerStore = defineStore("memeburner", {
|
||||
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));
|
||||
console.log(token.name, test);
|
||||
calls.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
|
||||
// calls1.push(this.contract.methods.getAmountToReachGoal(token.contractAddress));
|
||||
}
|
||||
console.log("this.contract", this.contract);
|
||||
const multicallStore = useMultiCallStore();
|
||||
@@ -97,10 +107,9 @@ export const useMemeburnerStore = defineStore("memeburner", {
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
async getGoalInBLD(roundNumber) {
|
||||
},
|
||||
async getGoalInBLD(roundNumber) {
|
||||
return await this.contract.methods.getGoalInBLD(roundNumber).call();
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+44
-42
@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
||||
import { markRaw } from "vue";
|
||||
import Web3 from "web3";
|
||||
import { useWalletStore } from "./wallet";
|
||||
import { useWalletStoreV2 } from "./walletV2";
|
||||
import { useContractStore } from "./contracts";
|
||||
import { ethers } from "ethers";
|
||||
import { useMemeburnerStore } from "./memeburner";
|
||||
@@ -9,7 +10,7 @@ import Meme1Json from "@/assets/contracts/Meme1.json";
|
||||
import Meme2Json from "@/assets/contracts/Meme2.json";
|
||||
import MemeToken from "@/assets/contracts/MemeToken.json";
|
||||
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
||||
import { multicall } from "@wagmi/core";
|
||||
import { multicall, getContract, fetchToken } from "@wagmi/core";
|
||||
|
||||
|
||||
export const useTokenStore = defineStore("token", {
|
||||
@@ -71,70 +72,71 @@ export const useTokenStore = defineStore("token", {
|
||||
async initV2() {
|
||||
console.log("-----------init token-------------");
|
||||
const contracts = [];
|
||||
const walletStore = useWalletStore();
|
||||
const walletStore = useWalletStoreV2();
|
||||
for (let index = 0; index < this.token.length; index++) {
|
||||
const token = this.token[index];
|
||||
// token.contract = new walletStore.web3.eth.Contract(token.abi, token.contractAddress);
|
||||
token.contract = getContract({
|
||||
address: token.contractAddress,
|
||||
abi: token.abi,
|
||||
publicClient,
|
||||
PublicClient: walletStore.publicClient,
|
||||
WalletClient: walletStore.walletClient
|
||||
});
|
||||
contracts.push({...token.contract, functionName: "decimals"})
|
||||
|
||||
// token.decimals = parseInt(await token.contract.methods.decimals().call());
|
||||
}
|
||||
|
||||
const data = await multicall({
|
||||
contracts
|
||||
});
|
||||
|
||||
console.log("data", data);
|
||||
|
||||
//MemeToken init
|
||||
this.memeToken.contract = new walletStore.web3.eth.Contract(
|
||||
this.memeToken.config.abi,
|
||||
this.memeToken.config.contractAddress
|
||||
);
|
||||
this.memeToken.decimals = parseInt(await this.memeToken.contract.methods.decimals().call());
|
||||
},
|
||||
async init() {
|
||||
console.log("-----------init token-------------");
|
||||
const walletStore = useWalletStore();
|
||||
for (let index = 0; index < this.token.length; index++) {
|
||||
const token = this.token[index];
|
||||
token.contract = new walletStore.web3.eth.Contract(token.abi, token.contractAddress);
|
||||
token.decimals = parseInt(await token.contract.methods.decimals().call());
|
||||
this.memeToken.contract = getContract({
|
||||
address: this.memeToken.config.contractAddress,
|
||||
abi: this.memeToken.config.abi,
|
||||
PublicClient: walletStore.publicClient,
|
||||
WalletClient: walletStore.walletClient,
|
||||
});
|
||||
contracts.push({ ...this.memeToken.contract, functionName: "decimals" });
|
||||
|
||||
|
||||
const data = await multicall({
|
||||
contracts,
|
||||
});
|
||||
//multicall decimal
|
||||
for (let index = 0; index < this.token.length; index++) {
|
||||
const token = this.token[index];
|
||||
token.decimals = data[index].result
|
||||
}
|
||||
|
||||
this.memeToken.decimals = data[this.token.length].result;
|
||||
|
||||
//MemeToken init
|
||||
this.memeToken.contract = new walletStore.web3.eth.Contract(
|
||||
this.memeToken.config.abi,
|
||||
this.memeToken.config.contractAddress
|
||||
);
|
||||
this.memeToken.decimals = parseInt(await this.memeToken.contract.methods.decimals().call());
|
||||
},
|
||||
async changeActiveToken(token) {
|
||||
async changeActiveToken(token) {
|
||||
console.log("changeActiveToken");
|
||||
this.activeToken = token;
|
||||
const web3 = new Web3(window.ethereum);
|
||||
this.contract = new web3.eth.Contract(token.abi, token.contractAddress);
|
||||
const walletStore = useWalletStore();
|
||||
if (walletStore.connected) {
|
||||
// const web3 = new Web3(window.ethereum);
|
||||
// this.contract = new web3.eth.Contract(token.abi, token.contractAddress);
|
||||
const walletStore = useWalletStoreV2();
|
||||
if (walletStore.connected) {
|
||||
//TODO, wenn connected, dann all diese Daten laden?
|
||||
this.activeToken.balance = await walletStore.getTokenBalance(token);
|
||||
this.activeToken.allowance = await this.allowance();
|
||||
}
|
||||
},
|
||||
async allowance() {
|
||||
console.log("allowance");
|
||||
const walletStore = useWalletStore();
|
||||
const walletStore = useWalletStoreV2();
|
||||
const memeBurnerStore = useMemeburnerStore();
|
||||
var allowance = await this.contract.methods
|
||||
.allowance(walletStore.address, memeBurnerStore.config.contractAddress)
|
||||
.call();
|
||||
var decimals = await this.contract.methods.decimals().call();
|
||||
console.log("decimals", decimals);
|
||||
console.log("Math.pow(10, decimals)", Math.pow(10, decimals));
|
||||
allowance = BigInt(allowance / Math.pow(10, decimals));
|
||||
// var allowance = await this.contract.methods
|
||||
// .allowance(walletStore.address, memeBurnerStore.config.contractAddress)
|
||||
// .call();
|
||||
console.log("this.activeToken.contract", this.activeToken.contract);
|
||||
var allowance = await this.activeToken.contract.read.allowance([
|
||||
walletStore.address,
|
||||
memeBurnerStore.config.contractAddress,
|
||||
]);
|
||||
// var decimals = await this.contract.methods.decimals().call();
|
||||
// console.log("decimals", decimals);
|
||||
const decimals = this.activeToken.decimals;
|
||||
|
||||
allowance = BigInt(allowance / BigInt(Math.pow(10, decimals)));
|
||||
return allowance;
|
||||
},
|
||||
async approveToken(amount) {
|
||||
|
||||
+14
-10
@@ -9,7 +9,8 @@ import {
|
||||
getAccount,
|
||||
getContract,
|
||||
connect,
|
||||
getWalletClient,
|
||||
getWalletClient,
|
||||
getPublicClient,
|
||||
disconnect,
|
||||
InjectedConnector,
|
||||
watchAccount,
|
||||
@@ -33,12 +34,12 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
web3: null,
|
||||
provider: null,
|
||||
client: null,
|
||||
pubilcClient: null,
|
||||
publicClient: null,
|
||||
walletClient: null,
|
||||
config: null
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
actions: {
|
||||
async init() {
|
||||
|
||||
console.log("wallet init");
|
||||
@@ -48,8 +49,8 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
const { chains, publicClient, webSocketPublicClient } = configureChains(
|
||||
[goerli],
|
||||
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
this.config = createConfig({
|
||||
autoConnect: true,
|
||||
connectors: [
|
||||
@@ -76,8 +77,9 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
],
|
||||
publicClient,
|
||||
webSocketPublicClient,
|
||||
});
|
||||
|
||||
});
|
||||
this.publicClient = publicClient;
|
||||
this.walletClient = await getWalletClient();
|
||||
// await this.isConnected();
|
||||
// const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||
// if (this.connected) {
|
||||
@@ -121,9 +123,11 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
// this.address = connection.account;
|
||||
},
|
||||
async getTokenBalance(token) {
|
||||
const tokenStore = useTokenStore();
|
||||
const contract = tokenStore.getTokenContract(token);
|
||||
const result = await contract.methods.balanceOf(this.address).call();
|
||||
// const tokenStore = useTokenStore();
|
||||
// const contract = tokenStore.getTokenContract(token);
|
||||
// const result = await contract.methods.balanceOf(this.address).call();
|
||||
console.log("this.address", this.address);
|
||||
const result = await token.contract.read.balanceOf([this.address]);
|
||||
return result;
|
||||
},
|
||||
async isConnected() {
|
||||
|
||||
Reference in New Issue
Block a user