Skip to content

Commit

Permalink
Merge pull request #1362 from web3dev00/master
Browse files Browse the repository at this point in the history
OptionBlitz
  • Loading branch information
waynebruce0x authored Apr 4, 2024
2 parents 2888964 + 4d7be30 commit d5e444f
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
87 changes: 87 additions & 0 deletions fees/optionBlitz/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import ADDRESSES from "../../helpers/coreAssets.json";
import { FetchResult, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { gql, request } from "graphql-request";
import * as sdk from "@defillama/sdk";
import { getTimestampAtStartOfDay } from "../../utils/date";

interface IDayDataGraph {
id: string;
rewardsUsdc: string;
lossesUsdc: string;
}
interface ITotalDataGraph {
id: string;
totalRewardsUsdc: string;
totalLossesUsdc: string;
timestamp: string;
}

const URL = "https://api.thegraph.com/subgraphs/name/web3dev00/optionblitz";

const fetch = async (timestamp: number): Promise<FetchResult> => {
const dayTimestamp = getTimestampAtStartOfDay(timestamp);
const chain = CHAIN.ARBITRUM;
const balances = new sdk.Balances({ chain });
const balances1 = new sdk.Balances({ chain });
const dayDataQuery = gql`
{
dayData(id: ${dayTimestamp * 1000}) {
id
rewardsUsdc
lossesUsdc
}
}`;

const totalDataQuery = gql`
{
totalDatas {
id
totalRewardsUsdc
totalLossesUsdc
timestamp
}
}`

const dayDataResponse: IDayDataGraph = (await request(URL, dayDataQuery)).dayData;
const totalDataResponse: ITotalDataGraph[] = (await request(URL, totalDataQuery)).totalDatas;

let perDayIncome = 0;
let totalIncome = 0;

if (dayDataResponse) {
perDayIncome = Math.abs(Number(dayDataResponse.rewardsUsdc) - Number(dayDataResponse.lossesUsdc));
}

if (totalDataResponse.length > 0) {
totalIncome = Math.abs(Number(totalDataResponse[0].totalRewardsUsdc) - Number(totalDataResponse[0].totalLossesUsdc));
}

balances.add(ADDRESSES[chain].USDC_CIRCLE, perDayIncome);
balances1.add(ADDRESSES[chain].USDC_CIRCLE, totalIncome);


return {
dailyFees: await balances.getUSDString(),
totalFees: await balances1.getUSDString(),
timestamp: dayTimestamp,
};
};

const methodology = {
Fees: "Trade collateral collected.",
Revenue: "Platform profit, (trader losses minus trader wins).",
};

const adapters: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetch as any,
start: 194784191,
meta: {
methodology: methodology,
},
},
},
};
export default adapters;
78 changes: 78 additions & 0 deletions options/optionBlitz/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import ADDRESSES from "../../helpers/coreAssets.json";
import { FetchResult, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { gql, request } from "graphql-request";
import * as sdk from "@defillama/sdk";
import { get } from "http";
import { getCurrentUnixTimestamp, getTimestampAtStartOfDay } from "../../utils/date";

interface IDayDataGraph {
id: string;
volumeUsdc: string;
}
interface ITotalDataGraph {
id: string;
totalVolumeUsdc: string;
timestamp: string;
}

const URL = "https://api.thegraph.com/subgraphs/name/web3dev00/optionblitz";

const fetch = async (timestamp: number): Promise<FetchResult> => {
const dayTimestamp = getTimestampAtStartOfDay(timestamp);
const chain = CHAIN.ARBITRUM;
const balances = new sdk.Balances({ chain });
const balances1 = new sdk.Balances({ chain });

const dayDataQuery = gql`
{
dayData(id: ${dayTimestamp * 1000}) {
id
volumeUsdc
}
}`;

const totalDataQuery = gql`
{
totalDatas {
id
totalVolumeUsdc
timestamp
}
}`

const dayDataResponse: IDayDataGraph = (await request(URL, dayDataQuery)).dayData;
const totalDataResponse: ITotalDataGraph[] = (await request(URL, totalDataQuery)).totalDatas;

let dailyVolume = BigInt(0);
let totalVolume = BigInt(0);

if (dayDataResponse) {
dailyVolume = BigInt(dayDataResponse.volumeUsdc);
}

if (totalDataResponse.length > 0) {
totalVolume = BigInt(totalDataResponse[0].totalVolumeUsdc);
}

balances.add(ADDRESSES.arbitrum.USDC_CIRCLE, dailyVolume.toString());
balances1.add(ADDRESSES.arbitrum.USDC_CIRCLE, totalVolume.toString());

return {
timestamp: dayTimestamp,
dailyNotionalVolume: 0,
dailyPremiumVolume: await balances.getUSDString(),
totalNotionalVolume: 0,
totalPremiumVolume: await balances1.getUSDString(),
};
};

const adapters: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetch as any,
start: 194784191,
},
},
};
export default adapters;

0 comments on commit d5e444f

Please sign in to comment.