update menu
This commit is contained in:
@@ -53,8 +53,8 @@ export const useMemeburnerStore = defineStore("memeburner", {
|
||||
console.log("getSacrificedRound", roundnumber);
|
||||
const tokenStore = useTokenStore();
|
||||
const contracts = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
for (let index = 0; index < tokenStore.sacrificeToken.length; index++) {
|
||||
const token = tokenStore.sacrificeToken[index];
|
||||
console.log("token.contractAddress", token.contractAddress);
|
||||
console.log("roundnumber", roundnumber);
|
||||
// contracts.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
|
||||
|
||||
@@ -35,9 +35,9 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
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];
|
||||
const contracts = [];
|
||||
for (let index = 0; index < tokenStore.sacrificeToken.length; index++) {
|
||||
const token = tokenStore.sacrificeToken[index];
|
||||
// calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
|
||||
contracts.push({
|
||||
...this.contract,
|
||||
@@ -68,5 +68,8 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||
async getTotalRewardsOf(address, rounds) {
|
||||
return await this.contract.read.getTotalRewardsOf([address, rounds]);
|
||||
},
|
||||
async getStaked(address) {
|
||||
return await this.contract.read.staked([address]);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -44,6 +44,7 @@ export const useRoundsStore = defineStore("rounds", {
|
||||
console.log("round not filled --> fill round");
|
||||
console.log("vor error");
|
||||
var data = await memeBurnerStore.getSacrificedRound(this.activeRound)
|
||||
console.log("databla", data);
|
||||
let rewardData = null;
|
||||
if (walletStore.connected) {
|
||||
rewardData = await rewardLockerStore.getRewardsForAllToken(this.activeRound);
|
||||
@@ -82,7 +83,9 @@ export const useRoundsStore = defineStore("rounds", {
|
||||
}
|
||||
tokenArray.push(tokenData);
|
||||
}
|
||||
const goalInBLD = await memeBurnerStore.getGoalInBLD(this.activeRound);
|
||||
const goalInBLD = await memeBurnerStore.getGoalInBLD(this.activeRound);
|
||||
console.log("goalInBLD", goalInBLD);
|
||||
console.log("tokenStore.memeToken.decimals", tokenStore.memeToken.decimals);
|
||||
this.rounds[this.activeRound] = {
|
||||
goal: goal[0],
|
||||
goalInBLD: goalInBLD / BigInt(Math.pow(10, tokenStore.memeToken.decimals)),
|
||||
|
||||
+75
-57
@@ -24,7 +24,6 @@ export const useTokenStore = defineStore("token", {
|
||||
backgroundColor: "#4b8501",
|
||||
abi: Meme1Json.abi,
|
||||
contractAddress: Meme1Json.contractAddress,
|
||||
ethcontract: null,
|
||||
},
|
||||
{
|
||||
name: "$SHIB",
|
||||
@@ -37,6 +36,11 @@ export const useTokenStore = defineStore("token", {
|
||||
abi: Meme2Json.abi,
|
||||
contractAddress: Meme2Json.contractAddress,
|
||||
},
|
||||
{
|
||||
abi: MemeToken.abi,
|
||||
contractAddress: MemeToken.contractAddress,
|
||||
logo: "/assets/img/token/bloodline.png",
|
||||
},
|
||||
// {
|
||||
// name: "$ELON",
|
||||
// logo: "/assets/img/token/elon.png",
|
||||
@@ -57,64 +61,79 @@ export const useTokenStore = defineStore("token", {
|
||||
allowance: null,
|
||||
},
|
||||
loading: false,
|
||||
memeToken: {
|
||||
config: {
|
||||
abi: MemeToken.abi,
|
||||
contractAddress: MemeToken.contractAddress,
|
||||
},
|
||||
},
|
||||
// memeToken: getTpelm
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
getters: {
|
||||
memeToken: (state) => state.token.find((obj) => obj.contractAddress === MemeToken.contractAddress),
|
||||
sacrificeToken: (state) => state.token.filter((obj) => obj.contractAddress !== MemeToken.contractAddress),
|
||||
},
|
||||
actions: {
|
||||
getToken(address) {
|
||||
console.log("address", address);
|
||||
const token = this.token.find((obj) => obj.contractAddress === address);
|
||||
return token;
|
||||
},
|
||||
async initV2() {
|
||||
console.log("-----------init token-------------");
|
||||
const contracts = [];
|
||||
const walletStore = useWalletStoreV2();
|
||||
console.log("-----------init token-------------");
|
||||
const walletStore = useWalletStoreV2();
|
||||
for (let index = 0; index < this.token.length; index++) {
|
||||
const token = this.token[index];
|
||||
console.log("token123abc", token);
|
||||
var test = getContract({
|
||||
const contracts = [];
|
||||
const token = this.token[index];
|
||||
console.log("token123abc", token);
|
||||
token.contract = getContract({
|
||||
address: token.contractAddress,
|
||||
abi: token.abi,
|
||||
// walletClient: walletStore.publicClient,
|
||||
});
|
||||
console.log("test", test);
|
||||
console.log("token.contract", token.contract);
|
||||
var decimals = await test.read.decimals();
|
||||
console.log("decimals", decimals);
|
||||
token.contract = test;
|
||||
// contracts.push({...token.contract, functionName: "decimals"})
|
||||
|
||||
}
|
||||
abi: token.abi,
|
||||
walletClient: walletStore.walletClient || walletStore.publicClient,
|
||||
});
|
||||
|
||||
|
||||
//MemeToken init
|
||||
// this.memeToken.contract = getContract({
|
||||
contracts.push({ ...token.contract, functionName: "decimals" });
|
||||
contracts.push({ ...token.contract, functionName: "name" });
|
||||
contracts.push({ ...token.contract, functionName: "symbol" });
|
||||
contracts.push({ ...token.contract, functionName: "totalSupply" });
|
||||
const data = await multicall({
|
||||
contracts,
|
||||
});
|
||||
token.decimals = data[0].result;
|
||||
token.name = data[1].result;
|
||||
token.symbol = data[2].result;
|
||||
token.totalSupply = data[3].result;
|
||||
}
|
||||
|
||||
// MemeToken init
|
||||
// this.memeToken.contract = getContract({
|
||||
// address: this.memeToken.config.contractAddress,
|
||||
// abi: this.memeToken.config.abi,
|
||||
// walletClient: walletStore.walletClient || walletStore.publicClient,
|
||||
// });
|
||||
// contracts.push({ ...this.memeToken.contract, functionName: "decimals" });
|
||||
// const contracts = [];
|
||||
// contracts.push({ ...this.memeToken.contract, functionName: "decimals" });
|
||||
// contracts.push({ ...this.memeToken.contract, functionName: "name" });
|
||||
// contracts.push({ ...this.memeToken.contract, functionName: "symbol" });
|
||||
// contracts.push({ ...this.memeToken.contract, functionName: "totalSupply" });
|
||||
|
||||
// const data = await multicall({
|
||||
// contracts,
|
||||
// });
|
||||
// this.memeToken.decimals = data[0].result;
|
||||
// this.memeToken.name = data[1].result;
|
||||
// this.memeToken.symbol = data[2].result;
|
||||
// this.memeToken.totalSupply = data[3].result;
|
||||
// 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
|
||||
// }
|
||||
// //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;
|
||||
|
||||
// this.memeToken.decimals = data[this.token.length].result;
|
||||
},
|
||||
async changeActiveToken(token) {
|
||||
console.log("changeActiveToken");
|
||||
async changeActiveToken(token) {
|
||||
console.log("changeActiveToken");
|
||||
this.activeToken = token;
|
||||
const walletStore = useWalletStoreV2();
|
||||
if (walletStore.connected) {
|
||||
//TODO, wenn connected, dann all diese Daten laden?
|
||||
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();
|
||||
}
|
||||
@@ -126,17 +145,17 @@ export const useTokenStore = defineStore("token", {
|
||||
// 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([
|
||||
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;
|
||||
const decimals = this.activeToken.decimals;
|
||||
|
||||
allowance = BigInt(allowance / BigInt(Math.pow(10, decimals)));
|
||||
console.log("allowance", allowance);
|
||||
allowance = BigInt(allowance / BigInt(Math.pow(10, decimals)));
|
||||
console.log("allowance", allowance);
|
||||
return allowance;
|
||||
},
|
||||
async approveToken(amount) {
|
||||
@@ -146,25 +165,24 @@ export const useTokenStore = defineStore("token", {
|
||||
// var approve = await this.contract.methods
|
||||
// .approve(memeBurnerStore.config.contractAddress, amount)
|
||||
// .send({ from: walletStore.address});
|
||||
console.log("approve");
|
||||
console.log("approve");
|
||||
var approveHash = await this.activeToken.contract.write.approve([
|
||||
memeBurnerStore.config.contractAddress,
|
||||
amount,
|
||||
]);
|
||||
console.log("approveHash", approvehash);
|
||||
|
||||
const data = await waitForTransaction({
|
||||
hash: approveHash,
|
||||
});
|
||||
return data;
|
||||
});
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
async nonces(userAddress) {
|
||||
return this.memeToken.contract.read.nonces([userAddress])
|
||||
}
|
||||
async nonces(userAddress) {
|
||||
return this.memeToken.contract.read.nonces([userAddress]);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+77
-76
@@ -1,6 +1,8 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { markRaw } from "vue";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import { useRewardLockerStore } from "./rewardlocker";
|
||||
import MemeToken from "@/assets/contracts/MemeToken.json";
|
||||
|
||||
import {
|
||||
createConfig,
|
||||
@@ -11,8 +13,9 @@ import {
|
||||
disconnect,
|
||||
InjectedConnector,
|
||||
watchAccount,
|
||||
getWalletClient,
|
||||
fetchBalance
|
||||
getWalletClient,
|
||||
fetchBalance,
|
||||
multicall,
|
||||
} from "@wagmi/core";
|
||||
|
||||
import { WalletConnectConnector } from "@wagmi/core/connectors/walletConnect";
|
||||
@@ -30,27 +33,29 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
alchemy: null,
|
||||
connected: false,
|
||||
address: null,
|
||||
provider: null,
|
||||
client: null,
|
||||
publicClient: null,
|
||||
walletClient: null,
|
||||
config: null,
|
||||
chain: null,
|
||||
provider: null,
|
||||
client: null,
|
||||
publicClient: null,
|
||||
walletClient: null,
|
||||
config: null,
|
||||
chain: null,
|
||||
token: [],
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async init() {
|
||||
|
||||
console.log("wallet init");
|
||||
const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||
const projectId = "d8e5ecb0353c02e21d4c0867d4473ac5";
|
||||
|
||||
getters: {
|
||||
sacrificeToken: (state) => state.token.filter((obj) => obj.contractAddress !== MemeToken.contractAddress),
|
||||
memeToken: (state) => state.token.find((obj) => obj.contractAddress === MemeToken.contractAddress),
|
||||
},
|
||||
actions: {
|
||||
async init() {
|
||||
console.log("wallet init");
|
||||
const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||
const projectId = "d8e5ecb0353c02e21d4c0867d4473ac5";
|
||||
|
||||
const { chains, publicClient, webSocketPublicClient } = configureChains(
|
||||
[goerli, mainnet],
|
||||
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
this.config = createConfig({
|
||||
autoConnect: true,
|
||||
connectors: [
|
||||
@@ -77,71 +82,67 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
||||
],
|
||||
publicClient,
|
||||
webSocketPublicClient,
|
||||
});
|
||||
this.publicClient = publicClient;
|
||||
|
||||
console.log("this.config", this.config);
|
||||
const walletClient = await getWalletClient();
|
||||
console.log("walletClient", walletClient);
|
||||
});
|
||||
this.publicClient = publicClient;
|
||||
|
||||
console.log("this.config", this.config);
|
||||
const walletClient = await getWalletClient();
|
||||
console.log("walletClient", walletClient);
|
||||
},
|
||||
async connectWallet(connector) {
|
||||
console.log("connector.name", connector.name);
|
||||
// if (!account.isConnected) {
|
||||
const connection = await connect({
|
||||
async connectWallet(connector) {
|
||||
console.log("connector.name", connector.name);
|
||||
// if (!account.isConnected) {
|
||||
const connection = await connect({
|
||||
chainId: goerli.id,
|
||||
connector: connector,
|
||||
});
|
||||
|
||||
console.log("connection", connection);
|
||||
// this.address = connection.account;
|
||||
});
|
||||
|
||||
console.log("connection", connection);
|
||||
// this.address = connection.account;
|
||||
},
|
||||
async getTokenBalance(token) {
|
||||
console.log("token", token);
|
||||
console.log("address", this.address);
|
||||
// const result = await token.contract.read.balanceOf([this.address]);
|
||||
// return result;
|
||||
async getTokenBalance(token) {
|
||||
console.log("token", token);
|
||||
console.log("address", this.address);
|
||||
const result = await token.contract.read.balanceOf([this.address]);
|
||||
return result;
|
||||
},
|
||||
|
||||
async getTokenBalances() {
|
||||
console.log("getTokenBalances");
|
||||
const tokenStore = useTokenStore();
|
||||
console.log("tokenStore.token.length", tokenStore.token.length);
|
||||
var contracts = [];
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
contracts.push({ ...token.contract, functionName: "balanceOf", args: [this.address] });
|
||||
}
|
||||
|
||||
const data = await multicall({
|
||||
contracts,
|
||||
});
|
||||
console.log("data", data);
|
||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||
const token = tokenStore.token[index];
|
||||
const balanceOfDecimal = data[index].result / BigInt(Math.pow(10, token.decimals));
|
||||
this.token.push({
|
||||
contractAddress: token.contractAddress,
|
||||
balanceOf: Number(balanceOfDecimal),
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async getTokenBalances() {
|
||||
//todo
|
||||
async loadWalletData() {
|
||||
const rewardlockerStore = useRewardLockerStore();
|
||||
|
||||
await this.getTokenBalances();
|
||||
|
||||
//MemeToken Staked
|
||||
const tokenStore = useTokenStore();
|
||||
|
||||
const staked = await rewardlockerStore.getStaked(this.address);
|
||||
|
||||
this.memeToken.staked = Number(staked / BigInt(Math.pow(10, tokenStore.memeToken.decimals)));
|
||||
|
||||
}
|
||||
// async isConnected() {
|
||||
// try {
|
||||
// this.loading = true;
|
||||
// if (!window.ethereum) {
|
||||
// console.warn("Metamask not installed"), (this.connected = false);
|
||||
// return;
|
||||
// }
|
||||
// const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
||||
// if (accounts.length) {
|
||||
// this.connected = true;
|
||||
// this.address = accounts[0];
|
||||
// console.log(`You're connected to: ${accounts[0]}`);
|
||||
// // const web3 = new Web3(window.ethereum);
|
||||
// // const tokenStore = useTokenStore();
|
||||
// // console.log("tokenStore.activeToken", tokenStore.activeToken);
|
||||
// // if (tokenStore.activeToken.contractAddress) {
|
||||
// // tokenStore.activeToken.balance = await this.getTokenBalance(
|
||||
// // tokenStore.activeToken
|
||||
// // );
|
||||
// // tokenStore.activeToken.allowance = await tokenStore.allowance();
|
||||
// // }
|
||||
// // tokenStore.memeBurner.contract = new web3.eth.Contract(
|
||||
// // tokenStore.memeBurner.config.abi,
|
||||
// // tokenStore.memeBurner.config.contractAddress
|
||||
// // );
|
||||
// } else {
|
||||
// console.log("Metamask is not connected");
|
||||
// this.connected = false;
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.log("error", error);
|
||||
// } finally {
|
||||
// this.loading = false;
|
||||
// return this.connected;
|
||||
// }
|
||||
// },
|
||||
},
|
||||
persist: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user