Adapter

Ren Protocol Fees

Ren Protocol is a protocol for cross-chain asset transfers.

Sub-Adapters 1

Preview and test each sub adapter.

Ren Protocol (ren)

Metadata

ID
ren
name

"Ren Protocol"

icon
category

"xchain"

description

"Ren Protocol is a protocol for cross-chain asset transfers."

feeDescription

"Transfer fees are paid by users to node operators (Darknodes)."

source

"RenVM Tracker"

website

"https://renproject.io"

tokenTicker

"REN"

tokenCoingecko

"republic-protocol"

protocolLaunch

"2020-05-27"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Ren Protocol Fees';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5const ONE_DAY = 86400;
6
7export function setup(sdk: Context) {
8  const getFees = async (date: string): Promise<number> => {
9    const snapshotTimestamp = sdk.date.dateToTimestamp(date);
10    const dayBeforeSnapshotTimestamp = snapshotTimestamp - ONE_DAY;
11
12    const data = await sdk.graph.query('https://stats.renproject.io/', `{
13      current: Snapshot(timestamp: "${snapshotTimestamp}") {
14        fees {
15          asset
16          amount
17        }
18        prices {
19          asset
20          priceInUsd
21          decimals
22        }
23      }
24      dayAgo: Snapshot(timestamp: "${dayBeforeSnapshotTimestamp}") {
25        fees {
26          asset
27          amount
28        }
29      }
30    }`);
31
32    const dayAgo = data.dayAgo.fees.reduce(
33      (acc, fees) => ({ ...acc, [fees.asset]: fees.amount }),
34      {}
35    );
36
37    const current = data.current.fees.reduce(
38      (acc, fees) => ({ ...acc, [fees.asset]: fees.amount }),
39      {}
40    );
41
42    const prices = data.current.prices.reduce(
43      (acc, prices) => ({ ...acc, [prices.asset]: prices }),
44      {}
45    );
46
47    const assets = Object.keys(current);
48
49    return assets.reduce((acc: number, asset: string) => {
50      const difference = current[asset] - (dayAgo[asset] || 0);
51      if (!prices[asset]) {
52        return acc;
53      }
54      const decimals = prices[asset].decimals;
55      const priceInUsd = prices[asset].priceInUsd;
56      const differentInUsd = (difference / 10 ** decimals) * priceInUsd;
57      return acc + (differentInUsd || 0);
58    }, 0);
59  };
60
61  sdk.register({
62    id: 'ren',
63    queries: {
64      oneDayTotalFees: getFees,
65    },
66    metadata: {
67      name: 'Ren Protocol',
68      icon: sdk.ipfs.getDataURILoader('QmQnRxS7jjLXVPcUJNtkidddynYiZQ4t9UpGMaAFuKbK4H', 'image/svg+xml'),
69      category: 'xchain',
70      description: 'Ren Protocol is a protocol for cross-chain asset transfers.',
71      feeDescription: 'Transfer fees are paid by users to node operators (Darknodes).',
72      source: 'RenVM Tracker',
73      website: 'https://renproject.io',
74      tokenTicker: 'REN',
75      tokenCoingecko: 'republic-protocol',
76      protocolLaunch: '2020-05-27',
77    },
78  })
79}
80

It's something off?

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

Adapter Info

Version

0.1.0

License

MIT

IPFS CID

QmUom2CDUNafKQSKbisC9ZVugbb22Sjfuq9Z9rHVWZ6HQL

CID (source)

QmazMjNhFp5emv9GHxssSDZbjjVNcgL6JURpeyxcyPQCrL

Collections

Author

mihal.eth