initial commit
This commit is contained in:
@@ -0,0 +1,467 @@
|
||||
import { defineStore } from "pinia";
|
||||
import Web3 from "web3";
|
||||
import { useWalletStore } from "./wallet";
|
||||
import Meme1Json from "@/assets/contracts/Meme1.json";
|
||||
import Meme2Json from "@/assets/contracts/Meme2.json";
|
||||
import MemeBurnerJson from "@/assets/contracts/MemeBurner.json";
|
||||
|
||||
export const useTokenStore = defineStore("token", {
|
||||
state: () => ({
|
||||
token: [
|
||||
// {
|
||||
// name: "PEPE",
|
||||
// contractAddress: "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
|
||||
// abi: [
|
||||
// {
|
||||
// inputs: [{ internalType: "uint256", name: "_totalSupply", type: "uint256" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "constructor",
|
||||
// },
|
||||
// {
|
||||
// anonymous: false,
|
||||
// inputs: [
|
||||
// { indexed: true, internalType: "address", name: "owner", type: "address" },
|
||||
// { indexed: true, internalType: "address", name: "spender", type: "address" },
|
||||
// { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
|
||||
// ],
|
||||
// name: "Approval",
|
||||
// type: "event",
|
||||
// },
|
||||
// {
|
||||
// anonymous: false,
|
||||
// inputs: [
|
||||
// { indexed: true, internalType: "address", name: "previousOwner", type: "address" },
|
||||
// { indexed: true, internalType: "address", name: "newOwner", type: "address" },
|
||||
// ],
|
||||
// name: "OwnershipTransferred",
|
||||
// type: "event",
|
||||
// },
|
||||
// {
|
||||
// anonymous: false,
|
||||
// inputs: [
|
||||
// { indexed: true, internalType: "address", name: "from", type: "address" },
|
||||
// { indexed: true, internalType: "address", name: "to", type: "address" },
|
||||
// { indexed: false, internalType: "uint256", name: "value", type: "uint256" },
|
||||
// ],
|
||||
// name: "Transfer",
|
||||
// type: "event",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "owner", type: "address" },
|
||||
// { internalType: "address", name: "spender", type: "address" },
|
||||
// ],
|
||||
// name: "allowance",
|
||||
// outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "spender", type: "address" },
|
||||
// { internalType: "uint256", name: "amount", type: "uint256" },
|
||||
// ],
|
||||
// name: "approve",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [{ internalType: "address", name: "account", type: "address" }],
|
||||
// name: "balanceOf",
|
||||
// outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "_address", type: "address" },
|
||||
// { internalType: "bool", name: "_isBlacklisting", type: "bool" },
|
||||
// ],
|
||||
// name: "blacklist",
|
||||
// outputs: [],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [{ internalType: "address", name: "", type: "address" }],
|
||||
// name: "blacklists",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [{ internalType: "uint256", name: "value", type: "uint256" }],
|
||||
// name: "burn",
|
||||
// outputs: [],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "decimals",
|
||||
// outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "spender", type: "address" },
|
||||
// { internalType: "uint256", name: "subtractedValue", type: "uint256" },
|
||||
// ],
|
||||
// name: "decreaseAllowance",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "spender", type: "address" },
|
||||
// { internalType: "uint256", name: "addedValue", type: "uint256" },
|
||||
// ],
|
||||
// name: "increaseAllowance",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "limited",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "maxHoldingAmount",
|
||||
// outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "minHoldingAmount",
|
||||
// outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "name",
|
||||
// outputs: [{ internalType: "string", name: "", type: "string" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "owner",
|
||||
// outputs: [{ internalType: "address", name: "", type: "address" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "renounceOwnership",
|
||||
// outputs: [],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "bool", name: "_limited", type: "bool" },
|
||||
// { internalType: "address", name: "_uniswapV2Pair", type: "address" },
|
||||
// { internalType: "uint256", name: "_maxHoldingAmount", type: "uint256" },
|
||||
// { internalType: "uint256", name: "_minHoldingAmount", type: "uint256" },
|
||||
// ],
|
||||
// name: "setRule",
|
||||
// outputs: [],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "symbol",
|
||||
// outputs: [{ internalType: "string", name: "", type: "string" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "totalSupply",
|
||||
// outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "recipient", type: "address" },
|
||||
// { internalType: "uint256", name: "amount", type: "uint256" },
|
||||
// ],
|
||||
// name: "transfer",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { internalType: "address", name: "sender", type: "address" },
|
||||
// { internalType: "address", name: "recipient", type: "address" },
|
||||
// { internalType: "uint256", name: "amount", type: "uint256" },
|
||||
// ],
|
||||
// name: "transferFrom",
|
||||
// outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
|
||||
// name: "transferOwnership",
|
||||
// outputs: [],
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [],
|
||||
// name: "uniswapV2Pair",
|
||||
// outputs: [{ internalType: "address", name: "", type: "address" }],
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// name: "SHIBA INU",
|
||||
// contractAddress: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
|
||||
// abi: [
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [],
|
||||
// name: "name",
|
||||
// outputs: [{ name: "", type: "string" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [
|
||||
// { name: "spender", type: "address" },
|
||||
// { name: "value", type: "uint256" },
|
||||
// ],
|
||||
// name: "approve",
|
||||
// outputs: [{ name: "", type: "bool" }],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [],
|
||||
// name: "totalSupply",
|
||||
// outputs: [{ name: "", type: "uint256" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [
|
||||
// { name: "sender", type: "address" },
|
||||
// { name: "recipient", type: "address" },
|
||||
// { name: "amount", type: "uint256" },
|
||||
// ],
|
||||
// name: "transferFrom",
|
||||
// outputs: [{ name: "", type: "bool" }],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [],
|
||||
// name: "decimals",
|
||||
// outputs: [{ name: "", type: "uint8" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [
|
||||
// { name: "spender", type: "address" },
|
||||
// { name: "addedValue", type: "uint256" },
|
||||
// ],
|
||||
// name: "increaseAllowance",
|
||||
// outputs: [{ name: "", type: "bool" }],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [{ name: "value", type: "uint256" }],
|
||||
// name: "burn",
|
||||
// outputs: [],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [{ name: "account", type: "address" }],
|
||||
// name: "balanceOf",
|
||||
// outputs: [{ name: "", type: "uint256" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [],
|
||||
// name: "symbol",
|
||||
// outputs: [{ name: "", type: "string" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [
|
||||
// { name: "spender", type: "address" },
|
||||
// { name: "subtractedValue", type: "uint256" },
|
||||
// ],
|
||||
// name: "decreaseAllowance",
|
||||
// outputs: [{ name: "", type: "bool" }],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: false,
|
||||
// inputs: [
|
||||
// { name: "recipient", type: "address" },
|
||||
// { name: "amount", type: "uint256" },
|
||||
// ],
|
||||
// name: "transfer",
|
||||
// outputs: [{ name: "", type: "bool" }],
|
||||
// payable: false,
|
||||
// stateMutability: "nonpayable",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// constant: true,
|
||||
// inputs: [
|
||||
// { name: "owner", type: "address" },
|
||||
// { name: "spender", type: "address" },
|
||||
// ],
|
||||
// name: "allowance",
|
||||
// outputs: [{ name: "", type: "uint256" }],
|
||||
// payable: false,
|
||||
// stateMutability: "view",
|
||||
// type: "function",
|
||||
// },
|
||||
// {
|
||||
// inputs: [
|
||||
// { name: "name", type: "string" },
|
||||
// { name: "symbol", type: "string" },
|
||||
// { name: "decimals", type: "uint8" },
|
||||
// { name: "totalSupply", type: "uint256" },
|
||||
// { name: "feeReceiver", type: "address" },
|
||||
// { name: "tokenOwnerAddress", type: "address" },
|
||||
// ],
|
||||
// payable: true,
|
||||
// stateMutability: "payable",
|
||||
// type: "constructor",
|
||||
// },
|
||||
// {
|
||||
// anonymous: false,
|
||||
// inputs: [
|
||||
// { indexed: true, name: "from", type: "address" },
|
||||
// { indexed: true, name: "to", type: "address" },
|
||||
// { indexed: false, name: "value", type: "uint256" },
|
||||
// ],
|
||||
// name: "Transfer",
|
||||
// type: "event",
|
||||
// },
|
||||
// {
|
||||
// anonymous: false,
|
||||
// inputs: [
|
||||
// { indexed: true, name: "owner", type: "address" },
|
||||
// { indexed: true, name: "spender", type: "address" },
|
||||
// { indexed: false, name: "value", type: "uint256" },
|
||||
// ],
|
||||
// name: "Approval",
|
||||
// type: "event",
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
{
|
||||
name: "Meme1",
|
||||
abi: Meme1Json.abi,
|
||||
contractAddress: Meme1Json.contractAddress,
|
||||
},
|
||||
{
|
||||
name: "Meme2",
|
||||
abi: Meme2Json.abi,
|
||||
contractAddress: Meme2Json.contractAddress,
|
||||
},
|
||||
],
|
||||
activeToken: {
|
||||
address: null,
|
||||
abi: null,
|
||||
balance: null,
|
||||
contract: null,
|
||||
allowance: null
|
||||
},
|
||||
memeBurner: {
|
||||
config: MemeBurnerJson,
|
||||
contract: null
|
||||
}
|
||||
}),
|
||||
getters: {},
|
||||
actions: {
|
||||
async changeActiveToken(token) {
|
||||
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) {
|
||||
this.activeToken.balance = await walletStore.getTokenBalance(token);
|
||||
this.activeToken.allowance = await this.allowance();
|
||||
|
||||
}
|
||||
},
|
||||
async allowance() {
|
||||
const walletStore = useWalletStore();
|
||||
console.log("walletStore.address", walletStore.address);
|
||||
const allowance = await this.contract.methods.allowance(walletStore.address, MemeBurnerJson.contractAddress).call();
|
||||
console.log("allowance", allowance);
|
||||
return allowance;
|
||||
},
|
||||
async approveToken(amount) {
|
||||
const walletStore = useWalletStore();
|
||||
var approve = await this.contract.methods
|
||||
.approve(this.memeBurner.config.contractAddress, amount)
|
||||
.send({ from: walletStore.address });
|
||||
console.log("approve", approve);
|
||||
console.log("this.contract", this.contract);
|
||||
},
|
||||
async sacrificeToken(amount) {
|
||||
console.log("this.activeToken.", this.activeToken.contractAddress);
|
||||
const walletStore = useWalletStore();
|
||||
console.log("walletStore.address", walletStore.address);
|
||||
var reward = await this.memeBurner.contract.methods
|
||||
.sacrificeMeme(this.activeToken.contractAddress, "400000000000000000")
|
||||
.call({ from: walletStore.address });
|
||||
console.log("reward", reward);
|
||||
},
|
||||
getTokenContract(token) {
|
||||
const contractAddress = token.contractAddress;
|
||||
const activeToken = this.token.find((obj) => obj.contractAddress === contractAddress);
|
||||
console.log("activeToken", activeToken);
|
||||
const web3 = new Web3(window.ethereum);
|
||||
const contract = new web3.eth.Contract(activeToken.abi, contractAddress);
|
||||
return contract;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useTokenStore } from "./tokens";
|
||||
import Web3 from "web3";
|
||||
export const useWalletStore = defineStore("wallet", {
|
||||
state: () => ({
|
||||
count: 0,
|
||||
alchemy: null,
|
||||
connected: false,
|
||||
address: null,
|
||||
}),
|
||||
getters: {
|
||||
double: (state) => state.count * 2,
|
||||
},
|
||||
actions: {
|
||||
increment() {
|
||||
this.count++;
|
||||
},
|
||||
async disconnectWallet() {
|
||||
// const permissions = await window.ethereum.request({
|
||||
// method: 'wallet_requestPermissions',
|
||||
// params: [{
|
||||
// eth_accounts: {},
|
||||
// }]
|
||||
// });
|
||||
// console.log("permissions", permissions);
|
||||
this.connected = false;
|
||||
this.address = null;
|
||||
},
|
||||
connectWallet() {
|
||||
console.log("window.ethereum", window.ethereum);
|
||||
// if (window.ethereum) {
|
||||
window.ethereum
|
||||
.request({ method: "eth_requestAccounts" })
|
||||
.then((data) => {
|
||||
console.log("data", data);
|
||||
this.address = data[0];
|
||||
this.connected = true;
|
||||
const tokenStore = useTokenStore();
|
||||
if (tokenStore.activeToken.address) {
|
||||
//Token selected but not refreshed
|
||||
this.getTokenBalance(tokenStore.activeToken.address).then(
|
||||
(data) => (tokenStore.activeToken.balance = data)
|
||||
);
|
||||
}
|
||||
// console.log("permissions", permissions);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.code === 4001) {
|
||||
// EIP-1193 userRejectedRequest error
|
||||
console.log("Please connect to MetaMask.");
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
// }
|
||||
},
|
||||
async getTokenBalance(token) {
|
||||
const tokenStore = useTokenStore();
|
||||
const contract = tokenStore.getTokenContract(token);
|
||||
const result = await contract.methods.balanceOf(this.address).call();
|
||||
return result;
|
||||
},
|
||||
async isConnected() {
|
||||
try {
|
||||
const accounts = await window.ethereum.request({ method: "eth_accounts" });
|
||||
if (accounts.length) {
|
||||
this.connected = true;
|
||||
|
||||
console.log(`You're connected to: ${accounts[0]}`);
|
||||
const web3 = new Web3(window.ethereum);
|
||||
const tokenStore = useTokenStore();
|
||||
tokenStore.memeBurner.contract = new web3.eth.Contract(
|
||||
tokenStore.memeBurner.config.abi,
|
||||
tokenStore.memeBurner.config.contractAddress
|
||||
);
|
||||
} else {
|
||||
this.disconnectWallet();
|
||||
console.log("Metamask is not connected");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
persist: true,
|
||||
});
|
||||
Reference in New Issue
Block a user