-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add adapter for origami (#10168)
* feat: add adapter for origami * code refactor --------- Co-authored-by: 0xl2 <[email protected]> Co-authored-by: g1nt0ki <[email protected]>
- Loading branch information
1 parent
de8114c
commit 976ed71
Showing
1 changed file
with
30 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,30 @@ | ||
const { cachedGraphQuery } = require('../helper/cache') | ||
|
||
const GRAPH_URLS = { | ||
ethereum: "https://api.thegraph.com/subgraphs/name/templedao/origami-mainnet", // ethereum | ||
arbitrum: "https://api.thegraph.com/subgraphs/name/templedao/origami-arb", // arbitrum | ||
} | ||
|
||
module.exports = { | ||
doublecounted: true, | ||
} | ||
|
||
Object.keys(GRAPH_URLS).forEach(chain => { | ||
const endpoint = GRAPH_URLS[chain] | ||
module.exports[chain] = { | ||
tvl: async (api) => { | ||
const { metrics: [{ investmentVaults }] } = await cachedGraphQuery('origami/' + chain, endpoint, '{ metrics { investmentVaults { id } } }') | ||
const vaults = investmentVaults.map(vault => vault.id) | ||
let tokens = await api.multiCall({ abi: 'address:reserveToken', calls: vaults }) | ||
if (chain === 'arbitrum') | ||
tokens = await api.multiCall({ abi: 'address:baseToken', calls: tokens }) | ||
|
||
const decimals = await api.multiCall({ abi: 'uint8:decimals', calls: vaults }) | ||
const supplies = await api.multiCall({ abi: 'uint256:totalSupply', calls: vaults }) | ||
const reserves = await api.multiCall({ abi: 'uint256:reservesPerShare', calls: vaults }) | ||
const bals = reserves.map((reserve, i) => reserve * supplies[i] / 10 ** decimals[i]) | ||
console.log(tokens, bals, vaults, api.chain) | ||
api.add(tokens, bals) | ||
} | ||
} | ||
}) |