forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
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 DefiLlama#1405 from HbarSuite/feature/hsuite
Added HbarSuite DEX dimension adapter
- Loading branch information
Showing
1 changed file
with
85 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,85 @@ | ||
import { SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import axios from "axios"; | ||
import asyncRetry from "async-retry"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
const BigNumber = require("bignumber.js"); | ||
|
||
/* | ||
* HbarSuite is a decentralized network of features built on Hedera Hashgraph. | ||
* It is a suite of products that are built on top of the layer 1, | ||
* relying on the security and speed of the Hedera network. | ||
* | ||
* HbarSute Network relies entirely on HCS (Hedera Consensus Service) for its data storage, | ||
* and HFS (Hedera File Service) for its file storage. | ||
* | ||
* It also uses NFTs (Non-Fungible Tokens) to represent the Liquidity Providers' shares in the pools, | ||
* storing the data on IPFS. | ||
*/ | ||
|
||
// Listing the urls of the nodes that are used by HbarSuite to connect to the Hedera Mainnet. | ||
const nodes = [ | ||
'https://mainnet-sn1.hbarsuite.network', | ||
'https://mainnet-sn2.hbarsuite.network', | ||
'https://mainnet-sn3.hbarsuite.network', | ||
'https://mainnet-sn4.hbarsuite.network', | ||
'https://mainnet-sn5.hbarsuite.network', | ||
'https://mainnet-sn6.hbarsuite.network', | ||
'https://mainnet-sn7.hbarsuite.network', | ||
'https://mainnet-sn8.hbarsuite.network' | ||
] | ||
|
||
interface IHbarSuiteVolumes { | ||
ticker: string | ||
pool: string | ||
daily: string | ||
total: string | ||
} | ||
|
||
const methodology = { | ||
UserFees: "User pays 0.3% fees on each swap.", | ||
ProtocolRevenue: "Liquidity Providers earn a fixed APR in HSUITE tokens.", | ||
Revenue: "All revenue generated comes from user fees.", | ||
Fees: "All fees comes from the user." | ||
} | ||
|
||
const fetch = async (timestamp: number) => { | ||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); | ||
|
||
// generating a random number, so to grab a random smart-node from the network.. | ||
let randomNode = nodes[Math.floor(Math.random() * nodes.length)]; | ||
|
||
let volumesForPools: Array<IHbarSuiteVolumes> = (await asyncRetry(async() => await axios.get( | ||
`${randomNode}/dex/analytics/volumes` | ||
))).data; | ||
|
||
let dailyVolumes = volumesForPools.reduce((acc, pool) => { | ||
acc = new BigNumber(acc).plus(pool.daily); | ||
return acc; | ||
}, "0"); | ||
|
||
let allTimeVolumes = volumesForPools.reduce((acc, pool) => { | ||
acc = new BigNumber(acc).plus(pool.total); | ||
return acc; | ||
}, "0"); | ||
|
||
return { | ||
totalVolume: allTimeVolumes.toString(), | ||
dailyVolume: dailyVolumes.toString(), | ||
timestamp: dayTimestamp | ||
}; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.HEDERA]: { | ||
fetch, | ||
start: async () => 1672531200, | ||
meta: { | ||
methodology | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |