Skip to content

Commit

Permalink
IPOR reward apy (DefiLlama#549)
Browse files Browse the repository at this point in the history
* Add APY rewards to IPOR pools

* Add IPOR reward token

* Revert reformatting

* Update IPOR reward apy
  • Loading branch information
kris-ipor authored Jan 30, 2023
1 parent 15dd848 commit 868ee99
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
55 changes: 55 additions & 0 deletions src/adaptors/ipor/abi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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"
},
]
}
36 changes: 34 additions & 2 deletions src/adaptors/ipor/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
const superagent = require('superagent');
const sdk = require("@defillama/sdk");
const {liquidityMiningAbi} = require('./abi')

const LP_STATS_URL = "https://api.ipor.io/monitor/liquiditypool-statistics";
const COIN_PRICES_URL = "https://coins.llama.fi/prices";

const apy = async () => {
const LM_ADDRESS = "0xCC3Fc4C9Ba7f8b8aA433Bc586D390A70560FF366";
const IPOR_TOKEN = "0x1e4746dc744503b53b4a082cb3607b169a289090";

const BLOCKS_PER_YEAR = 365 * 24 * 3600 / 12;

const apy = async () => {
const assets = (await superagent.get(LP_STATS_URL)).body.assets;
const coinKeys = assets.map((assetData) => "ethereum:" + assetData.assetAddress);
coinKeys.push('ethereum:' + IPOR_TOKEN);
const coinPrices = (await superagent.post(COIN_PRICES_URL).send({coins: coinKeys})).body.coins;
const iporTokenUsdPrice = coinPrices["ethereum:" + IPOR_TOKEN].price;

const lpTokenAddresses = assets.map((assetData) => assetData.ipTokenAssetAddress);

const globalStats = new Map((
await sdk.api.abi.multiCall({
abi: liquidityMiningAbi.find(({name}) => name === "getGlobalIndicators"),
calls: lpTokenAddresses.map((lpTokenAddress) => ({
target: LM_ADDRESS,
params: lpTokenAddress,
}))
})
).output.map(stats => [stats.input.params[0].toLowerCase(), stats.output]));

const pools = [];

Expand All @@ -16,6 +36,17 @@ const apy = async () => {
const coinPrice = coinPrices["ethereum:" + asset.assetAddress.toLowerCase()].price;
const lpBalanceHistory = asset.periods.find(({period}) => period === "HOUR").totalLiquidity;
const lpBalance = lpBalanceHistory[lpBalanceHistory.length - 1].totalLiquidity;
const lpTokenPriceHistory = asset.periods.find(({period}) => period === "HOUR").ipTokenExchangeRates;
const lpTokenPrice = lpTokenPriceHistory[lpTokenPriceHistory.length - 1].exchangeRate;
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

pools.push({
pool: asset.assetAddress + "-ethereum",
Expand All @@ -24,8 +55,9 @@ const apy = async () => {
symbol: asset.asset,
tvlUsd: lpBalance * coinPrice,
apyBase: Number(lpApr),
apyReward: null,
apyReward: Number(apyReward),
underlyingTokens: [asset.assetAddress],
rewardTokens: [IPOR_TOKEN]
});
}

Expand Down

0 comments on commit 868ee99

Please sign in to comment.