Skip to content

Commit 38a3e15

Browse files
authored
fix wombat (#2463)
1 parent 49a0fa5 commit 38a3e15

File tree

2 files changed

+45
-67
lines changed

2 files changed

+45
-67
lines changed

src/adaptors/wombat-exchange/config.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,18 @@ module.exports = {
55
APR_ENDPOINT: sdk.graph.modifyEndpoint(
66
'3jEHqbiN3BQn7pyMDzkDcBwm5EYFtpMpXaeryRDGPKA7'
77
),
8-
BLOCK_ENDPOINT: sdk.graph.modifyEndpoint(
9-
'aFYiBZ2nkQVbv1HsKTQcPpWBxCAiJY4w4pG8RXaDxge'
10-
),
118
WOM_ADDRESS: '0xAD6742A35fB341A9Cc6ad674738Dd8da98b94Fb1',
129
},
1310
arbitrum: {
1411
APR_ENDPOINT: sdk.graph.modifyEndpoint(
1512
'5YPaz7z5iYgboKtoShdvZYPohUKtrDLibcLSLzaC424M'
1613
),
17-
BLOCK_ENDPOINT: sdk.graph.modifyEndpoint(
18-
'H51Q1HznwXnrEEMQrKoniHJ6VLz3zryYmb9XQ8T8BmqJ'
19-
),
2014
WOM_ADDRESS: '0x7b5eb3940021ec0e8e463d5dbb4b7b09a89ddf96',
2115
},
2216
avax: {
2317
APR_ENDPOINT: sdk.graph.modifyEndpoint(
2418
'CoQESay2omXqeXf2irxDoPnggR9ULC9SeM7jPeSNgEVT'
2519
),
26-
BLOCK_ENDPOINT: sdk.graph.modifyEndpoint(
27-
'ESjwguQU6CdSHnBT6jMniNHkj2dfAHRdFLB5eWwDe6jB'
28-
),
2920
WOM_ADDRESS: '0xa15E4544D141aa98C4581a1EA10Eb9048c3b3382',
3021
},
3122
};

src/adaptors/wombat-exchange/index.js

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
const { gql, request } = require('graphql-request');
2+
const sdk = require('@defillama/sdk');
23
const config = require('./config.js');
34

4-
const prevBlockQuery = gql`
5-
query Blocks($timestamp_lte: BigInt = "") {
6-
blocks(
7-
first: 1
8-
orderBy: timestamp
9-
orderDirection: desc
10-
where: { timestamp_lte: $timestamp_lte }
11-
) {
12-
number
13-
timestamp
14-
}
15-
}
16-
`;
17-
185
const volumesQuery = gql`
196
query Volumes($block: Int = 0) {
207
assetsNow: assets {
@@ -52,58 +39,58 @@ const aprQuery = gql`
5239
const oneDay = 86400;
5340

5441
const apy = async () => {
55-
apy_export = [];
56-
for (chain in config) {
57-
const timestampPrior = +(new Date() / 1000).toFixed(0) - oneDay;
42+
const apy_export = [];
43+
for (const chain in config) {
44+
try {
45+
const timestampPrior = +(new Date() / 1000).toFixed(0) - oneDay;
5846

59-
const blockPrior = (
60-
await request(config[chain]['BLOCK_ENDPOINT'], prevBlockQuery, {
61-
timestamp_lte: timestampPrior,
62-
})
63-
).blocks[0].number;
47+
const { chainBlocks } = await sdk.blocks.getBlocks(timestampPrior, [chain]);
48+
const blockPrior = chainBlocks[chain];
6449

65-
const { assetsNow, assets24hAgo } = await request(
66-
config[chain]['APR_ENDPOINT'],
67-
volumesQuery,
68-
{
69-
block: +blockPrior,
70-
}
71-
);
50+
const { assetsNow, assets24hAgo } = await request(
51+
config[chain]['APR_ENDPOINT'],
52+
volumesQuery,
53+
{
54+
block: +blockPrior,
55+
}
56+
);
7257

73-
const { assets: aprs } = await request(
74-
config[chain]['APR_ENDPOINT'],
75-
aprQuery
76-
);
58+
const { assets: aprs } = await request(
59+
config[chain]['APR_ENDPOINT'],
60+
aprQuery
61+
);
7762

78-
const assets = aprs.map((pool) => {
79-
const aprData = aprs.find((apr) => apr.id === pool.id) || {};
80-
const feeNow = assetsNow.find((apr) => apr.id === pool.id) || {};
81-
const fee24hAgo = assets24hAgo.find((apr) => apr.id === pool.id) || {};
63+
aprs.map((pool) => {
64+
const aprData = aprs.find((apr) => apr.id === pool.id) || {};
65+
const feeNow = assetsNow.find((apr) => apr.id === pool.id) || {};
66+
const fee24hAgo = assets24hAgo.find((apr) => apr.id === pool.id) || {};
8267

83-
// Projected baseApy estimated by feeUSD collected in 24h
84-
let apyBase =
85-
(((Number(feeNow.totalSharedFeeUSD) -
86-
Number(fee24hAgo.totalSharedFeeUSD)) /
87-
2) *
88-
365 *
89-
100) /
90-
Number(pool.liabilityUSD) || 0;
68+
let apyBase =
69+
(((Number(feeNow.totalSharedFeeUSD) -
70+
Number(fee24hAgo.totalSharedFeeUSD)) /
71+
2) *
72+
365 *
73+
100) /
74+
Number(pool.liabilityUSD) || 0;
9175

92-
let apyReward =
93-
(Number(aprData.womBaseApr) + Number(aprData.totalBonusTokenApr)) * 100;
76+
let apyReward =
77+
(Number(aprData.womBaseApr) + Number(aprData.totalBonusTokenApr)) * 100;
9478

95-
apy_export.push({
96-
pool: aprData.id,
97-
project: 'wombat-exchange',
98-
chain: chain,
99-
tvlUsd: Number(pool.liabilityUSD) || 0,
100-
symbol: pool.symbol,
101-
apyReward,
102-
apyBase,
103-
underlyingTokens: [pool.underlyingToken.id],
104-
rewardTokens: [config[chain]['WOM_ADDRESS']],
79+
apy_export.push({
80+
pool: aprData.id,
81+
project: 'wombat-exchange',
82+
chain: chain,
83+
tvlUsd: Number(pool.liabilityUSD) || 0,
84+
symbol: pool.symbol,
85+
apyReward,
86+
apyBase,
87+
underlyingTokens: [pool.underlyingToken.id],
88+
rewardTokens: [config[chain]['WOM_ADDRESS']],
89+
});
10590
});
106-
});
91+
} catch (e) {
92+
console.log(`wombat-exchange ${chain} failed: ${e.message}`);
93+
}
10794
}
10895

10996
// remove dupes on lptoken

0 commit comments

Comments
 (0)