Skip to content

Commit 6474975

Browse files
committed
fix: tlv
1 parent fbd4356 commit 6474975

2 files changed

Lines changed: 66 additions & 43 deletions

File tree

src/loader/tvl/prepare-tvl-cronjob-data.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export async function getAmmPoolTvl(chain: LegacyChain) {
7474
if (values.length > 0) {
7575
await tvlRepository.create(values);
7676
}
77+
78+
return values;
7779
}
7880

7981
export async function getLendingPoolTvl(chain: LegacyChain) {
@@ -118,6 +120,8 @@ export async function getLendingPoolTvl(chain: LegacyChain) {
118120
if (values.length > 0) {
119121
await tvlRepository.create(values);
120122
}
123+
124+
return values;
121125
}
122126

123127
export async function getProtocolTvl(chain: LegacyChain) {
@@ -150,6 +154,8 @@ export async function getProtocolTvl(chain: LegacyChain) {
150154
if (values.length > 0) {
151155
await tvlRepository.create(values);
152156
}
157+
158+
return values;
153159
}
154160

155161
export async function getStakingTvl(chain: Chain) {
@@ -162,14 +168,19 @@ export async function getStakingTvl(chain: Chain) {
162168
if (sov) {
163169
const balance = await getErc20Balance(chain.rpc, sov.address, chain.stakingAddress);
164170
if (!isNil(balance) && balance > 0) {
165-
await tvlRepository.create({
166-
chainId: chain.chainId,
167-
contract: chain.stakingAddress,
168-
tokenId: sov.id,
169-
name: 'SOV_Staking',
170-
balance: prettyNumber(bignumber(balance).div(10 ** sov.decimals)),
171-
group: TvlGroup.staking,
172-
});
171+
const values = [
172+
{
173+
chainId: chain.chainId,
174+
contract: chain.stakingAddress,
175+
tokenId: sov.id,
176+
name: 'SOV_Staking',
177+
balance: prettyNumber(bignumber(balance).div(10 ** sov.decimals)),
178+
group: TvlGroup.staking,
179+
},
180+
];
181+
await tvlRepository.create(values);
182+
183+
return;
173184
}
174185
}
175186
}
@@ -187,18 +198,24 @@ export async function getFishTvl(chain: Chain) {
187198
? await getErc20Balance(chain.rpc, fish.address, chain.legacy.babelFishStaking)
188199
: BigInt(0);
189200

190-
await tvlRepository.create({
191-
chainId: chain.chainId,
192-
contract: fish.address,
193-
tokenId: fish.id,
194-
name: 'FISH_TVL',
195-
balance: prettyNumber(
196-
bignumber(fishTotalSupply).minus(multisigBalance.toString()).minus(stakingBalance.toString()),
197-
),
198-
group: TvlGroup.fish,
199-
});
201+
const values = [
202+
{
203+
chainId: chain.chainId,
204+
contract: fish.address,
205+
tokenId: fish.id,
206+
name: 'FISH_TVL',
207+
balance: prettyNumber(
208+
bignumber(fishTotalSupply).minus(multisigBalance.toString()).minus(stakingBalance.toString()),
209+
),
210+
group: TvlGroup.fish,
211+
},
212+
];
213+
214+
await tvlRepository.create(values);
200215

201216
logger.info('Fish TVL data processed');
217+
218+
return values;
202219
}
203220

204221
export async function getSubprotocolTvl(chain: LegacyChain) {
@@ -242,6 +259,8 @@ export async function getZeroTvl(chain: LegacyChain) {
242259
if (items) {
243260
await tvlRepository.create(items);
244261
}
262+
263+
return items;
245264
} catch (e) {
246265
logger.error({ error: e.message }, 'Error while processing Zero TVL');
247266
}
@@ -281,6 +300,8 @@ export async function getMyntTvl(chain: LegacyChain) {
281300
}
282301

283302
logger.info('Mynt TVL data processed');
303+
304+
return items;
284305
} catch (e) {
285306
logger.error({ error: e.message }, 'Error while processing Mynt TVL');
286307
}

src/loader/tvl/prepare-tvl-endpoint-data.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,33 @@ function makeEmptyTvlOutput(chain: Chain) {
5656
*/
5757
export async function prepareTvlEndpoint(chain: Chain) {
5858
// 1) Try snapshot first – this guarantees consistency if cron writes atomically
59-
const snapshot = await loadPrevSnapshot(chain.chainId);
60-
61-
if (snapshot?.data) {
62-
const output = snapshot.data as any;
63-
64-
// Ensure base shape is correct even if snapshot is slightly older schema
65-
if (isNil(output.total_usd)) {
66-
output.total_usd = '0';
67-
}
68-
if (isNil(output.updatedAt)) {
69-
// store ISO in snapshot; here we can convert or just pass through
70-
output.updatedAt = new Date().toISOString();
71-
}
72-
73-
const requiredGroups = makeGroups(chain);
74-
for (const g of requiredGroups) {
75-
if (!output[g]) {
76-
output[g] = { totalUsd: '0' };
77-
} else if (isNil(output[g].totalUsd)) {
78-
output[g].totalUsd = '0';
79-
}
80-
}
81-
82-
return output;
83-
}
59+
// const snapshot = await loadPrevSnapshot(chain.chainId);
60+
61+
// logger.info({ chain: chain.name, hasSnapshot: !!snapshot, data: snapshot }, 'Preparing TVL endpoint data');
62+
63+
// if (snapshot?.data) {
64+
// const output = snapshot.data as any;
65+
66+
// // Ensure base shape is correct even if snapshot is slightly older schema
67+
// if (isNil(output.total_usd)) {
68+
// output.total_usd = '0';
69+
// }
70+
// if (isNil(output.updatedAt)) {
71+
// // store ISO in snapshot; here we can convert or just pass through
72+
// output.updatedAt = new Date().toISOString();
73+
// }
74+
75+
// const requiredGroups = makeGroups(chain);
76+
// for (const g of requiredGroups) {
77+
// if (!output[g]) {
78+
// output[g] = { totalUsd: '0' };
79+
// } else if (isNil(output[g].totalUsd)) {
80+
// output[g].totalUsd = '0';
81+
// }
82+
// }
83+
84+
// return output;
85+
// }
8486

8587
// 2) Fallback: legacy behaviour (compute on the fly from DB)
8688
const data = await tvlRepository.loadAll(chain.chainId).execute();

0 commit comments

Comments
 (0)