contracts update
This commit is contained in:
+29
-26
@@ -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]);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user