-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1362 from web3dev00/master
OptionBlitz
- Loading branch information
Showing
2 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |