489 lines
15 KiB
JavaScript
489 lines
15 KiB
JavaScript
import { defineStore } from "pinia";
|
|
import Web3 from "web3";
|
|
import { useWalletStore } from "./wallet";
|
|
import { useContractStore } from "./contracts";
|
|
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,
|
|
},
|
|
loading: false,
|
|
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();
|
|
this.loading = true;
|
|
var approve = await this.contract.methods
|
|
.approve(this.memeBurner.config.contractAddress, amount)
|
|
.send({ from: walletStore.address });
|
|
console.log("approve", approve);
|
|
this.loading = false;
|
|
return approve;
|
|
},
|
|
async sacrificeToken(amount) {
|
|
try {
|
|
this.loading = true;
|
|
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")
|
|
.send({ from: walletStore.address });
|
|
console.log("reward", reward);
|
|
} catch (error) {
|
|
error.log(error);
|
|
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
async getRewardsFor(amount) {
|
|
const contractsStore = useContractStore();
|
|
var rewards = await contractsStore.list.memeBurnerPublic.methods
|
|
.getRewardFor(this.activeToken.contractAddress, amount)
|
|
.call();
|
|
return rewards
|
|
},
|
|
getTokenContract(token) {
|
|
console.log("token", token);
|
|
const contractAddress = token.contractAddress;
|
|
console.log("contractAddress", 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;
|
|
},
|
|
},
|
|
});
|