From 3cc31988a84a96b2c13452596e5000a53d19eaf7 Mon Sep 17 00:00:00 2001 From: kris-ipor <98769272+kris-ipor@users.noreply.github.com> Date: Mon, 16 Oct 2023 11:56:18 +0200 Subject: [PATCH] IPOR yields update (#1036) --- src/adaptors/ipor/abi.js | 55 ------------------------- src/adaptors/ipor/abiV2.js | 67 ++++++++++++++++++++++++++++++ src/adaptors/ipor/index.js | 83 +++++++++++++++++++++++++------------- 3 files changed, 121 insertions(+), 84 deletions(-) delete mode 100644 src/adaptors/ipor/abi.js create mode 100644 src/adaptors/ipor/abiV2.js diff --git a/src/adaptors/ipor/abi.js b/src/adaptors/ipor/abi.js deleted file mode 100644 index 02a7036e62..0000000000 --- a/src/adaptors/ipor/abi.js +++ /dev/null @@ -1,55 +0,0 @@ -module.exports = { - liquidityMiningAbi: [ - { - inputs: [ - { - internalType: "address", - name: "lpToken", - type: "address" - } - ], - name: "getGlobalIndicators", - outputs: [ - { - components: [ - { - internalType: "uint256", - name: "aggregatedPowerUp", - type: "uint256" - }, - { - internalType: "uint128", - name: "compositeMultiplierInTheBlock", - type: "uint128" - }, - { - internalType: "uint128", - name: "compositeMultiplierCumulativePrevBlock", - type: "uint128" - }, - { - internalType: "uint32", - name: "blockNumber", - type: "uint32" - }, - { - internalType: "uint32", - name: "rewardsPerBlock", - type: "uint32" - }, - { - internalType: "uint88", - name: "accruedRewards", - type: "uint88" - } - ], - internalType: "struct LiquidityMiningTypes.GlobalRewardsIndicators", - name: "", - type: "tuple" - } - ], - stateMutability: "view", - type: "function" - }, - ] -} diff --git a/src/adaptors/ipor/abiV2.js b/src/adaptors/ipor/abiV2.js new file mode 100644 index 0000000000..99279cb6ef --- /dev/null +++ b/src/adaptors/ipor/abiV2.js @@ -0,0 +1,67 @@ +module.exports = { + liquidityMiningV2Abi: [ + { + inputs: [ + { + internalType: "address[]", + name: "lpTokens", + type: "address[]" + } + ], + name: "getGlobalIndicators", + outputs: [ + { + components: [ + { + internalType: "address", + name: "lpToken", + type: "address" + }, + { + components: [ + { + internalType: "uint256", + name: "aggregatedPowerUp", + type: "uint256" + }, + { + internalType: "uint128", + name: "compositeMultiplierInTheBlock", + type: "uint128" + }, + { + internalType: "uint128", + name: "compositeMultiplierCumulativePrevBlock", + type: "uint128" + }, + { + internalType: "uint32", + name: "blockNumber", + type: "uint32" + }, + { + internalType: "uint32", + name: "rewardsPerBlock", + type: "uint32" + }, + { + internalType: "uint88", + name: "accruedRewards", + type: "uint88" + } + ], + internalType: "struct ILiquidityMiningLens.GlobalRewardsIndicators", + name: "indicators", + type: "tuple" + } + ], + internalType: "struct ILiquidityMiningLens.GlobalIndicatorsResult[]", + name: "", + type: "tuple[]" + } + ], + stateMutability: "view", + type: "function" + }, + ] +} diff --git a/src/adaptors/ipor/index.js b/src/adaptors/ipor/index.js index fb3a71b8f2..0ae852b9b8 100644 --- a/src/adaptors/ipor/index.js +++ b/src/adaptors/ipor/index.js @@ -1,6 +1,6 @@ const superagent = require('superagent'); const sdk = require('@defillama/sdk'); -const { liquidityMiningAbi } = require('./abi'); +const { liquidityMiningV2Abi } = require('./abiV2'); const LP_STATS_URL = 'https://api.ipor.io/monitor/liquiditypool-statistics'; const COIN_PRICES_URL = 'https://coins.llama.fi/prices/current'; @@ -30,17 +30,16 @@ const apy = async () => { const globalStats = new Map( ( await sdk.api.abi.multiCall({ - abi: liquidityMiningAbi.find( + abi: liquidityMiningV2Abi.find( ({ name }) => name === 'getGlobalIndicators' ), - calls: lpTokenAddresses.map((lpTokenAddress) => ({ + calls: [{ target: LM_ADDRESS, - params: lpTokenAddress, - })), + params: [lpTokenAddresses], + }], }) - ).output.map((stats) => [stats.input.params[0].toLowerCase(), stats.output]) - ); - + ).output.flatMap((response) => response.output.map((stats) => [stats.lpToken.toLowerCase(), stats.indicators]) + )); const pools = []; for (const asset of assets) { @@ -62,28 +61,54 @@ const apy = async () => { const liquidityMiningGlobalStats = globalStats.get( asset.ipTokenAssetAddress.toLowerCase() ); - const apyReward = - (((liquidityMiningGlobalStats.rewardsPerBlock / - 1e8 / - (liquidityMiningGlobalStats.aggregatedPowerUp / 1e18)) * - 0.4 * //base powerup - BLOCKS_PER_YEAR * - iporTokenUsdPrice) / - lpTokenPrice / - 2) * //50% early withdraw fee - 100; //percentage + if (asset.asset === 'stETH') { + const apyReward = + (((liquidityMiningGlobalStats.rewardsPerBlock / + 1e8 / + (liquidityMiningGlobalStats.aggregatedPowerUp / 1e18)) * + 0.2 * //base powerup + BLOCKS_PER_YEAR * + iporTokenUsdPrice) / + lpTokenPrice / + coinPrice / + 2) * //50% early withdraw fee + 100; //percentage + + pools.push({ + pool: asset.ipTokenAssetAddress + '-ethereum', + chain: 'Ethereum', + project: 'ipor', + symbol: asset.asset, + tvlUsd: lpBalance * coinPrice, + apyBase: Number(lpApr), + apyReward: Number(apyReward), + underlyingTokens: [asset.assetAddress], + rewardTokens: [IPOR_TOKEN], + }); + } else { + const apyReward = + (((liquidityMiningGlobalStats.rewardsPerBlock / + 1e8 / + (liquidityMiningGlobalStats.aggregatedPowerUp / 1e18)) * + 0.2 * //base powerup + BLOCKS_PER_YEAR * + iporTokenUsdPrice) / + lpTokenPrice / + 2) * //50% early withdraw fee + 100; //percentage - pools.push({ - pool: asset.assetAddress + '-ethereum', - chain: 'Ethereum', - project: 'ipor', - symbol: asset.asset, - tvlUsd: lpBalance * coinPrice, - apyBase: Number(lpApr), - apyReward: Number(apyReward), - underlyingTokens: [asset.assetAddress], - rewardTokens: [IPOR_TOKEN], - }); + pools.push({ + pool: asset.assetAddress + '-ethereum', + chain: 'Ethereum', + project: 'ipor', + symbol: asset.asset, + tvlUsd: lpBalance * coinPrice, + apyBase: Number(lpApr), + apyReward: Number(apyReward), + underlyingTokens: [asset.assetAddress], + rewardTokens: [IPOR_TOKEN], + }); + } } return pools;