-
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 #1382 from dverso/master
Add Smilee Finance Daily Stats
- Loading branch information
Showing
1 changed file
with
82 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,82 @@ | ||
import { gql, request } from "graphql-request"; | ||
import { Fetch, FetchResultOptions } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import * as sdk from "@defillama/sdk"; | ||
|
||
interface Trade { | ||
notionalUp: string; | ||
notionalDown: string; | ||
premium: string; | ||
} | ||
|
||
interface CumulativeData { | ||
cumulativeVolume: string; | ||
cumulativePremium: string; | ||
} | ||
|
||
const BASE_TOKEN = "0xaf88d065e77c8cc2239327c5edb3a432268e5831"; | ||
const SUBGRAPH_URL = "https://api.studio.thegraph.com/proxy/64770/smilee-finance/version/latest"; | ||
|
||
const tradeQuery = gql` | ||
query trades($timestampFrom: Int!, $timestampTo: Int!) { | ||
trades(where: {timestamp_gt: $timestampFrom, timestamp_lte: $timestampTo}) { | ||
notionalUp | ||
notionalDown | ||
premium | ||
} | ||
}`; | ||
|
||
const cumulativeStatsQuery = gql` | ||
query trades { | ||
protocolStatistics { | ||
cumulativeVolume | ||
cumulativePremium | ||
} | ||
}`; | ||
|
||
const fetch: Fetch = async (timestamp) => { | ||
const timestampFrom = timestamp - 60 * 60 * 24; | ||
|
||
const tradedNotional = new sdk.Balances({ chain: CHAIN.ARBITRUM, timestamp }); | ||
const tradedPremium = new sdk.Balances({ chain: CHAIN.ARBITRUM, timestamp }); | ||
// const totalTradedNotional = new sdk.Balances({ chain: CHAIN.ARBITRUM }); | ||
// const totalTradedPremium = new sdk.Balances({ chain: CHAIN.ARBITRUM }); | ||
|
||
// Fetching daily trades | ||
const tradeResponse = await request(SUBGRAPH_URL, tradeQuery, { | ||
timestampFrom, | ||
timestampTo: timestamp, | ||
}) as { trades: Trade[] }; | ||
|
||
tradeResponse.trades.forEach((trade: Trade) => { | ||
tradedNotional.add('usd', (Number(trade.notionalUp) + Number(trade.notionalDown)) / 1e6, { skipChain: true }); | ||
tradedPremium.add('usd', Number(trade.premium) / 1e6, { skipChain: true }); | ||
}); | ||
|
||
// Fetching cumulative statistics | ||
// const statsResponse = await request(SUBGRAPH_URL, cumulativeStatsQuery) as { protocolStatistics: CumulativeData }; | ||
// totalTradedNotional.add('usd', Number() / 1e6); | ||
// totalTradedPremium.add('usd', Number(statsResponse.protocolStatistics.cumulativePremium) / 1e6); | ||
|
||
// Building fetch result | ||
const fetchResult: FetchResultOptions = { | ||
timestamp: timestampFrom, | ||
dailyNotionalVolume: await tradedNotional.getUSDString(), | ||
dailyPremiumVolume: await tradedPremium.getUSDString(), | ||
// totalNotionalVolume: BigInt.(statsResponse.protocolStatistics.cumulativeVolume) / 1e6, | ||
// totalPremiumVolume: Number(statsResponse.protocolStatistics.cumulativePremium) / 1e6 | ||
}; | ||
|
||
return fetchResult; | ||
}; | ||
|
||
const adapter = { | ||
adapter: { | ||
[CHAIN.ARBITRUM]: { | ||
fetch, | ||
start: 1710440552 | ||
}, | ||
} | ||
}; | ||
|
||
export default adapter; |