Skip to content

Commit e0523a4

Browse files
authored
use chainapi again
1 parent f6ee7a1 commit e0523a4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

adapters/velodrome/index.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getLogs } from "@defillama/sdk/build/util/logs";
2-
import { getProvider } from "@defillama/sdk";
1+
import { ChainApi } from '@defillama/sdk'
32
import { LinearAdapterResult, TimeSeriesChainData } from "../../types/adapters";
43
import { PromisePool } from "@supercharge/promise-pool";
54
import { getBlock } from "@defillama/sdk/build/computeTVL/blocks";
@@ -75,6 +74,10 @@ async function getCachedChainData(version: 'v1' | 'v2'): Promise<VelodromeChainD
7574
}
7675

7776
async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData> {
77+
const api = new ChainApi({
78+
chain: 'optimism'
79+
})
80+
7881
const chainData: VelodromeChainData = {};
7982
const versionConfig = VERSIONS[version];
8083
const toBlock = (await getBlock("optimism", unixTimestampNow())).number;
@@ -84,7 +87,7 @@ async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData>
8487

8588
if (version === 'v2') {
8689
const [mintLogs, tokenMints] = await Promise.all([
87-
getLogs({
90+
api.getLogs({
8891
target: versionConfig.MINTER_ADDRESS,
8992
eventAbi: mintEventAbi,
9093
fromBlock: versionConfig.START,
@@ -93,7 +96,7 @@ async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData>
9396
entireLog: true,
9497
parseLog: true
9598
}),
96-
getLogs({
99+
api.getLogs({
97100
target: versionConfig.VELO_TOKEN,
98101
topics: [
99102
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
@@ -133,7 +136,7 @@ async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData>
133136
}
134137
} else {
135138
const [mintLogs, teamTransfers, rebaseTransfers] = await Promise.all([
136-
getLogs({
139+
api.getLogs({
137140
target: versionConfig.MINTER_ADDRESS,
138141
eventAbi: mintEventAbi,
139142
fromBlock: versionConfig.START,
@@ -142,7 +145,7 @@ async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData>
142145
entireLog: true,
143146
parseLog: true
144147
}),
145-
getLogs({
148+
api.getLogs({
146149
target: versionConfig.VELO_TOKEN,
147150
topics: [
148151
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
@@ -154,7 +157,7 @@ async function fetchChainData(version: 'v1' | 'v2'): Promise<VelodromeChainData>
154157
chain: "optimism",
155158
entireLog: true
156159
}),
157-
getLogs({
160+
api.getLogs({
158161
target: versionConfig.VELO_TOKEN,
159162
topics: [
160163
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
@@ -210,11 +213,15 @@ function groupTransfersByTx(transfers: any[]) {
210213
}
211214

212215
async function processBlocks(mintLogs: any[], chainData: VelodromeChainData) {
216+
const api = new ChainApi({
217+
chain: 'optimism'
218+
})
219+
213220
const blockNumbers = [...new Set(mintLogs.map(log => log.blockNumber))];
214221
await PromisePool.withConcurrency(10)
215222
.for(blockNumbers)
216223
.process(async (blockNum) => {
217-
const block = await getProvider("optimism").getBlock(blockNum);
224+
const block = await api.provider.getBlock(blockNum);
218225
if (block?.timestamp) {
219226
chainData[blockNum] = {
220227
timestamp: block.timestamp,

0 commit comments

Comments
 (0)