Skip to content

Commit

Permalink
Merge pull request #1382 from dverso/master
Browse files Browse the repository at this point in the history
Add Smilee Finance Daily Stats
  • Loading branch information
dtmkeng authored Apr 5, 2024
2 parents 264f14c + c5fec71 commit e030a5e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions options/smilee-finance/index.ts
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;

0 comments on commit e030a5e

Please sign in to comment.