From 14c7e28f45400ba83a16dbab5dc063e299e66c09 Mon Sep 17 00:00:00 2001 From: zkswapFinance Date: Thu, 21 Sep 2023 11:25:15 +0700 Subject: [PATCH 1/4] update fee rate --- src/adaptors/zkswap-finance/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adaptors/zkswap-finance/index.js b/src/adaptors/zkswap-finance/index.js index a4623e72d3..d3407cc1fa 100644 --- a/src/adaptors/zkswap-finance/index.js +++ b/src/adaptors/zkswap-finance/index.js @@ -17,7 +17,7 @@ const API_URL = 'https://api.studio.thegraph.com/query/49271/zkswap/0.0.9'; const SECOND_PER_YEAR = 60 * 60 * 24 * 365; const WEEKS_PER_YEAR = 52; -const FEE_RATE = 0.0006; +const FEE_RATE = 0.0004; const CHAIN = 'era'; From da931a0f7ee433e487427b3217739f3fbab3b8db Mon Sep 17 00:00:00 2001 From: zkswapFinance Date: Mon, 23 Oct 2023 16:40:08 +0700 Subject: [PATCH 2/4] get fee rate onchain and caculated APR base on trading volume 24h --- src/adaptors/zkswap-finance/abis.js | 34 ++++++++++++++-- src/adaptors/zkswap-finance/index.js | 58 ++++++++++++++++++---------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/adaptors/zkswap-finance/abis.js b/src/adaptors/zkswap-finance/abis.js index 6418c19dcb..8ae4154d39 100644 --- a/src/adaptors/zkswap-finance/abis.js +++ b/src/adaptors/zkswap-finance/abis.js @@ -1,5 +1,5 @@ module.exports = { - zfFarmABI: [ + zfFarmABI: [ { anonymous: false, inputs: [ @@ -1330,5 +1330,33 @@ module.exports = { type: 'function', }, ], - } - \ No newline at end of file + zfFactory: [ + { + inputs: [], + name: "protocolFeeFactor", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [], + name: "swapFee", + outputs: [ + { + internalType: "uint16", + name: "", + type: "uint16" + } + ], + stateMutability: "view", + type: "function" + } + ] + +} diff --git a/src/adaptors/zkswap-finance/index.js b/src/adaptors/zkswap-finance/index.js index d3407cc1fa..d8697eaf32 100644 --- a/src/adaptors/zkswap-finance/index.js +++ b/src/adaptors/zkswap-finance/index.js @@ -5,19 +5,19 @@ const { request, gql, batchRequests } = require('graphql-request'); const superagent = require('superagent'); const { chunk } = require('lodash'); -const { zfFarmABI, zfTokenABI, erc20ABI } = require('./abis'); +const { zfFarmABI, zfTokenABI, erc20ABI, zfFactory } = require('./abis'); const utils = require('../utils'); const { TokenProvider } = require('@uniswap/smart-order-router'); const ZFFarm = '0x9f9d043fb77a194b4216784eb5985c471b979d67'; const ZFToken = '0x31c2c031fdc9d33e974f327ab0d9883eae06ca4a'; +const ZFFactory = '0x3a76e377ed58c8731f9df3a36155942438744ce3' const RPC_URL = 'https://mainnet.era.zksync.io'; const API_URL = 'https://api.studio.thegraph.com/query/49271/zkswap/0.0.9'; const SECOND_PER_YEAR = 60 * 60 * 24 * 365; const WEEKS_PER_YEAR = 52; -const FEE_RATE = 0.0004; const CHAIN = 'era'; @@ -31,6 +31,23 @@ const apy = async () => { const totalAllocPoint = await zfFarm.methods.totalAllocPoint().call(); const zfPerSecond = (await zfFarm.methods.zfPerSecond().call()) / 1e18; + const protocolFeeRes = await sdk.api.abi.call({ + abi: zfFactory.find(abi => abi.name === 'protocolFeeFactor'), + target: ZFFactory, + chain: CHAIN, + }) + + const feeRes = await sdk.api.abi.call({ + abi: zfFactory.find(abi => abi.name === 'swapFee'), + target: ZFFactory, + chain: CHAIN, + }) + + const fee = feeRes.output + const protocolFee = protocolFeeRes.output + + const feeRate = fee*(1-1/protocolFee)/10000 + const poolsRes = await sdk.api.abi.multiCall({ abi: zfFarmABI.filter(({ name }) => name === 'poolInfo')[0], calls: [...Array(Number(poolsCount)).keys()].map((i) => ({ @@ -81,7 +98,6 @@ const apy = async () => { const pairsInfo = await utils.uniswap.getPairsInfo(lpTokens, API_URL); const lpChunks = chunk(lpTokens, 10); - const pairVolumes = await Promise.all( lpChunks.map((lpsChunk) => request( @@ -91,28 +107,29 @@ const apy = async () => { ${lpsChunk .slice(0, 10) .map( - (token, i) => `token_${token.toLowerCase()}:pairDayDatas( - orderBy: date - orderDirection: desc - first: 7 - where: { pairAddress: "${token.toLowerCase()}" } - ) { - dailyVolumeUSD - }`).join('\n')} - } - ` + (token, i) => + `token_${token.toLowerCase()}:pairHourDatas( + orderBy: hourStartUnix + orderDirection: desc + first: 24 + where: {pair_: {id: "${token.toLowerCase()}"}}) + { + hourlyVolumeUSD + }` + ).join('\n')}}` ) ) ); - const volumesMap = pairVolumes.flat().reduce( (acc, curChunk) => ({ ...acc, ...Object.entries(curChunk).reduce((innerAcc, [key, val]) => ({ ...innerAcc, [key.split('_')[1]]: val, - })), + }), + {} + ), }), {} ); @@ -127,7 +144,7 @@ const apy = async () => { const nonLpTvl = tvl / 1e18 const nonLpRes = nonLpPoolList.map((pool, i) => { const poolInfo = pool; - const poolWeight = poolInfo.allocPoint/totalAllocPoint + const poolWeight = poolInfo.allocPoint / totalAllocPoint const totalRewardPricePerYear = tokensPrices[ZFToken] * poolWeight * zfPerSecond * SECOND_PER_YEAR const totalStakingTokenInPool = tokensPrices[ZFToken] * nonLpTvl const apyReward = (totalRewardPricePerYear / totalStakingTokenInPool) * 100 @@ -175,12 +192,13 @@ const apy = async () => { ) .toString(); - const lpFees7D = + const lpFees24h = (volumesMap[pool.lpToken.toLowerCase()] || []).reduce( - (acc, { dailyVolumeUSD }) => acc + Number(dailyVolumeUSD), + (acc, { hourlyVolumeUSD }) => acc + Number(hourlyVolumeUSD), 0 - ) * FEE_RATE; - const apyBase = ((lpFees7D * WEEKS_PER_YEAR) / lpReservesUsd) * 100; + ) * feeRate; + + const apyBase = ((lpFees24h * 365) / lpReservesUsd) * 100; const apyReward = utils.uniswap.calculateApy( poolInfo, From cf78f4ea83bac9a9702dc569442d497bf800e10d Mon Sep 17 00:00:00 2001 From: zkswapFinance Date: Mon, 23 Oct 2023 18:49:31 +0700 Subject: [PATCH 3/4] add dao pool --- src/adaptors/zkswap-finance/abis.js | 877 +++++++++++++++++++++++++++ src/adaptors/zkswap-finance/index.js | 83 ++- 2 files changed, 953 insertions(+), 7 deletions(-) diff --git a/src/adaptors/zkswap-finance/abis.js b/src/adaptors/zkswap-finance/abis.js index 8ae4154d39..863e831cf6 100644 --- a/src/adaptors/zkswap-finance/abis.js +++ b/src/adaptors/zkswap-finance/abis.js @@ -1357,6 +1357,883 @@ module.exports = { stateMutability: "view", type: "function" } + ], + zfGOVAbi: [ + { + "inputs": [ + { + "internalType": "address", + "name": "_token", + "type": "address" + } + ], + "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": "amount", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "delegator", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "fromDelegate", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "toDelegate", + "type": "address" + } + ], + "name": "DelegateChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "delegate", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "previousBalance", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newBalance", + "type": "uint256" + } + ], + "name": "DelegateVotesChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Deposit", + "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": "amount", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "Withdraw", + "type": "event" + }, + { + "inputs": [], + "name": "DELEGATION_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "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": "rawAmount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "balance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "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": "", + "type": "address" + }, + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "name": "checkpoints", + "outputs": [ + { + "internalType": "uint32", + "name": "fromBlock", + "type": "uint32" + }, + { + "internalType": "uint96", + "name": "votes", + "type": "uint96" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + } + ], + "name": "delegate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "delegatee", + "type": "address" + }, + { + "internalType": "uint256", + "name": "nonce", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expiry", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "delegateBySig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "delegates", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "deposit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "endTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "getCurrentVotes", + "outputs": [ + { + "internalType": "uint96", + "name": "", + "type": "uint96" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "getCurrentZF", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "blockNumber", + "type": "uint256" + } + ], + "name": "getPriorVotes", + "outputs": [ + { + "internalType": "uint96", + "name": "", + "type": "uint96" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getYZFPricePerFullShare", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getZFPricePerFullShare", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastRewardTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "numCheckpoints", + "outputs": [ + { + "internalType": "uint32", + "name": "", + "type": "uint32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingZF", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "rawAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_endTime", + "type": "uint256" + } + ], + "name": "setEndTime", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_zfPerSecond", + "type": "uint256" + } + ], + "name": "setRewardRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_startTime", + "type": "uint256" + } + ], + "name": "setStartTime", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "_factor", + "type": "uint8" + } + ], + "name": "setWithdrawFeeFactor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "startTimestamp", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "token", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "rawAmount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "rawAmount", + "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": [ + { + "internalType": "uint256", + "name": "_shares", + "type": "uint256" + } + ], + "name": "withdraw", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawFeeFactor", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "withdrawFeeFactorMax", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "zfPerSecond", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } ] } diff --git a/src/adaptors/zkswap-finance/index.js b/src/adaptors/zkswap-finance/index.js index d8697eaf32..dc4df06e81 100644 --- a/src/adaptors/zkswap-finance/index.js +++ b/src/adaptors/zkswap-finance/index.js @@ -5,18 +5,24 @@ const { request, gql, batchRequests } = require('graphql-request'); const superagent = require('superagent'); const { chunk } = require('lodash'); -const { zfFarmABI, zfTokenABI, erc20ABI, zfFactory } = require('./abis'); +const { zfFarmABI, zfTokenABI, erc20ABI, zfFactory, zfGOVAbi } = require('./abis'); const utils = require('../utils'); const { TokenProvider } = require('@uniswap/smart-order-router'); +const { SECONDS_PER_YEAR } = require('../across/constants'); const ZFFarm = '0x9f9d043fb77a194b4216784eb5985c471b979d67'; const ZFToken = '0x31c2c031fdc9d33e974f327ab0d9883eae06ca4a'; -const ZFFactory = '0x3a76e377ed58c8731f9df3a36155942438744ce3' +const ZFFactory = '0x3a76e377ed58c8731f9df3a36155942438744ce3'; +const ZF_GOV = '0x4ca2ac3513739cebf053b66a1d59c88d925f1987'; +const DAO_START_TIME = 1697716800; const RPC_URL = 'https://mainnet.era.zksync.io'; const API_URL = 'https://api.studio.thegraph.com/query/49271/zkswap/0.0.9'; +const DAO_API_URL = 'https://api.studio.thegraph.com/query/49271/zfgovernancestaking/0.1.2' -const SECOND_PER_YEAR = 60 * 60 * 24 * 365; +const SECOND_PER_DAY = 60 * 60 * 24 +const DAY_PER_YEAR = 365; +const SECOND_PER_YEAR = SECOND_PER_DAY * DAY_PER_YEAR; const WEEKS_PER_YEAR = 52; const CHAIN = 'era'; @@ -27,6 +33,8 @@ const apy = async () => { const nonLpPools = [0]; const zfFarm = new web3.eth.Contract(zfFarmABI, ZFFarm); + const zfGOV = new web3.eth.Contract(zfGOVAbi, ZF_GOV); + const poolsCount = await zfFarm.methods.poolLength().call(); const totalAllocPoint = await zfFarm.methods.totalAllocPoint().call(); const zfPerSecond = (await zfFarm.methods.zfPerSecond().call()) / 1e18; @@ -46,7 +54,7 @@ const apy = async () => { const fee = feeRes.output const protocolFee = protocolFeeRes.output - const feeRate = fee*(1-1/protocolFee)/10000 + const feeRate = fee * (1 - 1 / protocolFee) / 10000 const poolsRes = await sdk.api.abi.multiCall({ abi: zfFarmABI.filter(({ name }) => name === 'poolInfo')[0], @@ -98,6 +106,25 @@ const apy = async () => { const pairsInfo = await utils.uniswap.getPairsInfo(lpTokens, API_URL); const lpChunks = chunk(lpTokens, 10); + const currentTime = Math.round((new Date()).getTime()/1000) + + const daoQuery = gql` + query daoQuery { + transfers( + where: {blockTimestamp_gt: ${currentTime - SECOND_PER_DAY * 3}, blockTimestamp_lte: ${currentTime}} + first: 1000 + ) { + value + }} + ` + + const {transfers} = await request(DAO_API_URL, daoQuery) + + + const unstakedZFReward = transfers.reduce((volume, transf) => { + return volume + Number(transf.value)/1e18 + }, 0 ) / 90 + const pairVolumes = await Promise.all( lpChunks.map((lpsChunk) => request( @@ -160,7 +187,49 @@ const apy = async () => { rewardTokens: [ZFToken], url: 'https://zkswap.finance/earn', }; - }) + }).filter(pool => pool.apyReward > 0) + + + const unstakedZFReward3Day = (unstakedZFReward/3 * DAY_PER_YEAR) * tokensPrices[ZFToken] + + const {output: zfDAOPerSecondRes} = await sdk.api.abi.call({ + abi: zfGOVAbi.filter(({ name }) => name === 'zfPerSecond')[0], + target: ZF_GOV, + chain: CHAIN + }); + const zfDAOPerSecond = Number(zfDAOPerSecondRes)/1e18 + + const {output: pendingZfRes} = await sdk.api.abi.call({ + abi: zfGOVAbi.filter(({ name }) => name === 'pendingZF')[0], + target: ZF_GOV, + chain: CHAIN + }); + const pendingZf = Number(pendingZfRes)/1e18 + + const {output: currentGovTvlRes} = await sdk.api.abi.call({ + abi: zfGOVAbi.filter(({ name }) => name === 'balance')[0], + target: ZF_GOV, + chain: CHAIN + }); + const currentGovTvl = Number(currentGovTvlRes)/1e18 + + const zfRewardDAOUntilNow = (currentTime - DAO_START_TIME) * zfDAOPerSecond + const govTvl = (currentGovTvl + pendingZf - zfRewardDAOUntilNow) * tokensPrices[ZFToken] + const unstakedAPY = unstakedZFReward3Day/govTvl * 100 + const govFarmAPY = zfDAOPerSecond * SECONDS_PER_YEAR * tokensPrices[ZFToken] / govTvl * 100 + + const govPool = { + pool: ZF_GOV, + chain: CHAIN, + project: 'zkswap-finance', + symbol: 'DAO STAKING ZF Token', + tvlUsd: govTvl, + apyBase: unstakedAPY, + apyReward: govFarmAPY, + underlyingTokens: [ZFToken], + rewardTokens: [ZFToken], + url: 'https://zkswap.finance/earn', + }; const res = pools.map((pool, i) => { const poolInfo = pool; @@ -198,7 +267,7 @@ const apy = async () => { 0 ) * feeRate; - const apyBase = ((lpFees24h * 365) / lpReservesUsd) * 100; + const apyBase = ((lpFees24h * DAY_PER_YEAR) / lpReservesUsd) * 100; const apyReward = utils.uniswap.calculateApy( poolInfo, @@ -222,7 +291,7 @@ const apy = async () => { url: 'https://zkswap.finance/earn', }; }); - return [...nonLpRes, ...res]; + return [...nonLpRes, ...res, govPool]; }; const makeMulticall = async (abi, addresses, chain, params = null) => { From 3af5c4c792486341a3d637a509cf226cd2f55de4 Mon Sep 17 00:00:00 2001 From: zkswapFinance Date: Thu, 26 Oct 2023 13:47:40 +0700 Subject: [PATCH 4/4] fixed token symbol --- src/adaptors/zkswap-finance/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adaptors/zkswap-finance/index.js b/src/adaptors/zkswap-finance/index.js index dc4df06e81..128f64fa55 100644 --- a/src/adaptors/zkswap-finance/index.js +++ b/src/adaptors/zkswap-finance/index.js @@ -222,7 +222,7 @@ const apy = async () => { pool: ZF_GOV, chain: CHAIN, project: 'zkswap-finance', - symbol: 'DAO STAKING ZF Token', + symbol: 'ZF', tvlUsd: govTvl, apyBase: unstakedAPY, apyReward: govFarmAPY,