Skip to content

Commit

Permalink
IPOR yields update (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-ipor authored Oct 16, 2023
1 parent 93c5c51 commit 3cc3198
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 84 deletions.
55 changes: 0 additions & 55 deletions src/adaptors/ipor/abi.js

This file was deleted.

67 changes: 67 additions & 0 deletions src/adaptors/ipor/abiV2.js
Original file line number Diff line number Diff line change
@@ -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"
},
]
}
83 changes: 54 additions & 29 deletions src/adaptors/ipor/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 3cc3198

Please sign in to comment.