Skip to content

Commit

Permalink
Merge pull request #675 from DefiLlama/split-velodrome
Browse files Browse the repository at this point in the history
split velodrome
  • Loading branch information
dtmkeng committed Jul 27, 2023
2 parents 0bd5f79 + 0a5e0e2 commit 4217a7c
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 18 deletions.
27 changes: 27 additions & 0 deletions dexs/velodrome-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { Chain } from "@defillama/sdk/build/general";
import { fetchV2 } from "./v2";


const fetch = (_: Chain) => {
return async (timestamp: number) => {
const [v2] = await Promise.all([fetchV2(timestamp)])
const dailyVolume = Number(v2.dailyVolume);
return {
dailyVolume: `${dailyVolume}`,
timestamp
}
}
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.OPTIMISM]: {
fetch: fetch(CHAIN.OPTIMISM),
start: async () => 1677110400
},
},
};

export default adapter;
File renamed without changes.
6 changes: 2 additions & 4 deletions dexs/velodrome/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { SimpleAdapter } from "../../adapters/types";
import { getStartTimestamp } from "../../helpers/getStartTimestamp";
import { DEFAULT_DAILY_VOLUME_FIELD, DEFAULT_TOTAL_VOLUME_FIELD, getChainVolume } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";
import { Chain } from "@defillama/sdk/build/general";
import { fetchV2 } from "./v2";

const endpoints = {
[CHAIN.OPTIMISM]: "https://api.thegraph.com/subgraphs/name/dmihal/velodrome",
Expand All @@ -23,8 +21,8 @@ const graphs = getChainVolume({

const fetch = (chain: Chain) => {
return async (timestamp: number) => {
const [v1, v2] = await Promise.all([graphs(chain)(timestamp, {}), fetchV2(timestamp)])
const dailyVolume = Number(v1.dailyVolume) + Number(v2.dailyVolume);
const [v1] = await Promise.all([graphs(chain)(timestamp, {})])
const dailyVolume = Number(v1.dailyVolume);
return {
dailyVolume: `${dailyVolume}`,
timestamp
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions fees/velodrome-v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Adapter, Fetch, FetchResultFees } from '../../adapters/types';
import { CHAIN, OPTIMISM } from '../../helpers/chains';
import { fetchV2 } from './velodrome-v2';
import { fees_bribes } from './bribes';
import { getBlock } from '../../helpers/getBlock';


const getFees = async (timestamp: number): Promise<FetchResultFees> => {
const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp
const fromBlock = (await getBlock(fromTimestamp, CHAIN.OPTIMISM, {}));
const toBlock = (await getBlock(toTimestamp, CHAIN.OPTIMISM, {}));
const [feeV2, bribes] = await Promise.all([fetchV2(fromBlock, toBlock,timestamp), fees_bribes(fromBlock, toBlock, timestamp)]);
const dailyFees = Number(feeV2.dailyFees);
const dailyRevenue = Number(feeV2.dailyRevenue) + bribes;
const dailyHoldersRevenue = Number(feeV2.dailyHoldersRevenue) + bribes;
return {
dailyFees: `${dailyFees}`,
dailyRevenue: `${dailyRevenue}`,
dailyHoldersRevenue: `${dailyHoldersRevenue}`,
dailyBribesRevenue: `${bribes}`,
timestamp
}
}

const adapter: Adapter = {
adapter: {
[OPTIMISM]: {
fetch: getFees,
start: async () => 1677110400, // TODO: Add accurate timestamp
},
},
};
export default adapter;
File renamed without changes.
20 changes: 6 additions & 14 deletions fees/velodrome/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { Adapter, Fetch, FetchResultFees } from '../../adapters/types';
import { CHAIN, OPTIMISM } from '../../helpers/chains';
import { Adapter, FetchResultFees } from '../../adapters/types';
import { OPTIMISM } from '../../helpers/chains';
import { fetchV1 } from './velodrome';
import { fetchV2 } from './velodrome-v2';
import { fees_bribes } from './bribes';
import { getBlock } from '../../helpers/getBlock';


const getFees = async (timestamp: number): Promise<FetchResultFees> => {
const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp
const fromBlock = (await getBlock(fromTimestamp, CHAIN.OPTIMISM, {}));
const toBlock = (await getBlock(toTimestamp, CHAIN.OPTIMISM, {}));
const [feeV1, feeV2, bribes] = await Promise.all([fetchV1()(timestamp), fetchV2(fromBlock, toBlock,timestamp), fees_bribes(fromBlock, toBlock, timestamp)]);
const dailyFees = Number(feeV1.dailyFees) + Number(feeV2.dailyFees);
const dailyRevenue = Number(feeV1.dailyRevenue) + Number(feeV2.dailyRevenue) + bribes;
const dailyHoldersRevenue = Number(feeV1.dailyHoldersRevenue) + Number(feeV2.dailyHoldersRevenue) + bribes;
const [feeV1] = await Promise.all([fetchV1()(timestamp)]);
const dailyFees = Number(feeV1.dailyFees);
const dailyRevenue = Number(feeV1.dailyRevenue);
const dailyHoldersRevenue = Number(feeV1.dailyHoldersRevenue);
return {
dailyFees: `${dailyFees}`,
dailyRevenue: `${dailyRevenue}`,
dailyHoldersRevenue: `${dailyHoldersRevenue}`,
dailyBribesRevenue: `${bribes}`,
timestamp
}
}
Expand Down

0 comments on commit 4217a7c

Please sign in to comment.