Sub-Adapters 1
Preview and test each sub adapter.
Ribbon (ribbon)
Metadata
- ID
- ribbon
- name
"Ribbon"
- icon
- category
"options"
- description
"Structured products protocol."
- feeDescription
"Protocol revenues are a management fee, charged on the AUM and a performance fee, which is charged on premiums earned."
- blockchain
"Ethereum"
- source
"The Graph Protocol"
- website
"https://www.ribbon.finance/"
- protocolLaunch
"2021-09-13"
- tokenTicker
"RBN"
- tokenCoingecko
"ribbon-finance"
- events
[]
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
1export const name = 'Ribbon fees';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5function getCoingeckoId(tokenSymbol: string) {
6 switch (tokenSymbol) {
7 case 'WETH':
8 return 'ethereum';
9 case 'WBTC':
10 return 'wrapped-bitcoin';
11 case 'AAVE':
12 return 'aave';
13 case 'USDC':
14 return 'usd-coin';
15 case 'APE':
16 return 'apecoin';
17 default:
18 throw new Error(`Unknown asset ${tokenSymbol}`)
19 };
20};
21
22export function setup(sdk: Context) {
23 const getFees = async (startDate: string, endDate: string, isProtocol: boolean): Promise<number> => {
24
25 const [startBlock, endBlock] = await Promise.all([
26 sdk.chainData.getBlockNumber(startDate, 'ethereum'),
27 sdk.chainData.getBlockNumber(endDate, 'ethereum')
28 ]);
29 const feeType = isProtocol ? 'totalFeeCollected' : 'totalPremiumEarned';
30
31 const query = `query {
32 start: vaults(id: "vaults", block: {number: ${startBlock}}) {
33 id
34 ${feeType}
35 underlyingAsset
36 underlyingSymbol
37 }
38 end: vaults(id: "vaults", block: {number: ${endBlock}}) {
39 id
40 ${feeType}
41 underlyingAsset
42 underlyingSymbol
43 }
44 }`;
45
46 const data = await sdk.graph.query('ribbon-finance/ribbon-v2', query, {});
47 let deltas = {};
48 let total = 0;
49
50 for (let i = 0; i < data['start'].length; i++) {
51 deltas[i] = data['end'][i][feeType] - data['start'][i][feeType];
52 const tokenContract = sdk.ethers.getERC20Contract(data['start'][i].underlyingAsset);
53 const [decimals, tokenPrice] = await Promise.all([
54 tokenContract.decimals(),
55 sdk.coinGecko.getHistoricalPrice(getCoingeckoId(data['start'][i].underlyingSymbol), endDate)
56 ]);
57
58 total += deltas[i] * tokenPrice / 10 ** decimals;
59 };
60
61 return total;
62 };
63
64 const getOneDayProtocolFees = async (date: string) => {
65 if (new Date(date).getDay() !== 5) {
66 return 0;
67 }
68 const nextDay = sdk.date.offsetDaysFormatted(date, 1);
69 return getFees(date, nextDay, true);
70 };
71 const getOneDayTotalFees = async (date: string) => {
72 if (new Date(date).getDay() !== 5) {
73 return 0;
74 }
75 const nextDay = sdk.date.offsetDaysFormatted(date, 1);
76 return getFees(date, nextDay, false);
77 };
78 const getProtocolFees = (startDate: string, endDate: string) => {
79 return getFees(startDate, endDate, true);
80 };
81 const getTotalFees = (startDate: string, endDate: string) => {
82 return getFees(startDate, endDate, false);
83 };
84
85 sdk.register({
86 id: 'ribbon',
87 queries: {
88 oneDayTotalFees: getOneDayTotalFees,
89 oneDayProtocolFees: getOneDayProtocolFees,
90 dateRangeTotalFees: getTotalFees,
91 dateRangeProtocolFees: getProtocolFees,
92 },
93 metadata: {
94 name: 'Ribbon',
95 icon: sdk.ipfs.getDataURILoader('QmR6R8v4GNqvYR5WcvjY1W5MRxuKoJTNf6L7ESGkBcj164', 'image/svg+xml'),
96 category: 'options',
97 description: 'Structured products protocol.',
98 feeDescription: 'Protocol revenues are a management fee, charged on the AUM and a performance fee, which is charged on premiums earned.',
99 blockchain: 'Ethereum',
100 source: 'The Graph Protocol',
101 website: 'https://www.ribbon.finance/',
102 protocolLaunch: '2021-09-13',
103 tokenTicker: 'RBN',
104 tokenCoingecko: 'ribbon-finance',
105 events: [],
106 },
107 })
108};
109
It's something off?
Report it to the discussion board on Discord, we will take care of it.