Skip to content

Commit ea31b81

Browse files
committed
fix scream
1 parent 1999e93 commit ea31b81

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/adaptors/scream/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const sdk = require('@defillama/sdk');
22
const superagent = require('superagent');
33
const { request, gql } = require('graphql-request');
4-
const { Web3 } = require('web3');
54

65
const utils = require('../utils');
76
const { comptrollerABI } = require('./abi');
87

9-
const FTM_RPC = 'https://rpc.ankr.com/fantom/';
108
const API_URL = sdk.graph.modifyEndpoint(
119
'5HSMXwr8MjGvXgsur1xJdx9FV47qkaUxttYSsnZ2G3F4'
1210
);
@@ -31,30 +29,32 @@ const query = gql`
3129
}
3230
`;
3331

34-
const web3 = new Web3(FTM_RPC);
35-
3632
const getRewardTokenApr = async (marketsData) => {
3733
const key = 'coingecko:scream';
3834
const rewardTokenPrice = (
3935
await superagent.get(`https://coins.llama.fi/prices/current/${key}`)
4036
).body.coins[key].price;
4137

42-
const comptroller = new web3.eth.Contract(
43-
comptrollerABI,
44-
COMPTROLLER_ADDRESS
45-
);
38+
const compSpeeds = (
39+
await sdk.api.abi.multiCall({
40+
calls: marketsData.map((m) => ({
41+
target: COMPTROLLER_ADDRESS,
42+
params: m.id,
43+
})),
44+
chain: 'fantom',
45+
abi: comptrollerABI.find((m) => m.name === 'compSpeeds'),
46+
})
47+
).output.map((i) => i.output);
4648

47-
const rewardsPerBlock = await Promise.all(
48-
marketsData.map(async (market) => ({
49-
market: market.id,
50-
reward: Number(await comptroller.methods.compSpeeds(market.id).call()),
51-
totalBorrowUSD:
52-
Number(market.totalBorrows) * Number(market.underlyingPriceUSD),
53-
totalSupplyUSD:
54-
(Number(market.cash) + Number(market.totalBorrows)) *
55-
Number(market.underlyingPriceUSD),
56-
}))
57-
);
49+
const rewardsPerBlock = marketsData.map((market, i) => ({
50+
market: market.id,
51+
reward: Number(compSpeeds[i]),
52+
totalBorrowUSD:
53+
Number(market.totalBorrows) * Number(market.underlyingPriceUSD),
54+
totalSupplyUSD:
55+
(Number(market.cash) + Number(market.totalBorrows)) *
56+
Number(market.underlyingPriceUSD),
57+
}));
5858

5959
const apr = rewardsPerBlock.reduce(
6060
(acc, { market, reward, totalBorrowUSD, totalSupplyUSD }) => {

0 commit comments

Comments
 (0)