Adapter

Ribbon fees

Structured products protocol.

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

Showing TS source.
1export const name = 'Ribbon fees';
2export const version = '0.0.6';
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  };
16};
17
18export function setup(sdk: Context) {
19  const getFees = async (startDate: string, endDate: string, isProtocol: boolean): Promise<number> => {
20
21    const [startBlock, endBlock] = await Promise.all([
22      sdk.chainData.getBlockNumber(startDate, 'ethereum'),
23      sdk.chainData.getBlockNumber(endDate, 'ethereum')
24    ]);
25    const feeType = isProtocol ? 'totalFeeCollected' : 'totalPremiumEarned';
26
27    const query = `query {
28      start: vaults(id: "vaults", block: {number: ${startBlock}}) {
29        id
30        ${feeType}
31        underlyingAsset
32        underlyingSymbol
33      }
34      end: vaults(id: "vaults", block: {number: ${endBlock}}) {
35        id
36        ${feeType}
37        underlyingAsset
38        underlyingSymbol
39      }
40    }`;
41
42    const data = await sdk.graph.query('ribbon-finance/ribbon-v2', query, {});
43    let deltas = {};
44    let total = 0;
45
46    for (let i = 0; i < data['start'].length; i++) {
47      deltas[i] = data['end'][i][feeType] - data['start'][i][feeType];
48      const tokenContract = sdk.ethers.getERC20Contract(data['start'][i].underlyingAsset);
49      const [decimals, tokenPrice] = await Promise.all([
50        tokenContract.decimals(),
51        sdk.coinGecko.getHistoricalPrice(getCoingeckoId(data['start'][i].underlyingSymbol), endDate)
52      ]);
53
54      total += deltas[i] * tokenPrice / 10 ** decimals;
55    };
56
57    return total;
58  };
59
60  const getOneDayProtocolFees = (date: string) => {
61    const nextDay = sdk.date.offsetDaysFormatted(date, 1);
62    return getFees(date, nextDay, true);
63  };
64  const getOneDayTotalFees = (date: string) => {
65    const nextDay = sdk.date.offsetDaysFormatted(date, 1);
66    return getFees(date, nextDay, false);
67  };
68  const getProtocolFees = (startDate: string, endDate: string) => {
69    return getFees(startDate, endDate, true);
70  };
71  const getTotalFees = (startDate: string, endDate: string) => {
72    return getFees(startDate, endDate, false);
73  };
74
75  sdk.register({
76    id: 'ribbon',
77    queries: {
78      oneDayTotalFees: getOneDayTotalFees,
79      oneDayProtocolFees: getOneDayProtocolFees,
80      dateRangeTotalFees: getTotalFees,
81      dateRangeProtocolFees: getProtocolFees,
82    },
83    metadata: {
84      name: 'Ribbon',
85      icon: sdk.ipfs.getDataURILoader('QmaAyrAUA8Hc1KbtfqkJDcnMkqkSjr8cYGJAoxqVX4pxwA', 'image/webp'),
86      category: 'options',
87      description: 'Structured products protocol.',
88      feeDescription: 'Protocol revenues are a management fee, charged on the AUM and a performance fee, which is charged on premiums earned.',
89      blockchain: 'Ethereum',
90      source: 'The Graph Protocol',
91      website: 'https://www.ribbon.finance/',
92      protocolLaunch: '2021-09-13', // Data should be available from this date, onwards
93      tokenTicker: 'RBN',
94      tokenCoingecko: 'ribbon-finance', // The CoinGecko API ID
95      events: [],
96    },
97  })
98};
99

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.0.6

License

MIT

IPFS CID

QmPFHwdMYesEppZ7o1ZnCU1usKUWAHBZRjU2rat8LYsSRH

CID (source)

QmehKN5Z1EevyoR7jf3jPtM2xEoaKUve7zUJS5VaYXCgbT

Collections

fees

Author

0x080a44879fD0F8a7693E600C9360a89b46189858