Skip to content

Commit a371b67

Browse files
authored
fix: add profit deposit ordering as well as live tvl (#2750)
Signed-off-by: Marin Petrunic <marin.petrunic@gmail.com>
1 parent 6bae819 commit a371b67

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/adaptors/sprinter/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
1616

1717
const DataQuery = gql`
1818
query DataQuery($from: BigInt = "", $to: BigInt = "") {
19-
depositProfits(where: {blockTimestamp_gte: $from, blockTimestamp_lte: $to}) {
19+
depositProfits(
20+
where: {blockTimestamp_gte: $from, blockTimestamp_lte: $to}
21+
orderBy: blockTimestamp
22+
orderDirection: desc
23+
) {
2024
assets
2125
totalAssets
2226
blockTimestamp
@@ -52,6 +56,14 @@ async function apy() {
5256

5357
const lastDepositProfit = depositProfits[0];
5458

59+
const totalAssets = (
60+
await sdk.api.abi.call({
61+
target: HUB_CONTRACT_ADDRESS,
62+
abi: 'function totalAssets() external view returns (uint256)',
63+
chain: 'base',
64+
})
65+
).output;
66+
5567
const timeDiff =
5668
new Date(parseInt(lastDepositProfit.blockTimestamp) * 1000).getTime() - startTimestamp;
5769
const daysInPeriod = Math.max(1, Math.floor(timeDiff / DAY_IN_MS));
@@ -66,7 +78,7 @@ async function apy() {
6678
pool: HUB_CONTRACT_ADDRESS,
6779
chain: utils.formatChain("base"),
6880
symbol: "USDC",
69-
tvlUsd: Number(formatUnits(lastDepositProfit.totalAssets, USDC_DECIMALS)),
81+
tvlUsd: Number(formatUnits(totalAssets, USDC_DECIMALS)),
7082
apy: rate * 100,
7183
underlyingTokens: [USDC_BASE],
7284
}];

0 commit comments

Comments
 (0)