diff --git a/src/components/chain/contract/ERC20.js b/src/components/chain/contract/ERC20.js index 7b2ca38..a159937 100644 --- a/src/components/chain/contract/ERC20.js +++ b/src/components/chain/contract/ERC20.js @@ -30,7 +30,9 @@ export class ERC20 { 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()); return contract.allowance(owner, spender); } diff --git a/src/components/staking/header.vue b/src/components/staking/header.vue index 8e242d9..004feff 100644 --- a/src/components/staking/header.vue +++ b/src/components/staking/header.vue @@ -176,6 +176,7 @@ const getCecData = async () => { // esCecConversion: 0, // esCecCollection: 0, let address = localWalletStore.address + if (!address) return let timer = setInterval( async () => { cecInfoData.value.cecBalance = parseInt(await bc.erc20.balanceOf(address)).toString() cecInfoData.value.esCecBalance = parseInt(await bc.erc20.esCecBalanceOf(address)).toString() diff --git a/src/components/staking/index.vue b/src/components/staking/index.vue index d726db3..b856cce 100644 --- a/src/components/staking/index.vue +++ b/src/components/staking/index.vue @@ -162,14 +162,22 @@ const dialogUnstakeText = ref({ }) const unCecStaked = async () => { - console.log(localWalletStore.address, STAKING_ADDRESSES[chainId].stakedCecTracker,(1*1e18).toString()) - // try{ - // let res = await bc.erc20.approve(localWalletStore.address, STAKING_ADDRESSES[chainId].stakedCecTracker,(1*1e18).toString()) - // } catch (e) { - // console.log(e) - // } - let res = await bc.staking.stakeCec((1*1e18).toString()) - console.log(res) + const amount = BigInt(1 * 1e18) + console.log(localWalletStore.address, STAKING_ADDRESSES[chainId].cec, (1*1e18).toString()) + try{ + let allow = await bc.erc20.allowance(STAKING_ADDRESSES[chainId].cec, STAKING_ADDRESSES[chainId].stakedCecTracker) + allow = BigInt(allow) + if (allow < amount) { + console.log('not enough allowance') + 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) + } + } diff --git a/src/configs/configchain.js b/src/configs/configchain.js index b5c7a38..2b6e09e 100644 --- a/src/configs/configchain.js +++ b/src/configs/configchain.js @@ -108,12 +108,12 @@ export const STAKING_ADDRESSES = { cec: '0xfa1223747bae6d519580c53Cbb9C11a45b13c6b7', esCec: '0x1FbA3F84e62163069050f1156b73C008722136A3', vester: '0x41a7f94f0B3b615F84c7084F45556FEf1bd18A18', - stakedCecRouter: '0xE9AFdA5939023a7B4104931030a32CFAC99f4af8', - stakedCecTracker: '0x18B41FbA9E096bc3E0A1F6aa92617B819Df6A602', - stakedCecDistributor: '0xA4f4452b4B91C27B84275ebcfBCca1c277FFA15b', - stakedEsCecRouter: '0x2B656F1c485913577461e06bbf5adC999BC7743B', - stakedEsCecTracker: '0x9679DE719eCe856Fe40E1f68C5ed48b344181035', - stakedEsCecDistributor: '0x11440cE5a7d6a1e6fa1e9fd790EBa93476F0DeA0', + stakedCecRouter: '0x576c3D53c6d4A19471E216c06945d41EC39f6014', + stakedCecTracker: '0x7554e677fF63212264db26dc743c67C277f219d2', + stakedCecDistributor: '0x53153a177F4483b53b3f732Ff63eeB48c6FE89E5', + stakedEsCecRouter: '0x19934736a578527cF725a33201445166Cbb62e52', + stakedEsCecTracker: '0x30cd668d0f280C404aD504bFf5d7a3Bf535f2A92', + stakedEsCecDistributor: '0x6Ee091c2c242470f4f6D3d55604e1a66c6FF4ff5', } }