Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
259ddec9ec | ||
|
|
c160b1c836 | ||
|
|
8ae8f9a64a | ||
|
|
b7a54f2cdd | ||
|
|
650df134d2 | ||
|
|
5157308745 | ||
|
|
0bab85fe75 | ||
|
|
34a445eaa3 | ||
|
|
e200b82697 |
Generated
+14207
-14927
File diff suppressed because it is too large
Load Diff
+34
-39
@@ -1,41 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-ethereum2",
|
"name": "vue-ethereum2",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs --fix --ignore-path .gitignore"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
"@fortawesome/fontawesome-svg-core": "^6.4.0",
|
||||||
"@fortawesome/free-brands-svg-icons": "^6.4.0",
|
"@fortawesome/free-brands-svg-icons": "^6.4.0",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.4.0",
|
"@fortawesome/free-solid-svg-icons": "^6.4.0",
|
||||||
"@fortawesome/vue-fontawesome": "^3.0.3",
|
"@fortawesome/vue-fontawesome": "^3.0.3",
|
||||||
"@wagmi/core": "^1.3.8",
|
"@wagmi/core": "^1.3.8",
|
||||||
"@walletconnect/ethereum-provider": "^2.9.1",
|
"abi-decoder": "^2.4.0",
|
||||||
"@walletconnect/modal": "^2.6.0",
|
"ethers": "^6.6.3",
|
||||||
"@walletconnect/modal-sign-html": "^2.6.0",
|
"pinia": "^2.0.36",
|
||||||
"@web3modal/html": "^2.7.0",
|
"pinia-plugin-persistedstate": "^3.1.0",
|
||||||
"abi-decoder": "^2.4.0",
|
"sass": "^1.62.1",
|
||||||
"ethers": "^6.6.3",
|
"swiper": "^9.4.1",
|
||||||
"pinia": "^2.0.36",
|
"viem": "^1.4.1",
|
||||||
"pinia-plugin-persistedstate": "^3.1.0",
|
"vue": "^3.3.2",
|
||||||
"sass": "^1.62.1",
|
"vue-router": "^4.2.0",
|
||||||
"swiper": "^9.4.1",
|
"web3": "^v1.9.0"
|
||||||
"viem": "^1.4.1",
|
},
|
||||||
"vue": "^3.3.2",
|
"devDependencies": {
|
||||||
"vue-router": "^4.2.0",
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
||||||
"wagmi": "^1.3.9",
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
||||||
"web3": "^v1.9.0"
|
"@vitejs/plugin-vue": "^4.2.3",
|
||||||
},
|
"eslint": "^8.39.0",
|
||||||
"devDependencies": {
|
"eslint-plugin-vue": "^9.11.0",
|
||||||
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
"vite": "^4.3.5"
|
||||||
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
}
|
||||||
"@vitejs/plugin-vue": "^4.2.3",
|
|
||||||
"eslint": "^8.39.0",
|
|
||||||
"eslint-plugin-vue": "^9.11.0",
|
|
||||||
"vite": "^4.3.5"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+64
-13
@@ -4,7 +4,6 @@ import { storeToRefs } from "pinia";
|
|||||||
|
|
||||||
import Navbar from "./components/Navbar.vue";
|
import Navbar from "./components/Navbar.vue";
|
||||||
import { useWalletStoreV2 } from "@/stores/walletV2";
|
import { useWalletStoreV2 } from "@/stores/walletV2";
|
||||||
const walletStore = useWalletStoreV2();
|
|
||||||
import { useTokenStore } from "@/stores/tokens";
|
import { useTokenStore } from "@/stores/tokens";
|
||||||
import { useContractStore } from "@/stores/contracts";
|
import { useContractStore } from "@/stores/contracts";
|
||||||
import { useMemeburnerStore } from "@/stores/memeburner";
|
import { useMemeburnerStore } from "@/stores/memeburner";
|
||||||
@@ -15,7 +14,15 @@ import { useRoundsStore } from "@/stores/rounds";
|
|||||||
import SlideoutPanel from "./components/SlideoutPanel.vue";
|
import SlideoutPanel from "./components/SlideoutPanel.vue";
|
||||||
import ConnectWallet from "./components/ConnectWallet.vue";
|
import ConnectWallet from "./components/ConnectWallet.vue";
|
||||||
|
|
||||||
import { watchAccount, getPublicClient, getWalletClient } from "@wagmi/core";
|
import {
|
||||||
|
watchAccount,
|
||||||
|
watchNetwork,
|
||||||
|
watchContractEvent,
|
||||||
|
getAccount,
|
||||||
|
getNetwork,
|
||||||
|
getPublicClient,
|
||||||
|
getWalletClient,
|
||||||
|
} from "@wagmi/core";
|
||||||
|
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
const contractStore = useContractStore();
|
const contractStore = useContractStore();
|
||||||
@@ -23,17 +30,21 @@ const memeBurnerStore = useMemeburnerStore();
|
|||||||
const rewardLockerStore = useRewardLockerStore();
|
const rewardLockerStore = useRewardLockerStore();
|
||||||
const multiCallStore = useMultiCallStore();
|
const multiCallStore = useMultiCallStore();
|
||||||
const roundsStore = useRoundsStore();
|
const roundsStore = useRoundsStore();
|
||||||
|
const walletStore = useWalletStoreV2();
|
||||||
const { memeBurner, token } = storeToRefs(tokenStore);
|
const { memeBurner, token } = storeToRefs(tokenStore);
|
||||||
const { list } = storeToRefs(contractStore);
|
const { list } = storeToRefs(contractStore);
|
||||||
const isMobile = ref(false);
|
const isMobile = ref(false);
|
||||||
const showPanel = ref(false);
|
const showPanel = ref(false);
|
||||||
const eventWatch = ref(null);
|
const eventWatch = ref(null);
|
||||||
|
const netWorkEvent = ref(null);
|
||||||
|
const memeSacrificedEvent = ref(null);
|
||||||
|
|
||||||
isMobile.value = isMobileFunc();
|
isMobile.value = isMobileFunc();
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
window.removeEventListener("resize", handleWindowSizeChange);
|
window.removeEventListener("resize", handleWindowSizeChange);
|
||||||
|
|
||||||
eventWatch.value();
|
eventWatch.value();
|
||||||
|
netWorkEvent.value();
|
||||||
console.log("unsubscribe");
|
console.log("unsubscribe");
|
||||||
});
|
});
|
||||||
const handleWindowSizeChange = () => {
|
const handleWindowSizeChange = () => {
|
||||||
@@ -60,36 +71,76 @@ onMounted(async () => {
|
|||||||
|
|
||||||
// initContracts
|
// initContracts
|
||||||
await walletStore.init();
|
await walletStore.init();
|
||||||
// await tokenStore.init();
|
await tokenStore.initV2();
|
||||||
// await memeBurnerStore.init();
|
await memeBurnerStore.init();
|
||||||
// await rewardLockerStore.init();
|
await rewardLockerStore.init();
|
||||||
// await memeBurnerStore.init();
|
await memeBurnerStore.init();
|
||||||
// await multiCallStore.init();
|
// await multiCallStore.init();
|
||||||
//Memeburner Contract
|
//Memeburner Contract
|
||||||
|
|
||||||
|
const account = getAccount();
|
||||||
|
|
||||||
|
console.log("account", account);
|
||||||
|
if (account.address) {
|
||||||
|
walletStore.address = account.address;
|
||||||
|
walletStore.connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
//init
|
//init
|
||||||
// roundsStore.currentRound = parseInt(
|
roundsStore.currentRound = parseInt(
|
||||||
// await memeBurnerStore.getCurrentRound()
|
await memeBurnerStore.getCurrentRound()
|
||||||
// );
|
);
|
||||||
// console.log("roundsStore.currentRound", roundsStore.currentRound);
|
console.log("roundsStore.currentRound", roundsStore.currentRound);
|
||||||
// roundsStore.activeRound = roundsStore.currentRound;
|
roundsStore.activeRound = roundsStore.currentRound;
|
||||||
// await roundsStore.fillRound(roundsStore.activeRound);
|
await roundsStore.fillRound(roundsStore.activeRound);
|
||||||
|
|
||||||
//events
|
//events
|
||||||
eventWatch.value = watchAccount(async (account) => {
|
eventWatch.value = watchAccount(async (account) => {
|
||||||
console.log("account123", account);
|
console.log("account123", account);
|
||||||
const publicClient = getPublicClient();
|
const publicClient = getPublicClient();
|
||||||
console.log("publicClient", publicClient);
|
console.log("publicClient", publicClient);
|
||||||
var walletClient = await getWalletClient();
|
|
||||||
|
// {chainId: }
|
||||||
console.log("walletClient", walletClient);
|
console.log("walletClient", walletClient);
|
||||||
if (account.address) {
|
if (account.address) {
|
||||||
walletStore.address = account.address;
|
walletStore.address = account.address;
|
||||||
walletStore.connected = true;
|
walletStore.connected = true;
|
||||||
|
let chainObject = walletStore.chain;
|
||||||
|
if (!walletStore.chain) {
|
||||||
|
const { chain, chains } = getNetwork();
|
||||||
|
chainObject = chain;
|
||||||
|
}
|
||||||
|
var walletClient = await getWalletClient({
|
||||||
|
chainId: chainObject.id,
|
||||||
|
});
|
||||||
|
walletStore.walletClient = walletClient;
|
||||||
|
await memeBurnerStore.init();
|
||||||
} else {
|
} else {
|
||||||
walletStore.address = null;
|
walletStore.address = null;
|
||||||
walletStore.connected = false;
|
walletStore.connected = false;
|
||||||
|
walletStore.walletClient = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
netWorkEvent.value = watchNetwork((network) => {
|
||||||
|
console.log("network123", network);
|
||||||
|
if (network.chain) {
|
||||||
|
walletStore.chain = network.chain;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
memeSacrificedEvent.value = watchContractEvent(
|
||||||
|
{
|
||||||
|
address: memeBurnerStore.config.contractAddress,
|
||||||
|
abi: memeBurnerStore.config.abi,
|
||||||
|
eventName: "MemeSacrificed",
|
||||||
|
},
|
||||||
|
async (log) => {
|
||||||
|
console.log("memeSacrificedEvent", log);
|
||||||
|
const token = log[0].args.sacrificedToken;
|
||||||
|
await roundsStore.updateCurrentRound(token);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<h3>Connect Wallet</h3>
|
<h3>Connect Wallet</h3>
|
||||||
<div class="connectors-wrapper">
|
<div class="connectors-wrapper" v-if="!walletStore.connected">
|
||||||
<div class="connectors-element" v-for="connector in walletStore.connectors" @click="connectWallet(connector)">
|
<div class="connectors-element" v-for="connector in walletStore.config?.connectors" @click="connectWallet(connector)">
|
||||||
<div class="connector-icon">
|
<div class="connector-icon">
|
||||||
<img :src="`/assets/img/connectors/${connector.id}.svg`" :alt="`${connector.name} Logo`">
|
<img :src="`/assets/img/connectors/${connector.id}.svg`" :alt="`${connector.name} Logo`">
|
||||||
</div>
|
</div>
|
||||||
<div class="connector-name">{{ connector.name }}</div>
|
<div class="connector-name">{{ connector.name }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div @click="disconnectWallet">disconnect</div>
|
<div class="btn btn-immortal" v-else @click="disconnectWallet">disconnect</div>
|
||||||
<div @click="getWalletClientTest">getwalletclient</div>
|
|
||||||
<div>Connected: {{ walletStore.connected }}</div>
|
<div>Connected: {{ walletStore.connected }}</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -28,7 +27,6 @@ import {
|
|||||||
disconnect,
|
disconnect,
|
||||||
InjectedConnector,
|
InjectedConnector,
|
||||||
watchAccount,
|
watchAccount,
|
||||||
getWalletClient,
|
|
||||||
} from "@wagmi/core";
|
} from "@wagmi/core";
|
||||||
|
|
||||||
const walletStore = useWalletStoreV2();
|
const walletStore = useWalletStoreV2();
|
||||||
@@ -75,27 +73,15 @@ const instance = getCurrentInstance();
|
|||||||
async function disconnectWallet() {
|
async function disconnectWallet() {
|
||||||
console.log("disconnectWallet");
|
console.log("disconnectWallet");
|
||||||
try {
|
try {
|
||||||
|
instance.parent.emit("update:modelValue", false);
|
||||||
await disconnect();
|
await disconnect();
|
||||||
|
// walletStore.connected = false;
|
||||||
|
// walletStore.address = null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("error", error);
|
console.log("error", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getWalletClientTest() {
|
|
||||||
const walletClient = await getWalletClient();
|
|
||||||
console.log("walletClient", walletClient);
|
|
||||||
const contract = getContract({
|
|
||||||
address: Meme1Json.contractAddress,
|
|
||||||
abi: Meme1Json.abi,
|
|
||||||
walletClient,
|
|
||||||
});
|
|
||||||
const result = await contract.read.totalSupply();
|
|
||||||
console.log("result", result);
|
|
||||||
|
|
||||||
// console.log("obj", obj);
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function connectWallet(connector) {
|
async function connectWallet(connector) {
|
||||||
instance.parent.emit("update:modelValue", false);
|
instance.parent.emit("update:modelValue", false);
|
||||||
await walletStore.connectWallet(toRaw(connector));
|
await walletStore.connectWallet(toRaw(connector));
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ async function getRewardsFor(e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("activeToken.value.decimals", activeToken.value.decimals);
|
console.log("activeToken.value.decimals", activeToken.value.decimals);
|
||||||
const rewardsForResult = await memeburnerStore.getRewardsFor(
|
const rewardsForResult = await memeburnerStore.getRewardFor(
|
||||||
BigInt(e.target.value * Math.pow(10, activeToken.value.decimals))
|
BigInt(e.target.value * Math.pow(10, activeToken.value.decimals))
|
||||||
);
|
);
|
||||||
// var test = await memeburnerStore.getRewardsFor(10000);
|
// var test = await memeburnerStore.getRewardsFor(10000);
|
||||||
@@ -167,7 +167,7 @@ async function getRewardsFor(e) {
|
|||||||
Math.pow(10, tokenStore.memeToken.decimals)
|
Math.pow(10, tokenStore.memeToken.decimals)
|
||||||
);
|
);
|
||||||
output.value =
|
output.value =
|
||||||
rewardsForResult / Math.pow(10, tokenStore.memeToken.decimals);
|
rewardsForResult / BigInt(Math.pow(10, tokenStore.memeToken.decimals));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addTokens(value) {
|
async function addTokens(value) {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ export function getImageUrl(url) {
|
|||||||
export function getPercentage(amount, goal) {
|
export function getPercentage(amount, goal) {
|
||||||
console.log("amount", amount);
|
console.log("amount", amount);
|
||||||
console.log("goal", goal);
|
console.log("goal", goal);
|
||||||
return ((amount / goal) * 100).toFixed(2);
|
|
||||||
|
return ((Number(amount) / Number(goal)) * 100).toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ const router = createRouter({
|
|||||||
name: "Test",
|
name: "Test",
|
||||||
component: () => import("../views/TestView.vue"),
|
component: () => import("../views/TestView.vue"),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/walletconnect",
|
|
||||||
name: "WalletConnect",
|
|
||||||
component: () => import("../views/WalletConnectView.vue"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/wagmi",
|
path: "/wagmi",
|
||||||
name: "Wagmi",
|
name: "Wagmi",
|
||||||
|
|||||||
+66
-54
@@ -3,78 +3,88 @@ import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
|||||||
import { useTokenStore } from "./tokens";
|
import { useTokenStore } from "./tokens";
|
||||||
import { useMultiCallStore } from "./multicall";
|
import { useMultiCallStore } from "./multicall";
|
||||||
import { useWalletStore } from "./wallet";
|
import { useWalletStore } from "./wallet";
|
||||||
|
import { useWalletStoreV2 } from "./walletV2";
|
||||||
import { useRoundsStore } from "@/stores/rounds";
|
import { useRoundsStore } from "@/stores/rounds";
|
||||||
|
|
||||||
|
import { multicall, getContract, fetchToken, waitForTransaction } from "@wagmi/core";
|
||||||
|
|
||||||
|
|
||||||
export const useMemeburnerStore = defineStore("memeburner", {
|
export const useMemeburnerStore = defineStore("memeburner", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
config: MemeBurnerJson,
|
config: MemeBurnerJson,
|
||||||
contract: null,
|
contract: null,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
async init() {
|
async init() {
|
||||||
console.log("-----------init memeburner-------------");
|
console.log("-----------init memeburner-------------");
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
const roundsStore = useRoundsStore();
|
// const roundsStore = useRoundsStore();
|
||||||
|
console.log("walletStore.walletClient", walletStore.walletClient);
|
||||||
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
// this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
||||||
|
this.contract = getContract({
|
||||||
|
address: this.config.contractAddress,
|
||||||
const websocketMemeBurner = new walletStore.web3socket.eth.Contract(
|
abi: this.config.abi,
|
||||||
this.config.abi,
|
walletClient: walletStore.walletClient || walletStore.publicClient,
|
||||||
this.config.contractAddress
|
});
|
||||||
);
|
console.log("this.contract", this.contract);
|
||||||
websocketMemeBurner.events
|
// const websocketMemeBurner = new walletStore.web3socket.eth.Contract(
|
||||||
.MemeSacrificed()
|
// this.config.abi,
|
||||||
.on("data", async (event) => {
|
// this.config.contractAddress
|
||||||
console.log("sacrificedAmount", event.returnValues.sacrificedAmount);
|
// );
|
||||||
console.log("sacrificedToken", event.returnValues.sacrificedToken);
|
// websocketMemeBurner.events
|
||||||
await roundsStore.updateCurrentRound(
|
// .MemeSacrificed()
|
||||||
event.returnValues.sacrificedToken,
|
// .on("data", async (event) => {
|
||||||
event.returnValues.sacrificedAmount
|
// console.log("sacrificedAmount", event.returnValues.sacrificedAmount);
|
||||||
);
|
// console.log("sacrificedToken", event.returnValues.sacrificedToken);
|
||||||
})
|
// await roundsStore.updateCurrentRound(
|
||||||
.on("error", (error) => console.log("MemeSacrificederror", error));
|
// event.returnValues.sacrificedToken,
|
||||||
|
// event.returnValues.sacrificedAmount
|
||||||
|
// );
|
||||||
|
// })
|
||||||
|
// .on("error", (error) => console.log("MemeSacrificederror", error));
|
||||||
},
|
},
|
||||||
async getRewardsFor(amount) {
|
async getRewardFor(amount) {
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
var rewards = await this.contract.methods
|
// var rewards = await this.contract.methods
|
||||||
.getRewardFor(tokenStore.activeToken.contractAddress, amount)
|
// .getRewardFor(tokenStore.activeToken.contractAddress, amount)
|
||||||
.call();
|
// .call();
|
||||||
|
const rewards = await this.contract.read.getRewardFor([tokenStore.activeToken.contractAddress, amount]);
|
||||||
|
console.log("rewards", rewards);
|
||||||
return rewards;
|
return rewards;
|
||||||
},
|
},
|
||||||
async getCurrentRound() {
|
async getCurrentRound() {
|
||||||
return await this.contract.methods.currentRound().call();
|
return await this.contract.read.currentRound();
|
||||||
},
|
},
|
||||||
async getGoal(roundnumber) {
|
async getGoal(roundnumber) {
|
||||||
return await this.contract.methods.rounds(roundnumber).call();
|
return await this.contract.read.rounds([roundnumber]);
|
||||||
},
|
},
|
||||||
//returns participated, amount achieved
|
//returns participated, amount achieved
|
||||||
async getSacrificedMeme(roundnumber, tokenAddress) {
|
async getSacrificedMeme(roundnumber, tokenAddress) {
|
||||||
return await this.contract.methods.getSacrificedMeme(roundnumber, tokenAddress).call();
|
return await this.contract.read.getSacrificedMeme([roundnumber, tokenAddress]);
|
||||||
},
|
},
|
||||||
async getAmountToReachGoal(tokenAddress) {
|
async getAmountToReachGoal(tokenAddress) {
|
||||||
return await this.contract.methods.getAmountToReachGoal(tokenAddress).call();
|
return await this.contract.read.getAmountToReachGoal([tokenAddress]);
|
||||||
},
|
},
|
||||||
async getSacrificedRound(roundnumber) {
|
async getSacrificedRound(roundnumber) {
|
||||||
console.log("getSacrificedRound", roundnumber);
|
console.log("getSacrificedRound", roundnumber);
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
const calls = [];
|
const contracts = [];
|
||||||
// const calls1 = [];
|
|
||||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||||
const token = tokenStore.token[index];
|
const token = tokenStore.token[index];
|
||||||
console.log("token.contractAddress", token.contractAddress);
|
console.log("token.contractAddress", token.contractAddress);
|
||||||
console.log("roundnumber", roundnumber);
|
console.log("roundnumber", roundnumber);
|
||||||
var test = await this.getSacrificedMeme(roundnumber, token.contractAddress);
|
// contracts.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
|
||||||
console.log(token.name, test);
|
contracts.push({ ...this.contract, functionName: "getSacrificedMeme", args: [roundnumber, token.contractAddress] });
|
||||||
calls.push(this.contract.methods.getSacrificedMeme(roundnumber, token.contractAddress));
|
|
||||||
// calls1.push(this.contract.methods.getAmountToReachGoal(token.contractAddress));
|
|
||||||
}
|
}
|
||||||
console.log("this.contract", this.contract);
|
// console.log("this.contract", this.contract);
|
||||||
const multicallStore = useMultiCallStore();
|
// const multicallStore = useMultiCallStore();
|
||||||
return await multicallStore.aggregate(calls);
|
// return await multicallStore.aggregate(calls);
|
||||||
|
const data = await multicall({
|
||||||
|
contracts,
|
||||||
|
});
|
||||||
|
return data;
|
||||||
},
|
},
|
||||||
async sacrificeMeme(amount) {
|
async sacrificeMeme(amount) {
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStore();
|
||||||
@@ -87,20 +97,22 @@ export const useMemeburnerStore = defineStore("memeburner", {
|
|||||||
}
|
}
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals));
|
const amountDecimal = BigInt(amount * Math.pow(10, tokenStore.activeToken.decimals));
|
||||||
var reward = await this.contract.methods
|
console.log("this.contract", this.contract);
|
||||||
.sacrificeMeme(tokenStore.activeToken.contractAddress, amountDecimal)
|
var hash = await this.contract.write
|
||||||
.send({ from: walletStore.address });
|
.sacrificeMeme([tokenStore.activeToken.contractAddress, amountDecimal])
|
||||||
console.log("reward", reward);
|
console.log("hash", hash);
|
||||||
tokenStore.activeToken.allowance = await tokenStore.allowance();
|
const data = await waitForTransaction({
|
||||||
|
hash: hash,
|
||||||
|
});
|
||||||
|
tokenStore.activeToken.allowance = await tokenStore.allowance();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async getGoalInBLD(roundNumber) {
|
async getGoalInBLD(roundNumber) {
|
||||||
return await this.contract.methods.getGoalInBLD(roundNumber).call();
|
return await this.contract.read.getGoalInBLD([roundNumber]);
|
||||||
|
},
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+32
-18
@@ -3,7 +3,10 @@ import RewardLockerJson from "@/assets/contracts/RewardLocker.json";
|
|||||||
import { useTokenStore } from "./tokens";
|
import { useTokenStore } from "./tokens";
|
||||||
import { useMultiCallStore } from "./multicall";
|
import { useMultiCallStore } from "./multicall";
|
||||||
import { useWalletStore } from "./wallet";
|
import { useWalletStore } from "./wallet";
|
||||||
|
import { useWalletStoreV2 } from "./walletV2";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
|
import { multicall, getContract } from "@wagmi/core";
|
||||||
|
|
||||||
|
|
||||||
export const useRewardLockerStore = defineStore("rewardlocker", {
|
export const useRewardLockerStore = defineStore("rewardlocker", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -15,8 +18,13 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
|||||||
actions: {
|
actions: {
|
||||||
async init() {
|
async init() {
|
||||||
console.log("-----------init rewardlocker-------------");
|
console.log("-----------init rewardlocker-------------");
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
this.contract = new walletStore.web3.eth.Contract(this.config.abi, this.config.contractAddress);
|
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
|
* @param {*} walletAddress
|
||||||
@@ -25,37 +33,43 @@ export const useRewardLockerStore = defineStore("rewardlocker", {
|
|||||||
* @returns Rewards for specific token and specific round
|
* @returns Rewards for specific token and specific round
|
||||||
*/
|
*/
|
||||||
async getRewards(walletAddress, roundNumber, tokenAddress) {
|
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) {
|
async getRewardsForAllToken(roundNumber) {
|
||||||
console.log("getRewardsForAllToken");
|
console.log("getRewardsForAllToken");
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
const calls = [];
|
const contracts = [];
|
||||||
for (let index = 0; index < tokenStore.token.length; index++) {
|
for (let index = 0; index < tokenStore.token.length; index++) {
|
||||||
const token = tokenStore.token[index];
|
const token = tokenStore.token[index];
|
||||||
calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
|
// calls.push(this.contract.methods.rewards(walletStore.address, roundNumber, token.contractAddress));
|
||||||
}
|
contracts.push({
|
||||||
const multicallStore = useMultiCallStore();
|
...this.contract,
|
||||||
return await multicallStore.aggregate(calls);
|
functionName: "rewards",
|
||||||
|
args: [walletStore.address, roundNumber, token.contractAddress],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const data = await multicall({
|
||||||
|
contracts,
|
||||||
|
});
|
||||||
|
// const multicallStore = useMultiCallStore();
|
||||||
|
return data
|
||||||
},
|
},
|
||||||
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
|
async getSacrificedTokenCoefficient(roundNumber, sacrificedToken) {
|
||||||
return await this.contract.methods.getSacrificedTokenCoefficient(roundNumber, sacrificedToken).call();
|
return await this.contract.read.getSacrificedTokenCoefficient([roundNumber, sacrificedToken]);
|
||||||
},
|
},
|
||||||
async lastCompletedRound() {
|
async lastCompletedRound() {
|
||||||
return await this.contract.methods.lastCompletedRound().call();
|
return await this.contract.read.lastCompletedRound();
|
||||||
},
|
},
|
||||||
async claim(round) {
|
async claim(round) {
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
// return await this.contract.methods.claim(round).call();
|
// return await this.contract.methods.claim(round).call();
|
||||||
console.log(this.contract.methods.claim(round));
|
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) {
|
async getTotalRewardsOf(address, rounds) {
|
||||||
return await this.contract.methods.getTotalRewardsOf(address, rounds).call();
|
return await this.contract.read.getTotalRewardsOf([address, rounds]);
|
||||||
},
|
},
|
||||||
async stakeToBeSecured(amount, deadline, v, r, s) {
|
|
||||||
return await this.contract.methods.stakeToBeSecured(amount, deadline, v,r,s)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
+27
-24
@@ -3,6 +3,7 @@ import { useMemeburnerStore } from "./memeburner";
|
|||||||
import { useTokenStore } from "./tokens";
|
import { useTokenStore } from "./tokens";
|
||||||
import { useRewardLockerStore } from "./rewardlocker";
|
import { useRewardLockerStore } from "./rewardlocker";
|
||||||
import { useWalletStore } from "./wallet";
|
import { useWalletStore } from "./wallet";
|
||||||
|
import { useWalletStoreV2 } from "./walletV2";
|
||||||
|
|
||||||
|
|
||||||
export const useRoundsStore = defineStore("rounds", {
|
export const useRoundsStore = defineStore("rounds", {
|
||||||
@@ -21,20 +22,20 @@ export const useRoundsStore = defineStore("rounds", {
|
|||||||
async init() {
|
async init() {
|
||||||
//fill initial round
|
//fill initial round
|
||||||
},
|
},
|
||||||
async updateCurrentRound(sacrificedToken, sacrificedAmount) {
|
async updateCurrentRound(sacrificedToken) {
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
const memeBurnerStore = useMemeburnerStore();
|
const memeBurnerStore = useMemeburnerStore();
|
||||||
var data = await memeBurnerStore.getSacrificedRound(this.currentRound)
|
var data = await memeBurnerStore.getSacrificedRound(this.currentRound);
|
||||||
console.log("data123", data);
|
console.log("data123", data);
|
||||||
var tokenIndex = this.rounds[this.currentRound].token.findIndex((tokenData) => tokenData.contractAddress === sacrificedToken);
|
var tokenIndex = this.rounds[this.currentRound].token.findIndex((tokenData) => tokenData.contractAddress === sacrificedToken);
|
||||||
this.rounds[this.currentRound].token[tokenIndex].amount = data[tokenIndex][1];
|
this.rounds[this.currentRound].token[tokenIndex].amount = data[tokenIndex].result[1];
|
||||||
|
|
||||||
},
|
},
|
||||||
async fillRound() {
|
async fillRound() {
|
||||||
console.log("fillRound");
|
console.log("fillRound");
|
||||||
const memeBurnerStore = useMemeburnerStore();
|
const memeBurnerStore = useMemeburnerStore();
|
||||||
const tokenStore = useTokenStore();
|
const tokenStore = useTokenStore();
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
const rewardLockerStore = useRewardLockerStore();
|
const rewardLockerStore = useRewardLockerStore();
|
||||||
|
|
||||||
// if (this.activeRound === this.currentRound) {
|
// if (this.activeRound === this.currentRound) {
|
||||||
@@ -45,16 +46,16 @@ export const useRoundsStore = defineStore("rounds", {
|
|||||||
console.log("vor error");
|
console.log("vor error");
|
||||||
var data = await memeBurnerStore.getSacrificedRound(this.activeRound)
|
var data = await memeBurnerStore.getSacrificedRound(this.activeRound)
|
||||||
let rewardData = null;
|
let rewardData = null;
|
||||||
if (await walletStore.isConnected()) {
|
if (walletStore.connected) {
|
||||||
rewardData = await rewardLockerStore.getRewardsForAllToken(this.activeRound);
|
rewardData = await rewardLockerStore.getRewardsForAllToken(this.activeRound);
|
||||||
}
|
}
|
||||||
console.log("rewardData123", rewardData);
|
console.log("rewardData123", rewardData);
|
||||||
|
|
||||||
var goal = await memeBurnerStore.getGoal(this.activeRound);
|
var goal = await memeBurnerStore.getGoal(this.activeRound);
|
||||||
|
console.log("goal", goal);
|
||||||
var tokenArray = []
|
var tokenArray = []
|
||||||
var rewards_clan = BigInt(0);
|
var rewards_clan = 0
|
||||||
var rewards_sacrifice = BigInt(0);
|
var rewards_sacrifice = 0
|
||||||
for (let index = 0; index < data.length; index++) {
|
for (let index = 0; index < data.length; index++) {
|
||||||
var tokenData = {};
|
var tokenData = {};
|
||||||
const token = tokenStore.token[index];
|
const token = tokenStore.token[index];
|
||||||
@@ -66,31 +67,33 @@ export const useRoundsStore = defineStore("rounds", {
|
|||||||
tokenData.contractAddress = token.contractAddress;
|
tokenData.contractAddress = token.contractAddress;
|
||||||
tokenData.vamplogo = token.vamp.logo;
|
tokenData.vamplogo = token.vamp.logo;
|
||||||
tokenData.vampname = token.vamp.name;
|
tokenData.vampname = token.vamp.name;
|
||||||
tokenData.amount = data[index][1];
|
tokenData.amount = data[index].result[1];
|
||||||
tokenData.getAmountToReachGoal= await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
|
tokenData.getAmountToReachGoal= await memeBurnerStore.getAmountToReachGoal(token.contractAddress);
|
||||||
if (this.currentRound !== this.activeRound && await walletStore.isConnected()) {
|
if (this.currentRound !== this.activeRound && walletStore.connected) {
|
||||||
const clanwin = BigInt((testcoef / 10000 - 1) * rewardData[index]);
|
const clanwin = (Number(testcoef) / 10000 - 1) * Number(rewardData[index].result);
|
||||||
const sacrificeRewards = BigInt(rewardData[index]) - clanwin;
|
const sacrificeRewards = Number(rewardData[index].result) - clanwin;
|
||||||
tokenData.rewards_ges = rewardData[index];
|
|
||||||
tokenData.rewards_clan = clanwin;
|
tokenData.rewards_ges = BigInt(rewardData[index].result);
|
||||||
tokenData.rewards_sacrifice = sacrificeRewards;
|
tokenData.rewards_clan = BigInt(clanwin);
|
||||||
rewards_clan = rewards_clan + BigInt(clanwin / BigInt(Math.pow(10, token.decimals)));
|
tokenData.rewards_sacrifice = BigInt(sacrificeRewards);
|
||||||
|
|
||||||
|
rewards_clan = rewards_clan + (clanwin / Math.pow(10, token.decimals));
|
||||||
rewards_sacrifice =
|
rewards_sacrifice =
|
||||||
rewards_sacrifice + BigInt(sacrificeRewards / BigInt(Math.pow(10, token.decimals)));
|
rewards_sacrifice + sacrificeRewards / Math.pow(10, token.decimals);
|
||||||
}
|
}
|
||||||
tokenArray.push(tokenData);
|
tokenArray.push(tokenData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const goalInBLD = await memeBurnerStore.getGoalInBLD(this.activeRound);
|
const goalInBLD = await memeBurnerStore.getGoalInBLD(this.activeRound);
|
||||||
this.rounds[this.activeRound] = {
|
this.rounds[this.activeRound] = {
|
||||||
goal: goal.goal,
|
goal: goal[0],
|
||||||
goalInBLD: goalInBLD /Math.pow(10, tokenStore.memeToken.decimals),
|
goalInBLD: goalInBLD / BigInt(Math.pow(10, tokenStore.memeToken.decimals)),
|
||||||
expirationTimestamp: goal.expirationTimestamp,
|
expirationTimestamp: goal[1],
|
||||||
rewards_clan: rewards_clan,
|
rewards_clan: BigInt(rewards_clan),
|
||||||
rewards_sacrifice: rewards_sacrifice,
|
rewards_sacrifice: BigInt(rewards_sacrifice),
|
||||||
rewards_total: rewards_clan + rewards_sacrifice,
|
rewards_total: BigInt(rewards_clan + rewards_sacrifice),
|
||||||
token: tokenArray,
|
token: tokenArray,
|
||||||
};
|
};
|
||||||
|
console.log("this.rounds[this.activeRound]", this.rounds[this.activeRound]);
|
||||||
} else {
|
} else {
|
||||||
console.log("round already filled");
|
console.log("round already filled");
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-23
@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
|
|||||||
import { markRaw } from "vue";
|
import { markRaw } from "vue";
|
||||||
import Web3 from "web3";
|
import Web3 from "web3";
|
||||||
import { useWalletStore } from "./wallet";
|
import { useWalletStore } from "./wallet";
|
||||||
|
import { useWalletStoreV2 } from "./walletV2";
|
||||||
import { useContractStore } from "./contracts";
|
import { useContractStore } from "./contracts";
|
||||||
import { ethers } from "ethers";
|
import { ethers } from "ethers";
|
||||||
import { useMemeburnerStore } from "./memeburner";
|
import { useMemeburnerStore } from "./memeburner";
|
||||||
@@ -9,6 +10,8 @@ import Meme1Json from "@/assets/contracts/Meme1.json";
|
|||||||
import Meme2Json from "@/assets/contracts/Meme2.json";
|
import Meme2Json from "@/assets/contracts/Meme2.json";
|
||||||
import MemeToken from "@/assets/contracts/MemeToken.json";
|
import MemeToken from "@/assets/contracts/MemeToken.json";
|
||||||
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
||||||
|
import { multicall, getContract, fetchToken } from "@wagmi/core";
|
||||||
|
|
||||||
|
|
||||||
export const useTokenStore = defineStore("token", {
|
export const useTokenStore = defineStore("token", {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -66,43 +69,74 @@ export const useTokenStore = defineStore("token", {
|
|||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
async init() {
|
async initV2() {
|
||||||
console.log("-----------init token-------------");
|
console.log("-----------init token-------------");
|
||||||
const walletStore = useWalletStore();
|
const contracts = [];
|
||||||
|
const walletStore = useWalletStoreV2();
|
||||||
for (let index = 0; index < this.token.length; index++) {
|
for (let index = 0; index < this.token.length; index++) {
|
||||||
const token = this.token[index];
|
const token = this.token[index];
|
||||||
token.contract = new walletStore.web3.eth.Contract(token.abi, token.contractAddress);
|
token.contract = getContract({
|
||||||
token.decimals = parseInt(await token.contract.methods.decimals().call());
|
address: token.contractAddress,
|
||||||
|
abi: token.abi,
|
||||||
|
WalletClient: walletStore.walletClient || walletStore.publicClient,
|
||||||
|
});
|
||||||
|
contracts.push({...token.contract, functionName: "decimals"})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//MemeToken init
|
//MemeToken init
|
||||||
this.memeToken.contract = new walletStore.web3.eth.Contract(
|
this.memeToken.contract = getContract({
|
||||||
this.memeToken.config.abi,
|
address: this.memeToken.config.contractAddress,
|
||||||
this.memeToken.config.contractAddress
|
abi: this.memeToken.config.abi,
|
||||||
);
|
PublicClient: walletStore.publicClient,
|
||||||
this.memeToken.decimals = parseInt(await this.memeToken.contract.methods.decimals().call());
|
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;
|
||||||
|
|
||||||
},
|
},
|
||||||
async changeActiveToken(token) {
|
async changeActiveToken(token) {
|
||||||
|
console.log("changeActiveToken");
|
||||||
this.activeToken = token;
|
this.activeToken = token;
|
||||||
const web3 = new Web3(window.ethereum);
|
// const web3 = new Web3(window.ethereum);
|
||||||
this.contract = new web3.eth.Contract(token.abi, token.contractAddress);
|
// this.contract = new web3.eth.Contract(token.abi, token.contractAddress);
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
if (walletStore.connected) {
|
if (walletStore.connected) {
|
||||||
|
//TODO, wenn connected, dann all diese Daten laden?
|
||||||
this.activeToken.balance = await walletStore.getTokenBalance(token);
|
this.activeToken.balance = await walletStore.getTokenBalance(token);
|
||||||
this.activeToken.allowance = await this.allowance();
|
this.activeToken.allowance = await this.allowance();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async allowance() {
|
async allowance() {
|
||||||
console.log("allowance");
|
console.log("allowance");
|
||||||
const walletStore = useWalletStore();
|
const walletStore = useWalletStoreV2();
|
||||||
const memeBurnerStore = useMemeburnerStore();
|
const memeBurnerStore = useMemeburnerStore();
|
||||||
var allowance = await this.contract.methods
|
// var allowance = await this.contract.methods
|
||||||
.allowance(walletStore.address, memeBurnerStore.config.contractAddress)
|
// .allowance(walletStore.address, memeBurnerStore.config.contractAddress)
|
||||||
.call();
|
// .call();
|
||||||
var decimals = await this.contract.methods.decimals().call();
|
console.log("this.activeToken.contract", this.activeToken.contract);
|
||||||
console.log("decimals", decimals);
|
var allowance = await this.activeToken.contract.read.allowance([
|
||||||
console.log("Math.pow(10, decimals)", Math.pow(10, decimals));
|
walletStore.address,
|
||||||
allowance = BigInt(allowance / Math.pow(10, decimals));
|
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)));
|
||||||
|
console.log("allowance", allowance);
|
||||||
return allowance;
|
return allowance;
|
||||||
},
|
},
|
||||||
async approveToken(amount) {
|
async approveToken(amount) {
|
||||||
|
|||||||
+49
-46
@@ -9,7 +9,6 @@ import {
|
|||||||
getAccount,
|
getAccount,
|
||||||
getContract,
|
getContract,
|
||||||
connect,
|
connect,
|
||||||
getWalletClient,
|
|
||||||
disconnect,
|
disconnect,
|
||||||
InjectedConnector,
|
InjectedConnector,
|
||||||
watchAccount,
|
watchAccount,
|
||||||
@@ -33,12 +32,13 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
|||||||
web3: null,
|
web3: null,
|
||||||
provider: null,
|
provider: null,
|
||||||
client: null,
|
client: null,
|
||||||
pubilcClient: null,
|
publicClient: null,
|
||||||
walletClient: null,
|
walletClient: null,
|
||||||
config: null
|
config: null,
|
||||||
|
chain: null,
|
||||||
}),
|
}),
|
||||||
getters: {},
|
getters: {},
|
||||||
actions: {
|
actions: {
|
||||||
async init() {
|
async init() {
|
||||||
|
|
||||||
console.log("wallet init");
|
console.log("wallet init");
|
||||||
@@ -48,7 +48,8 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
|||||||
const { chains, publicClient, webSocketPublicClient } = configureChains(
|
const { chains, publicClient, webSocketPublicClient } = configureChains(
|
||||||
[goerli],
|
[goerli],
|
||||||
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
|
[alchemyProvider({ apiKey: goerliKey }), publicProvider()]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
this.config = createConfig({
|
this.config = createConfig({
|
||||||
autoConnect: true,
|
autoConnect: true,
|
||||||
@@ -76,8 +77,8 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
|||||||
],
|
],
|
||||||
publicClient,
|
publicClient,
|
||||||
webSocketPublicClient,
|
webSocketPublicClient,
|
||||||
});
|
});
|
||||||
|
this.publicClient = publicClient;
|
||||||
// await this.isConnected();
|
// await this.isConnected();
|
||||||
// const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
// const goerliKey = import.meta.env.VITE_GOERLI_KEY;
|
||||||
// if (this.connected) {
|
// if (this.connected) {
|
||||||
@@ -121,47 +122,49 @@ export const useWalletStoreV2 = defineStore("walletV2", {
|
|||||||
// this.address = connection.account;
|
// this.address = connection.account;
|
||||||
},
|
},
|
||||||
async getTokenBalance(token) {
|
async getTokenBalance(token) {
|
||||||
const tokenStore = useTokenStore();
|
// const tokenStore = useTokenStore();
|
||||||
const contract = tokenStore.getTokenContract(token);
|
// const contract = tokenStore.getTokenContract(token);
|
||||||
const result = await contract.methods.balanceOf(this.address).call();
|
// 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;
|
return result;
|
||||||
},
|
},
|
||||||
async isConnected() {
|
// async isConnected() {
|
||||||
try {
|
// try {
|
||||||
this.loading = true;
|
// this.loading = true;
|
||||||
if (!window.ethereum) {
|
// if (!window.ethereum) {
|
||||||
console.warn("Metamask not installed"), (this.connected = false);
|
// console.warn("Metamask not installed"), (this.connected = false);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
// const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
||||||
if (accounts.length) {
|
// if (accounts.length) {
|
||||||
this.connected = true;
|
// this.connected = true;
|
||||||
this.address = accounts[0];
|
// this.address = accounts[0];
|
||||||
console.log(`You're connected to: ${accounts[0]}`);
|
// console.log(`You're connected to: ${accounts[0]}`);
|
||||||
// const web3 = new Web3(window.ethereum);
|
// // const web3 = new Web3(window.ethereum);
|
||||||
// const tokenStore = useTokenStore();
|
// // const tokenStore = useTokenStore();
|
||||||
// console.log("tokenStore.activeToken", tokenStore.activeToken);
|
// // console.log("tokenStore.activeToken", tokenStore.activeToken);
|
||||||
// if (tokenStore.activeToken.contractAddress) {
|
// // if (tokenStore.activeToken.contractAddress) {
|
||||||
// tokenStore.activeToken.balance = await this.getTokenBalance(
|
// // tokenStore.activeToken.balance = await this.getTokenBalance(
|
||||||
// tokenStore.activeToken
|
// // tokenStore.activeToken
|
||||||
// );
|
// // );
|
||||||
// tokenStore.activeToken.allowance = await tokenStore.allowance();
|
// // tokenStore.activeToken.allowance = await tokenStore.allowance();
|
||||||
// }
|
// // }
|
||||||
// tokenStore.memeBurner.contract = new web3.eth.Contract(
|
// // tokenStore.memeBurner.contract = new web3.eth.Contract(
|
||||||
// tokenStore.memeBurner.config.abi,
|
// // tokenStore.memeBurner.config.abi,
|
||||||
// tokenStore.memeBurner.config.contractAddress
|
// // tokenStore.memeBurner.config.contractAddress
|
||||||
// );
|
// // );
|
||||||
} else {
|
// } else {
|
||||||
console.log("Metamask is not connected");
|
// console.log("Metamask is not connected");
|
||||||
this.connected = false;
|
// this.connected = false;
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.log("error", error);
|
// console.log("error", error);
|
||||||
} finally {
|
// } finally {
|
||||||
this.loading = false;
|
// this.loading = false;
|
||||||
return this.connected;
|
// return this.connected;
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
persist: true,
|
persist: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
function timeBetweenDates() {
|
function timeBetweenDates() {
|
||||||
const dateEntered = new Date(
|
const dateEntered = new Date(
|
||||||
getCurrentRoundData.value?.expirationTimestamp * 1000
|
Number(getCurrentRoundData.value?.expirationTimestamp) * 1000
|
||||||
);
|
);
|
||||||
|
|
||||||
if (dateEntered) {
|
if (dateEntered) {
|
||||||
@@ -153,7 +153,8 @@ function timeBetweenDates() {
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Sacrifice:</td>
|
<td>Sacrifice:</td>
|
||||||
<td class="divider"></td>
|
<td class="divider"></td>
|
||||||
<td>{{ getCurrentRoundData?.goalInBLD?.toFixed(2) }} $BDL</td>
|
<!-- <td>{{ getCurrentRoundData?.goalInBLD?.toFixed(2) }} $BDL</td> -->
|
||||||
|
<td>{{ getCurrentRoundData?.goalInBLD }} $BDL</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Time left:</td>
|
<td>Time left:</td>
|
||||||
|
|||||||
@@ -1,223 +0,0 @@
|
|||||||
<template>
|
|
||||||
{{ activeWallet }}
|
|
||||||
{{ fromAddressWC }}
|
|
||||||
<div class="connect-overview" v-if="!activeWallet && !fromAddressWC">
|
|
||||||
<div v-for="wallet in wallets">
|
|
||||||
<img :src="wallet.icon" :alt="wallet.name" @click="connectWallet($event, wallet)">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
<button @click="disconnectWallet">disconnect</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref, onMounted } from "vue";
|
|
||||||
import { WalletConnectModalSign } from "@walletconnect/modal-sign-html";
|
|
||||||
import {
|
|
||||||
EthereumProvider,
|
|
||||||
OPTIONAL_EVENTS,
|
|
||||||
REQUIRED_EVENTS,
|
|
||||||
REQUIRED_METHODS,
|
|
||||||
OPTIONAL_METHODS,
|
|
||||||
} from "@walletconnect/ethereum-provider";
|
|
||||||
|
|
||||||
import Web3 from "web3";
|
|
||||||
|
|
||||||
// const modal = new WalletConnectModal({
|
|
||||||
// projectId: "d8e5ecb0353c02e21d4c0867d4473ac5",
|
|
||||||
// chains: ["goerli"],
|
|
||||||
// });
|
|
||||||
|
|
||||||
const activeWallet = ref(null);
|
|
||||||
const fromAddressWC = ref(null);
|
|
||||||
const provider = ref(null);
|
|
||||||
const wallets = [
|
|
||||||
{
|
|
||||||
name: "MetaMask",
|
|
||||||
icon: "https://cdn.iconscout.com/icon/free/png-512/metamask-2728406-2261817.png",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "WalletConnect",
|
|
||||||
icon: "https://time.com/img/icons/wallet-connect.png",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const disableConnectButton = ref(false);
|
|
||||||
// const web3Modal = new WalletConnectModalSign({
|
|
||||||
// projectId,
|
|
||||||
// metadata: {
|
|
||||||
// name: "Bloodline-App",
|
|
||||||
// description: "TODO Bloodline Description",
|
|
||||||
// url: "https://gitea.loseyourip.com/",
|
|
||||||
// icons: ["https://gitea.loseyourip.com/assets/img/vampir.png"],
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
const projectId = "d8e5ecb0353c02e21d4c0867d4473ac5";
|
|
||||||
const showQrModal = true;
|
|
||||||
|
|
||||||
const metadata = {
|
|
||||||
name: "Bloodline-App",
|
|
||||||
description: "TODO Bloodline Description",
|
|
||||||
url: "https://gitea.loseyourip.com/",
|
|
||||||
icons: ["https://gitea.loseyourip.com/assets/img/vampir.png"],
|
|
||||||
};
|
|
||||||
provider.value = await EthereumProvider.init({
|
|
||||||
projectId, // REQUIRED your projectId
|
|
||||||
chains: [1], // chains added to required namespaces
|
|
||||||
optionalChains: [5], // chains added to optional namespaces
|
|
||||||
showQrModal, // REQUIRED set to "true" to use @walletconnect/modal
|
|
||||||
REQUIRED_METHODS, // REQUIRED ethereum methods
|
|
||||||
OPTIONAL_METHODS, // OPTIONAL ethereum methods
|
|
||||||
REQUIRED_EVENTS, // REQUIRED ethereum events
|
|
||||||
OPTIONAL_EVENTS, // OPTIONAL ethereum events
|
|
||||||
// rpcMap, // OPTIONAL rpc urls for each chain
|
|
||||||
metadata, // OPTIONAL metadata of your app
|
|
||||||
// qrModalOptions, // OPTIONAL - `undefined` by default, see https://docs.walletconnect.com/2.0/web3modal/options
|
|
||||||
});
|
|
||||||
console.log("provider.value", provider.value);
|
|
||||||
if (provider.value.accounts.length > 0) {
|
|
||||||
fromAddressWC.value = provider.value.accounts[0];
|
|
||||||
} else {
|
|
||||||
fromAddressWC.value = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function disconnectWallet() {
|
|
||||||
activeWallet.value = null;
|
|
||||||
fromAddressWC.value = null;
|
|
||||||
provider.value.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function connectWallet(event, wallet) {
|
|
||||||
try {
|
|
||||||
disableConnectButton.value = true;
|
|
||||||
if (wallet.name === "MetaMask") {
|
|
||||||
window.ethereum
|
|
||||||
.request({ method: "eth_requestAccounts" })
|
|
||||||
.then((data) => {
|
|
||||||
console.log("data", data);
|
|
||||||
activeWallet.value = { ...wallet, address: data };
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
if (error.code === 4001) {
|
|
||||||
// EIP-1193 userRejectedRequest error
|
|
||||||
console.log("Please connect to MetaMask.");
|
|
||||||
} else {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (wallet.name === "WalletConnect") {
|
|
||||||
const methods = [
|
|
||||||
"eth_signTypedData",
|
|
||||||
"eth_signTypedData_v4",
|
|
||||||
"eth_sign",
|
|
||||||
];
|
|
||||||
const optionalMethods = [];
|
|
||||||
const events = [];
|
|
||||||
|
|
||||||
console.log("OPTIONAL_EVENTS", OPTIONAL_EVENTS);
|
|
||||||
console.log("REQUIRED_EVENTS", REQUIRED_EVENTS);
|
|
||||||
console.log("REQUIRED_METHODS", REQUIRED_METHODS);
|
|
||||||
console.log("OPTIONAL_METHODS", OPTIONAL_METHODS);
|
|
||||||
|
|
||||||
console.log("provider", provider.value);
|
|
||||||
// await provider.value.connect();
|
|
||||||
await provider.value.enable();
|
|
||||||
provider.value.on("accountsChanged", function (account) {
|
|
||||||
console.log("accountschanged", { account });
|
|
||||||
fromAddressWC.value = account;
|
|
||||||
});
|
|
||||||
const result = await provider.value.request({
|
|
||||||
method: "eth_requestAccounts",
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("result", result);
|
|
||||||
fromAddressWC.value = result[0];
|
|
||||||
// const session = await web3Modal.connect({
|
|
||||||
// requiredNamespaces: {
|
|
||||||
// eip155: {
|
|
||||||
// methods: ["eth_sendTransaction", "personal_sign"],
|
|
||||||
// chains: ["eip155:1"],
|
|
||||||
// events: ["chainChanged", "accountsChanged"],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
// console.log("session", session);
|
|
||||||
// const web3 = new Web3(session);
|
|
||||||
// console.log("web3", web3);
|
|
||||||
// try {
|
|
||||||
// // console.log("web3Modal", web3Modal);
|
|
||||||
// // var test = await web3Modal.request({
|
|
||||||
// // method: "eth_requestAccounts",
|
|
||||||
// // });
|
|
||||||
// // console.log("test", test);
|
|
||||||
|
|
||||||
// console.log("getAccounts");
|
|
||||||
// const accounts = await web3.eth.getAccounts();
|
|
||||||
// console.log("Got accounts", accounts);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log("error", error);
|
|
||||||
// }
|
|
||||||
// // MetaMask does not give you all accounts, only the selected account
|
|
||||||
// const fromAddress = session.namespaces.eip155.accounts[0].slice(9);
|
|
||||||
// console.log("Web3 instance is", web3);
|
|
||||||
// try {
|
|
||||||
// var balance = web3.eth.getBalance(fromAddress);
|
|
||||||
// console.log("balance", balance);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log("error", error);
|
|
||||||
// }
|
|
||||||
// // var accounts = await web3.eth.getAccounts();
|
|
||||||
// console.log("accounts", accounts);
|
|
||||||
// var userAccount = accounts[0];
|
|
||||||
// console.log("userAccount", userAccount);
|
|
||||||
// session.on("accountsChanged", (accounts) => {
|
|
||||||
// console.log("ACCOUNTS CHANGED" + accounts[0]);
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
} finally {
|
|
||||||
disableConnectButton.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onConnect() {
|
|
||||||
try {
|
|
||||||
disableConnectButton.value = true;
|
|
||||||
const session = await web3Modal.connect({
|
|
||||||
requiredNamespaces: {
|
|
||||||
eip155: {
|
|
||||||
methods: ["eth_sendTransaction", "personal_sign"],
|
|
||||||
chains: ["eip155:1"],
|
|
||||||
events: ["chainChanged", "accountsChanged"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
console.info(session);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
} finally {
|
|
||||||
disableConnectButton.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function disconnect() {
|
|
||||||
modal.closeModal();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="sass">
|
|
||||||
.connect-overview
|
|
||||||
display: flex
|
|
||||||
div
|
|
||||||
background-color: black
|
|
||||||
width: 100px
|
|
||||||
height: auto
|
|
||||||
img
|
|
||||||
width: 100%
|
|
||||||
height: auto
|
|
||||||
</style>
|
|
||||||
Reference in New Issue
Block a user