const serverUrl = "https://5bhp1j2cqjqo.usemoralis.com:2053/server"; const appId = "7fSE8n3CXiA4ompkoLUS4mlpX3FJ5mjSKmrL1kM2"; const DECIMALS = 5; const contractAddress = "0x536F523911E49BCb7a774C3C32E4759A54a8298D"; const pairAddress = "0x4e5478348adcb526313e2382a2e04f8ed0e04d4f"; var userAddress; var ethers; var mainContract; var days = 1; let sharedValues = { price: 0, yourBalance: 0, apy: 383025.8 } Moralis.start({ serverUrl, appId }); function linkButtons() { document.getElementById("walletCircle").onclick = loginManual; document.getElementById("copyToken").onclick = copyToken; document.getElementById("copyPair").onclick = copyPair; document.getElementById("btn_docs").onclick = goToPage; document.getElementById("btn_account").onclick = enterAccount; document.getElementById("btn_menu").onclick = enterHomepage; document.getElementById("btn_calc").onclick = enterCalculator; } function copyToken() { document.getElementById("tokenClipboard").style = "visibility: hidden"; document.getElementById("tokenTick").style = "visibility: visible"; setTimeout(function(){ document.getElementById("tokenClipboard").style = "visibility: visible"; document.getElementById("tokenTick").style = "visibility: hidden"; }, 500); navigator.clipboard.writeText(contractAddress); } function copyPair() { document.getElementById("pairClipboard").style = "visibility: hidden"; document.getElementById("pairTick").style = "visibility: visible"; setTimeout(function(){ document.getElementById("pairClipboard").style = "visibility: visible"; document.getElementById("pairTick").style = "visibility: hidden"; }, 500); navigator.clipboard.writeText(pairAddress); } function goToPage() { window.open( "https://docs.demeterfi.farm", "_blank"); } function goToDiscord() { window.open( "https://discord.gg/cTf9gxtZ", "_blank"); } function beautifyAddress(address, first) { return address.slice(0, first)+"..."+address.slice(-3); } function updateUserAddress(ethAddress) { userAddress = ethAddress; document.getElementById("usersWallet").innerHTML = beautifyAddress(ethAddress,5); // beautifyAddress(ethAddress,5); } async function loginManual() { await logOut(); await login(); } async function login() { provider = await Moralis.enableWeb3(); ethers = Moralis.web3Library; const newChainId = "0xa86a"; //AVAX Mainnet await Moralis.switchNetwork(newChainId); let user = Moralis.User.current(); if (!user) { user = await Moralis.Web3.authenticate({signingMessage: "Requesting permission to read account balances"}); } updateUserAddress(user.attributes.ethAddress); getStats(); } async function logOut() { await Moralis.User.logOut(); console.log("logged out"); } async function getStats() { var contract = await new ethers.Contract(contractAddress, abi, provider); let circulatingSupply = await contract.getCirculatingSupply(); let pairContract = await new ethers.Contract(pairAddress, pairABI, provider); let LPReserves = await pairContract.getReserves(); let avaxReserves = LPReserves['_reserve0']; let tokenReserves = LPReserves['_reserve1']; console.log("avaxReserves: "+avaxReserves+" token: "+tokenReserves); var price = avaxReserves/tokenReserves*70; console.log("price: "+avaxReserves/tokenReserves*70); let treasuryReceiver = await contract.treasuryReceiver(); let treasuryBalance = await contract.balanceOf(treasuryReceiver); let valueOfTreasury = treasuryBalance*price.usdPrice; let marketCap = circulatingSupply/(10**5)*price.usdPrice; let firePit = await contract.firePit(); let firePitBalance = await contract.balanceOf(firePit); let valueOfFirePit = firePitBalance*price.usdPrice; let pair = await contract.pair(); const lpOptions = { pair_address: pair, chain: "avalanche", }; sharedValues['price'] = price.toFixed(2); updateFrontend( circulatingSupply/(10**5), valueOfTreasury/(10**5), marketCap, firePitBalance/(10**5), valueOfFirePit/(10**5), (firePitBalance/circulatingSupply*100).toFixed(2), (avaxReserves/(10**18)*70).toFixed(0) ); setupCountdown(); updateCalcFrontend() } function getPriceAVAX() { } function setupCountdown() { var coeff = 1000 * 60 * 15; var countDownDate = new Date(); countDownDate = new Date(Math.round(countDownDate.getTime() / coeff) * coeff+coeff) var x = setInterval(function() { // Get today's date and time var now = new Date().getTime(); // Find the distance between now and the count down date var distance = countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Display the result in the element with id="demo" rebaseElements = document.getElementsByClassName("rebaseCountdown"); console.log("rebase"+rebaseElements) for(var i=0; i