Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
feat(exactly): ✨ return deposit rates
Browse files Browse the repository at this point in the history
Co-authored-by: itofarina <[email protected]>
  • Loading branch information
cruzdanilo and itofarina committed Jan 4, 2023
1 parent d4912b6 commit 8567be4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/apps/exactly/ethereum/exactly.deposit.token-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type BigNumber, constants } from 'ethers';

import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
import type { GetTokenPropsParams } from '~position/template/app-token.template.types';
import type { GetDataPropsParams, GetTokenPropsParams } from '~position/template/app-token.template.types';

import type { ExactlyMarketDefinition } from '../common/exactly.definitions-resolver';
import { type ExactlyMarketProps, ExactlyTokenFetcher } from '../common/exactly.token-fetcher';
Expand All @@ -16,4 +18,28 @@ export class EthereumExactlyDepositFetcher extends ExactlyTokenFetcher {
getTotalAssets({ definition }: GetTokenPropsParams<Market, ExactlyMarketProps, ExactlyMarketDefinition>) {
return definition.totalFloatingDepositAssets;
}

async getApr({
definition: { blockNumber, timestamp, totalFloatingDepositShares, totalFloatingDepositAssets },
multicall: { contract: multicall },
contract: market,
}: GetDataPropsParams<Market, ExactlyMarketProps, ExactlyMarketDefinition>) {
const [, [[, totalSupplyData], [, totalAssetsData], [, tsData]]] = await multicall.callStatic.aggregate(
[
{ target: market.address, callData: market.interface.encodeFunctionData('totalSupply') },
{ target: market.address, callData: market.interface.encodeFunctionData('totalAssets') },
{ target: multicall.address, callData: multicall.interface.encodeFunctionData('getCurrentBlockTimestamp') },
],
true,
{ blockTag: blockNumber - 123 },
);
const [prevTotalSupply] = market.interface.decodeFunctionResult('totalSupply', totalSupplyData) as [BigNumber];
const [prevTotalAssets] = market.interface.decodeFunctionResult('totalAssets', totalAssetsData) as [BigNumber];
const [prevTimestamp] = multicall.interface.decodeFunctionResult('getCurrentBlockTimestamp', tsData) as [BigNumber];

const shareValue = totalFloatingDepositAssets.mul(constants.WeiPerEther).div(totalFloatingDepositShares);
const prevShareValue = prevTotalAssets.mul(constants.WeiPerEther).div(prevTotalSupply);
const proportion = shareValue.mul(constants.WeiPerEther).div(prevShareValue);
return (Number(proportion) / 1e16 - 100) * (31_536_000 / (timestamp - prevTimestamp.toNumber()));
}
}

0 comments on commit 8567be4

Please sign in to comment.