-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
66 lines (57 loc) · 2.01 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { BigNumber } from "./dependencies.ts";
import { SECONDS_IN_A_YEAR, ASSET } from "./constants.ts";
import {
getMarketInfo,
getMarsPrice,
getAssetIncentiveInfo,
getMarketLiquidityAmount,
getPrice,
} from "./functions.ts";
// Depositing asset to query APY for
const DEPOSITING_ASSET: Asset = ASSET.OSMO;
// First step is to get Market info
const marketInfo = await getMarketInfo(DEPOSITING_ASSET.denom);
if (!marketInfo) {
throw "There is no market for the given denom.";
}
// Secondly, getting market's liquidity amount, incentive info and price infos of MARS token and depositing asset
const [
marketLiquidityAmount,
assetIncentiveInfo,
depositingAssetPrice,
marsPrice,
] = await Promise.all([
getMarketLiquidityAmount(
DEPOSITING_ASSET.denom,
marketInfo.collateral_total_scaled
),
getAssetIncentiveInfo(DEPOSITING_ASSET.denom),
getPrice(DEPOSITING_ASSET),
getMarsPrice(),
]);
// Next is to calculate annual emission by multiplying emission_per_second with seconds in a year,
// shifting the value by the MARS decimals to get the actual amount
// And then multiplying by the MARS price to get the dollar value of annual emission
const annualEmissionValue = new BigNumber(
assetIncentiveInfo.emission_per_second
)
.multipliedBy(SECONDS_IN_A_YEAR)
.shiftedBy(-ASSET.MARS.decimals)
.multipliedBy(marsPrice);
// Also, converting the market liquidity amount to dollar value
const marketLiquidityValue = depositingAssetPrice.multipliedBy(
marketLiquidityAmount.shiftedBy(-DEPOSITING_ASSET.decimals)
);
// Calculating market returns
const marketReturns = marketLiquidityValue.multipliedBy(
marketInfo.liquidity_rate
);
// Adding annualEmission to market returns and then dividing by market's underlying liquidity value.
// Lastly, multiplying by 100 to get the total annual return percent
const apy = new BigNumber(annualEmissionValue)
.plus(marketReturns)
.dividedBy(marketLiquidityValue)
.multipliedBy(100);
console.log(`Denom: ${DEPOSITING_ASSET.denom}
Incentive APY: %${apy.toFixed(2)}
`);