import { Contract } from 'ethers'; import vesterAbi from '../abis/Vester.json'; import { STAKING_ADDRESSES } from '@/configs/configchain'; const chainId = parseInt(import.meta.env.VUE_APP_STAKING_CHAIN); export class Vester { constructor(_chainInstance) { this.bc = _chainInstance; const { vester } = STAKING_ADDRESSES[chainId] this.vesterAddress = vester } async execMethod({provider, method, params}) { this.bc.checkAndChangeChain(chainId, provider); const contract = new Contract(this.vesterAddress, vesterAbi, provider.getSigner()); const tx = await contract[method](...params); await tx.wait(); return tx; } async queryMethod({provider, method, params}) { this.bc.checkAndChangeChain(chainId, provider); // const contract = new Contract(this.vesterAddress, routerAbi, provider.getSigner()); const contract = new Contract(this.vesterAddress, vesterAbi, provider.getSigner()); return contract[method](...params); } /** * 存入EsCEC, 开始转化为CEC * @param {*} amount 需要转化的数量, 单位为wei * @returns */ async deposit(amount) { return this.execMethod({ provider: this.bc.eoaProvider, method: 'deposit', params: [amount] }); } /** * 取回EsCEC, 停止转化为CEC * @returns */ async withdraw() { return this.execMethod({ provider: this.bc.eoaProvider, method: 'withdraw', params: [] }); } /** * 获取当前用户的所有转化完成的CEC * @returns */ async claim() { return this.execMethod({ provider: this.bc.eoaProvider, method: 'claim', params: [] }); } /** * 查询当前用户处于转化状态的EsCEC数量 * 这个数量也是锁定中的CEC数量 */ async queryVested() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'balanceOf', params: [userAddress] }); } /** * 查询当前用户存储的EsCEC数量(转化+未转化) * @returns */ async queryVestedTotal() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'getTotalVested', params: [userAddress] }); } /** * 查询当前用户可以领取的CEC数量 */ async queryClaimable() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'claimable', params: [userAddress] }); } /** * 查询用户已经领取的CEC总量 * @returns */ async queryClaimabledAll() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'claimedAmounts', params: [userAddress] }); } /** * 查询用户剩余未转换的EsCEC数量 * @returns */ async queryRemainingEsCEC() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'remainingEsToken', params: [userAddress] }); } /** * 查询用户最后一次存入时间 * @returns */ async queryLastDepositTime() { const userAddress = await this.bc.eoaProvider.getSigner().getAddress() return this.queryMethod({ provider: this.bc.eoaProvider, method: 'lastDepositTimes', params: [userAddress] }); } }