Skip to content

Commit

Permalink
colony
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Sep 11, 2024
1 parent 3a6305c commit eefff16
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 123 deletions.
24 changes: 3 additions & 21 deletions fees/ascent-v3.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import { Chain } from "@defillama/sdk/build/general";

import { SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import {
DEFAULT_DAILY_VOLUME_FACTORY,
DEFAULT_TOTAL_VOLUME_FIELD,
} from "../helpers/getUniSubgraphVolume";

import { getGraphDimensions } from "../helpers/getUniSubgraph";

interface IPoolData {
id: number;
feesUSD: string;
}
import { DEFAULT_TOTAL_VOLUME_FIELD } from "../helpers/getUniSubgraphVolume";
import { getGraphDimensions2 } from "../helpers/getUniSubgraph";

type IURL = {
[l: string | Chain]: string;
Expand All @@ -23,20 +13,12 @@ const endpoints: IURL = {
"https://eon-graph.horizenlabs.io/subgraphs/name/surfacing8671/v3AscentFull2",
};

const v3Graphs = getGraphDimensions({
const v3Graphs = getGraphDimensions2({
graphUrls: endpoints,
totalVolume: {
factory: "factories",
field: DEFAULT_TOTAL_VOLUME_FIELD,
},
dailyVolume: {
factory: "pancakeDayData",
field: "volumeUSD",
},
dailyFees: {
factory: "pancakeDayData",
field: "feesUSD",
},
feesPercent: {
type: "fees",
ProtocolRevenue: 32,
Expand Down
2 changes: 1 addition & 1 deletion fees/beamswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const feeAdapter = getDexChainFees({
});

const adapter: Adapter = {
version: 2,
version: 1,
adapter: feeAdapter
};

Expand Down
14 changes: 3 additions & 11 deletions fees/cleopatra-exchange.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { SimpleAdapter, FetchResultFees, BaseAdapter } from "../adapters/types";
import { SimpleAdapter } from "../adapters/types";
import { MANTLE, CHAIN } from "../helpers/chains";

import {
getGraphDimensions,
DEFAULT_DAILY_VOLUME_FACTORY,
DEFAULT_TOTAL_VOLUME_FIELD,
getGraphDimensions2,
} from "../helpers/getUniSubgraph";

type TStartTime = {
Expand All @@ -19,18 +17,12 @@ const v2Endpoints = {
"https://subgraph-api.mantle.xyz/subgraphs/name/cleoexchange/cl-subgraph",
};

const VOLUME_USD = "volumeUSD";

const v2Graphs = getGraphDimensions({
const v2Graphs = getGraphDimensions2({
graphUrls: v2Endpoints,
totalVolume: {
factory: "factories",
field: DEFAULT_TOTAL_VOLUME_FIELD,
},
dailyVolume: {
factory: DEFAULT_DAILY_VOLUME_FACTORY,
field: VOLUME_USD,
},
feesPercent: {
type: "fees",
HoldersRevenue: 72,
Expand Down
9 changes: 3 additions & 6 deletions fees/colony/airdrops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ export async function airdrops(
options: FetchOptions,
stakingV3SubgraphEndpoint: string,
): Promise<Airdrops> {
const { createBalances, startTimestamp } = options;
const { createBalances, startTimestamp, endTimestamp } = options;

let dailyHoldersRevenue = createBalances()
let totalHoldersRevenue = createBalances()

const day = Math.floor(startTimestamp / 86400)
const date = day * 86400

try {
const res: IGraphAirdropsResponse = await request(stakingV3SubgraphEndpoint, queryAirdrops, {
timestampFrom: date,
timestampTo: date + 86400
timestampFrom: startTimestamp,
timestampTo: endTimestamp
});

if (res.rewards.length > 0) {
Expand Down
12 changes: 2 additions & 10 deletions fees/colony/dex.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGraphDimensions } from "../../helpers/getUniSubgraph"
import { getGraphDimensions, getGraphDimensions2 } from "../../helpers/getUniSubgraph"
import { FetchOptions } from "../../adapters/types";
import { Balances } from "@defillama/sdk";
import BigNumber from "bignumber.js";
Expand Down Expand Up @@ -32,26 +32,18 @@ export async function dexFees(
const VOLUME_USD = "volumeUSD";
const FEES_USD = "feesUSD";

const v2Graph = getGraphDimensions({
const v2Graph = getGraphDimensions2({
graphUrls: {
[options.chain]: dexSubgraphEndpoint,
},
totalVolume: {
factory: "factories",
field: VOLUME_USD,
},
dailyVolume: {
factory: "dayData",
field: VOLUME_USD,
},
totalFees: {
factory: "factories",
field: FEES_USD,
},
dailyFees: {
factory: "dayData",
field: FEES_USD,
}
});

const results = await v2Graph(options.chain)(options)
Expand Down
7 changes: 2 additions & 5 deletions fees/colony/earlystage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@ export async function earlyStageFees(
options: FetchOptions,
earlystageSubgraphEndpoint: string,
): Promise<EarlyStageFees> {
const { createBalances, startTimestamp } = options;
const { createBalances, startTimestamp, endTimestamp } = options;

let dailyProtocolRevenue = createBalances()
let totalProtocolRevenue = createBalances()
let dailyHoldersRevenue = createBalances()
let totalHoldersRevenue = createBalances()

const day = Math.floor(startTimestamp / 86400)
const date = day * 86400

try {
const res: IGraphEarlyStageFeesResponse = await request(earlystageSubgraphEndpoint, queryEarlyStageFees);

if (res.projectDistributions && res.projectDistributions.length) {
const todayRes = res.projectDistributions.filter(x => x.timestamp >= date && x.timestamp < date + 86400)
const todayRes = res.projectDistributions.filter(x => x.timestamp >= startTimestamp && x.timestamp < endTimestamp)

// --- Protocol Revenue
dailyProtocolRevenue = todayRes.reduce((acc: Balances, x) => {
Expand Down
7 changes: 2 additions & 5 deletions fees/colony/masterChef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ export async function masterChef(
masterChefSubgraphEndpoint: string,
earlyStageSubgraphEndpoint: string,
): Promise<Airdrops> {
const { createBalances, startTimestamp } = options;
const { createBalances, startTimestamp, endTimestamp } = options;

let dailySupplySideRevenue = createBalances()
let totalSupplySideRevenue = createBalances()

const day = Math.floor(startTimestamp / 86400)
const date = day * 86400

try {
const ceTokenRes: ICeTokensResponse = await request(earlyStageSubgraphEndpoint, ceTokensQuery);
const priceMap = new Map()
Expand All @@ -101,7 +98,7 @@ export async function masterChef(

const rewardersRes: IGraphAirdropsResponse = await request(masterChefSubgraphEndpoint, rewardersQuery);
for (const rewarder of rewardersRes.rewarders) {
if (rewarder.startTimestamp >= date && rewarder.startTimestamp < date + 86400) {
if (rewarder.startTimestamp >= startTimestamp && rewarder.startTimestamp < endTimestamp) {
addTokenBalance(
dailySupplySideRevenue,
priceMap,
Expand Down
99 changes: 41 additions & 58 deletions fees/colony/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,53 @@ import { Balances } from "@defillama/sdk";
import { FetchOptions } from "../../adapters/types";
import { request, gql } from "graphql-request";

export interface StakingFees {
dailyHoldersRevenue: Balances;
totalHoldersRevenue: Balances;
}

interface ITotalStakeFees {
totalStakeFees: string;
totalUnstakeFees: string;
}

interface IDailyStakeFees {
stakeFees: string;
unstakeFees: string;
}

interface IGraphStakeResponse {
metrics: ITotalStakeFees[];
dailyMetrics: IDailyStakeFees[];
}

const queryStakingFeesMetrics = gql
`query fees($date: Int!) {
metrics {
totalStakeFees
totalUnstakeFees
}
dailyMetrics(where: {date: $date}) {
unstakeFees
stakeFees
const queryStakingFeesMetrics = gql`
query fees($block: Int!) {
metrics(block: { number: $block }) {
totalStakeFees
totalUnstakeFees
}
}
}`;
`;

export async function stakingFees(
options: FetchOptions,
stakingSubgraphEndpoint: string,
ColonyGovernanceToken: string
): Promise<StakingFees> {
const { createBalances, startTimestamp } = options;

let dailyHoldersRevenue = createBalances()
let totalHoldersRevenue = createBalances()

const day = Math.floor(startTimestamp / 86400)
const date = day * 86400

try {
const res: IGraphStakeResponse = await request(stakingSubgraphEndpoint, queryStakingFeesMetrics, { date });

if (res.dailyMetrics && res.dailyMetrics.length) {
dailyHoldersRevenue.add(ColonyGovernanceToken, res.dailyMetrics[0].stakeFees);
dailyHoldersRevenue.add(ColonyGovernanceToken, res.dailyMetrics[0].unstakeFees);
}

if (res.metrics && res.metrics.length) {
totalHoldersRevenue.add(ColonyGovernanceToken, res.metrics[0].totalStakeFees);
totalHoldersRevenue.add(ColonyGovernanceToken, res.metrics[0].totalUnstakeFees);
}

} catch (e) {
console.error(e);
}
ColonyGovernanceToken: string,
): Promise<{
dailyHoldersRevenue: Balances;
totalHoldersRevenue: Balances;
}> {
const { createBalances, getStartBlock, getEndBlock } = options;

const [startBlock, endBlock] = await Promise.all([
getStartBlock(),
getEndBlock(),
]);
let dailyHoldersRevenue = createBalances();
let totalHoldersRevenue = createBalances();

const [beforeRes, afterRes] = await Promise.all([
request(stakingSubgraphEndpoint, queryStakingFeesMetrics, {
block: startBlock,
}),
request(stakingSubgraphEndpoint, queryStakingFeesMetrics, {
block: endBlock,
}),
]);

const beforeFees: number =
Number(beforeRes.metrics[0].totalStakeFees) +
Number(beforeRes.metrics[0].totalUnstakeFees);
const afterFees: number =
Number(afterRes.metrics[0].totalStakeFees) +
Number(afterRes.metrics[0].totalUnstakeFees);

dailyHoldersRevenue.add(ColonyGovernanceToken, afterFees - beforeFees);
totalHoldersRevenue.add(ColonyGovernanceToken, afterFees);

return {
dailyHoldersRevenue,
totalHoldersRevenue
}
totalHoldersRevenue,
};
}
9 changes: 3 additions & 6 deletions fees/colony/validatorProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,17 @@ export async function validatorProgramFees(
options: FetchOptions,
stakingV3SubgraphEndpoint: string,
): Promise<ValidatorProgramFees> {
const { createBalances, startTimestamp } = options;
const { createBalances, startTimestamp, endTimestamp } = options;

let dailyProtocolRevenue = createBalances()
let totalProtocolRevenue = createBalances()
let dailyHoldersRevenue = createBalances()
let totalHoldersRevenue = createBalances()

const day = Math.floor(startTimestamp / 86400)
const date = day * 86400

try {
const res: IGraphEarlyStageFeesResponse = await request(stakingV3SubgraphEndpoint, queryValidatorProgramFees, {
timestampFrom: date,
timestampTo: date + 86400
timestampFrom: startTimestamp,
timestampTo: endTimestamp
});

if (res.rewards[0] !== undefined) {
Expand Down

0 comments on commit eefff16

Please sign in to comment.