This commit is contained in:
yuyongdong 2024-09-11 10:27:25 +08:00
commit cf8d6156df
7 changed files with 63 additions and 32 deletions

View File

@ -30,7 +30,9 @@ export class ERC20 {
return contract.balanceOf(address); return contract.balanceOf(address);
} }
async allowance(provider, tokenAddress, owner, spender) { async allowance(tokenAddress, spender) {
const provider = this.bc.eoaProvider;
const owner = provider.getSigner().getAddress();
const contract = new Contract(tokenAddress, erc20Abi, provider.getSigner()); const contract = new Contract(tokenAddress, erc20Abi, provider.getSigner());
return contract.allowance(owner, spender); return contract.allowance(owner, spender);
} }

View File

@ -55,10 +55,11 @@ export class Vester {
* @returns * @returns
*/ */
async claim() { async claim() {
const userAddress = await this.bc.eoaProvider.getSigner().getAddress()
return this.execMethod({ return this.execMethod({
provider: this.bc.eoaProvider, provider: this.bc.eoaProvider,
method: 'claim', method: 'claim',
params: [] params: [userAddress]
}); });
} }
/** /**
@ -89,10 +90,11 @@ export class Vester {
* 查询当前用户可以领取的CEC数量 * 查询当前用户可以领取的CEC数量
*/ */
async queryClaimable() { async queryClaimable() {
const userAddress = await this.bc.eoaProvider.getSigner().getAddress()
return this.queryMethod({ return this.queryMethod({
provider: this.bc.eoaProvider, provider: this.bc.eoaProvider,
method: 'claimable', method: 'claimable',
params: [] params: [userAddress]
}); });
} }
/** /**

View File

@ -281,3 +281,10 @@ export const parseTradeEvent = (event) => {
} }
return {icon, price, usd, currencyName, amount: amountBn, decimals: currencyData.decimals} return {icon, price, usd, currencyName, amount: amountBn, decimals: currencyData.decimals}
} }
export const queryCECPrice = async() => {
const tokenAddress = '0x111111267109489dc6f350608d5113B10c0C5cd7'
const url = `https://price.api.cx.metamask.io/v2/chains/56/spot-prices?tokenAddresses=${tokenAddress}&vsCurrency=usd&includeMarketData=true`
const res = await fetch(url).then(res => res.json());
return res[tokenAddress].price
}

View File

@ -25,7 +25,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>CEC staking</div> <div>CEC staking</div>
<p>{{ stakingStore.cecInfoData.CecStaked }}</p> <p>{{ priceCalculated(cecInfoData.CecStaked) }}</p>
</div> </div>
</li> </li>
<li> <li>
@ -36,7 +36,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>CEC disarm</div> <div>CEC disarm</div>
<p>{{ stakingStore.cecInfoData.CecDisarm }}</p> <p>{{ priceCalculated(cecInfoData.CecDisarm) }}</p>
</div> </div>
</li> </li>
<li> <li>
@ -47,7 +47,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>CEC collection</div> <div>CEC collection</div>
<p>{{ stakingStore.cecInfoData.CecCollection }}</p> <p>{{ priceCalculated(cecInfoData.CecCollection) }}</p>
</div> </div>
</li> </li>
</div> </div>
@ -60,7 +60,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>esCEC</div> <div>esCEC</div>
<p>{{ stakingStore.cecInfoData.esCecBalance }}</p> <p>{{ priceCalculated(cecInfoData.esCecBalance) }}</p>
</div> </div>
</li> </li>
<li> <li>
@ -71,7 +71,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>esCEC Staking</div> <div>esCEC Staking</div>
<p>{{ stakingStore.cecInfoData.esCecStaked }}</p> <p>{{ priceCalculated(cecInfoData.esCecStaked) }}</p>
</div> </div>
</li> </li>
<li> <li>
@ -82,7 +82,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>esCEC conversion</div> <div>esCEC conversion</div>
<p>{{ stakingStore.cecInfoData.esCecConversion }}</p> <p>{{ priceCalculated(cecInfoData.esCecConversion) }}</p>
</div> </div>
</li> </li>
<li> <li>
@ -93,7 +93,7 @@
</div> </div>
<div class="right"> <div class="right">
<div>esCEC collection</div> <div>esCEC collection</div>
<p>{{ stakingStore.cecInfoData.esCecCollection }}</p> <p>{{ priceCalculated(cecInfoData.esCecCollection) }}</p>
</div> </div>
</li> </li>
</div> </div>
@ -178,15 +178,24 @@ const getCecData = async () => {
// esCecStaked: 0, // esCecStaked: 0,
// esCecConversion: 0, // esCecConversion: 0,
// esCecCollection: 0, // esCecCollection: 0,
let address = localWalletStore.address
if (!address) return
let timer = setInterval( async () => { let timer = setInterval( async () => {
cecInfoData.value.cecBalance = parseInt(await bc.erc20.balanceOf(address)).toString() cecInfoData.value.cecBalance = BigInt(await bc.erc20.balanceOf(address)).toString()
cecInfoData.value.esCecBalance = parseInt(await bc.erc20.esCecBalanceOf(address)).toString() cecInfoData.value.esCecBalance = BigInt(await bc.erc20.esCecBalanceOf(address)).toString()
cecInfoData.value.CecStaked = parseInt(await bc.staking.queryCECStaked()).toString() cecInfoData.value.CecStaked = BigInt(await bc.staking.queryCECStaked()).toString()
cecInfoData.value.esCecStaked = parseInt(await bc.staking.queryEsCECStaked()).toString() cecInfoData.value.esCecStaked = BigInt(await bc.staking.queryEsCECStaked()).toString()
let res = parseInt(await bc.staking.queryClaimableByCEC()) cecInfoData.value.esCecConversion = BigInt(await bc.vester.queryVested()).toString()
// let ClaimableByCEC = await bc.staking.queryCumulativeByCEC() // cec esCec
// let ClaimableByEsCEC = await bc.staking.queryClaimableByEsCEC() cecInfoData.value.CecDisarm = cecInfoData.value.esCecConversion;
console.log(cecInfoData.value.CecStaked,res) try {
cecInfoData.value.CecCollection = await bc.vester.queryClaimable()
const stakeCecCollection = await bc.staking.queryClaimableByCEC()
const stakeEsCecCollection = await bc.staking.queryClaimableByEsCEC()
cecInfoData.value.esCecCollection = (BigInt(stakeCecCollection) + BigInt(stakeEsCecCollection)).toString()
} catch (e) {
console.log('query claimable error', e)
}
clearInterval(timer); clearInterval(timer);
}, 2000); }, 2000);
// let cec = await bc.staking.queryCECStaked() // let cec = await bc.staking.queryCECStaked()

View File

@ -163,14 +163,22 @@ const dialogUnstakeText = ref({
}) })
const unCecStaked = async () => { const unCecStaked = async () => {
console.log(localWalletStore.address, STAKING_ADDRESSES[chainId].stakedCecTracker,stakingStore.cecInfoData.cecBalance) const amount = BigInt(1 * 1e18)
// try{ console.log(localWalletStore.address, STAKING_ADDRESSES[chainId].cec, (1*1e18).toString())
// let res = await bc.erc20.approve(STAKING_ADDRESSES[chainId].stakedCecTracker, STAKING_ADDRESSES[chainId].cec,(1*1e18).toString()) try{
// } catch (e) { let allow = await bc.erc20.allowance(STAKING_ADDRESSES[chainId].cec, STAKING_ADDRESSES[chainId].stakedCecTracker)
// console.log(e) allow = BigInt(allow)
// } if (allow < amount) {
let res = await bc.staking.stakeCec(localWalletStore.address,(1*1e18).toString()) console.log('not enough allowance')
console.log(res) let res = await bc.erc20.approve(STAKING_ADDRESSES[chainId].stakedCecTracker, STAKING_ADDRESSES[chainId].cec, amount)
await res.wait()
}
let res2 = await bc.staking.stakeCec(amount)
console.log(res2)
} catch (e) {
console.log(e)
}
} }
</script> </script>

View File

@ -108,12 +108,12 @@ export const STAKING_ADDRESSES = {
cec: '0xfa1223747bae6d519580c53Cbb9C11a45b13c6b7', cec: '0xfa1223747bae6d519580c53Cbb9C11a45b13c6b7',
esCec: '0x1FbA3F84e62163069050f1156b73C008722136A3', esCec: '0x1FbA3F84e62163069050f1156b73C008722136A3',
vester: '0x41a7f94f0B3b615F84c7084F45556FEf1bd18A18', vester: '0x41a7f94f0B3b615F84c7084F45556FEf1bd18A18',
stakedCecRouter: '0xE9AFdA5939023a7B4104931030a32CFAC99f4af8', stakedCecRouter: '0x576c3D53c6d4A19471E216c06945d41EC39f6014',
stakedCecTracker: '0x18B41FbA9E096bc3E0A1F6aa92617B819Df6A602', stakedCecTracker: '0x7554e677fF63212264db26dc743c67C277f219d2',
stakedCecDistributor: '0xA4f4452b4B91C27B84275ebcfBCca1c277FFA15b', stakedCecDistributor: '0x53153a177F4483b53b3f732Ff63eeB48c6FE89E5',
stakedEsCecRouter: '0x2B656F1c485913577461e06bbf5adC999BC7743B', stakedEsCecRouter: '0x19934736a578527cF725a33201445166Cbb62e52',
stakedEsCecTracker: '0x9679DE719eCe856Fe40E1f68C5ed48b344181035', stakedEsCecTracker: '0x30cd668d0f280C404aD504bFf5d7a3Bf535f2A92',
stakedEsCecDistributor: '0x11440cE5a7d6a1e6fa1e9fd790EBa93476F0DeA0', stakedEsCecDistributor: '0x6Ee091c2c242470f4f6D3d55604e1a66c6FF4ff5',
} }
} }

View File

@ -3,6 +3,9 @@ import { ethers } from "ethers"
// 计算价格精度 // 计算价格精度
export const priceCalculated = (price, decimals=18) => { export const priceCalculated = (price, decimals=18) => {
if (!price) {
return '0.00000'
}
let str = Number(ethers.utils.formatUnits(price, decimals)).toFixed(5) let str = Number(ethers.utils.formatUnits(price, decimals)).toFixed(5)
if(str == '0.00000') { if(str == '0.00000') {
str = '<0.00001' str = '<0.00001'