Skip to content

Commit

Permalink
Merge pull request #1381 from Intent-X/master
Browse files Browse the repository at this point in the history
Segregated volume & fees per chain for IntentX. Core markets blast chain correction
  • Loading branch information
dtmkeng committed Apr 4, 2024
2 parents 7ca380f + a2d2e6b commit bbda451
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dexs/core-markets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BASE]: {
[CHAIN.BLAST]: {
fetch: fetchVolume,
start: async () => 236678,
},
Expand Down
39 changes: 31 additions & 8 deletions dexs/intent-x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});
const response_blast: IGraphResponse = await request(endpoint_blast, queryBlast, {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});

let dailyVolume = new BigNumber(0);
response_0_8_0.dailyHistories.forEach((data) => {
Expand All @@ -108,10 +104,6 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
response.dailyHistories.forEach((data) => {
dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume));
});
response_blast.dailyHistories.forEach((data) => {
dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume));
});


let totalVolume = new BigNumber(0);
response_0_8_0.totalHistories.forEach((data) => {
Expand All @@ -120,6 +112,33 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
response.totalHistories.forEach((data) => {
totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume));
});

dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18));
totalVolume = totalVolume.dividedBy(new BigNumber(1e18));

const _dailyVolume = toString(dailyVolume);
const _totalVolume = toString(totalVolume);

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));

return {
timestamp: dayTimestamp,
dailyVolume: _dailyVolume ?? "0",
totalVolume: _totalVolume ?? "0",
};
};

const fetchVolumeBlast = async (timestamp: number): Promise<FetchResultVolume> => {
let dailyVolume = new BigNumber(0);
let totalVolume = new BigNumber(0);

const response_blast: IGraphResponse = await request(endpoint_blast, queryBlast, {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});
response_blast.dailyHistories.forEach((data) => {
dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume));
});
response_blast.totalHistories.forEach((data) => {
totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume));
});
Expand All @@ -145,6 +164,10 @@ const adapter: SimpleAdapter = {
fetch: fetchVolume,
start: 1698796800,
},
[CHAIN.BLAST]: {
fetch: fetchVolumeBlast,
start: 1698796800,
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion fees/core-markets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultFees> => {

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BASE]: {
[CHAIN.BLAST]: {
fetch: fetchVolume,
start: async () => 236678,
},
Expand Down
61 changes: 53 additions & 8 deletions fees/intent-x/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultFees> => {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});
const response_blast: IGraphResponse = await request(endpoint_blast, queryBlast, {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});

// Merging both responses
let dailyFees = new BigNumber(0);
Expand All @@ -109,9 +105,6 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultFees> => {
response.dailyHistories.forEach((data) => {
dailyFees = dailyFees.plus(new BigNumber(data.platformFee));
});
response_blast.dailyHistories.forEach((data) => {
dailyFees = dailyFees.plus(new BigNumber(data.platformFee));
});

let totalFees = new BigNumber(0);
response_0_8_0.totalHistories.forEach((data) => {
Expand All @@ -120,13 +113,61 @@ const fetchVolume = async (timestamp: number): Promise<FetchResultFees> => {
response.totalHistories.forEach((data) => {
totalFees = totalFees.plus(new BigNumber(data.platformFee));
});

dailyFees = dailyFees.dividedBy(new BigNumber(1e18));
totalFees = totalFees.dividedBy(new BigNumber(1e18));

const _dailyFees = toString(dailyFees);
const _totalFees = toString(totalFees);

const dailyUserFees = _dailyFees;
const dailyRevenue = _dailyFees;
const dailyProtocolRevenue = "0";
const dailyHoldersRevenue = _dailyFees;
const dailySupplySideRevenue = "0";

const totalUserFees = _totalFees;
const totalRevenue = _totalFees;
const totalProtocolRevenue = "0";
const totalSupplySideRevenue = "0";

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));

return {
timestamp: dayTimestamp,

dailyFees: _dailyFees ?? "0",
totalFees: _totalFees ?? "0",

dailyUserFees: dailyUserFees ?? "0",
dailyRevenue: dailyRevenue ?? "0",
dailyProtocolRevenue: dailyProtocolRevenue ?? "0",
dailyHoldersRevenue: dailyHoldersRevenue ?? "0",
dailySupplySideRevenue: dailySupplySideRevenue ?? "0",
totalUserFees: totalUserFees ?? "0",
totalRevenue: totalRevenue ?? "0",
totalProtocolRevenue: totalProtocolRevenue ?? "0",
totalSupplySideRevenue: totalSupplySideRevenue ?? "0",
};
};

const fetchVolumeBlast = async (timestamp: number): Promise<FetchResultFees> => {
let dailyFees = new BigNumber(0);
let totalFees = new BigNumber(0);

const response_blast: IGraphResponse = await request(endpoint_blast, queryBlast, {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp),
});
response_blast.dailyHistories.forEach((data) => {
dailyFees = dailyFees.plus(new BigNumber(data.platformFee));
});
response_blast.totalHistories.forEach((data) => {
totalFees = totalFees.plus(new BigNumber(data.platformFee));
});

dailyFees = dailyFees.dividedBy(new BigNumber(1e18));
totalFees = totalFees.dividedBy(new BigNumber(1e18));

const _dailyFees = toString(dailyFees);
const _totalFees = toString(totalFees);

Expand Down Expand Up @@ -167,6 +208,10 @@ const adapter: SimpleAdapter = {
fetch: fetchVolume,
start: 1698796800,
},
[CHAIN.BLAST]: {
fetch: fetchVolumeBlast,
start: 1698796800,
},
},
};
export default adapter;

0 comments on commit bbda451

Please sign in to comment.