Sub-Adapters 1

Preview and test each sub adapter.

ENS (ens)

Metadata

ID
ens
icon
name

"ENS"

website

"https://ens.domains"

treasuries

[ "0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5", "0xCF60916b6CB4753f58533808fA610FcbD4098Ec0", "0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7", "0xd7A029Db2585553978190dB5E85eC724Aa4dF23f" ]

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'ENS Treasuries';
2export const version = '0.1.0';
3export const license = 'MIT';
4
5const REGISTRAR = '0x283Af0B28c62C092C9727F1Ee09c02CA627EB7F5' // Registrar controller (fee collection)
6const GNOSIS = '0xCF60916b6CB4753f58533808fA610FcbD4098Ec0' // Gnosis safe
7const TIMELOCK = '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' // Timelock
8const VESTING_ADDRESS = '0xd7A029Db2585553978190dB5E85eC724Aa4dF23f'
9
10const TREASURY_ADDRESSES = GNOSIS + ',' + TIMELOCK
11
12export async function setup(sdk: Context) {
13  let portfolioCache: { [address: string]: Promise<any> } = {}
14  const getPortfolio = (key: string): Promise<any> => {
15    if (!portfolioCache[key]) {
16      portfolioCache[key] = sdk.http.get(`https://zerion-api.vercel.app/api/portfolio/${key}`)
17        .then(result => {
18          if (result.success) {
19            return result.value
20          }
21          sdk.log.error(`https://zerion-api.vercel.app/api/portfolio/${key}`, result)
22          throw new Error(result.error)
23        })
24    }
25    return portfolioCache[key]
26  }
27
28  const getRegistrarETH = async () => {
29    const balance = await sdk.ethers.getProvider('ethereum').getBalance(REGISTRAR)
30    return parseFloat(sdk.ethers.utils.formatEther(balance))
31  }
32
33  const getTreasuryInUSD = async () => {
34    const [treasury, vesting, eth] = await Promise.all([
35      getPortfolio(TREASURY_ADDRESSES),
36      getPortfolio(VESTING_ADDRESS),
37      getRegistrarETH(),
38    ])
39
40    for (const item of treasury.portfolio) {
41      if (item.symbol === 'ETH') {
42        return treasury.totalValue + vesting.totalValue + (eth * item.price)
43      }
44    }
45    throw new Error('No ETH')
46  }
47
48  const getLiquidTreasuryInUSD = async () => {
49    const [treasury, eth] = await Promise.all([
50      getPortfolio(TREASURY_ADDRESSES),
51      getRegistrarETH(),
52    ])
53
54    for (const item of treasury.portfolio) {
55      if (item.symbol === 'ETH') {
56        return treasury.totalValue + (eth * item.price)
57      }
58    }
59    throw new Error('No ETH')
60  }
61
62  const getTreasuryPortfolio = async () => {
63    const [treasury, vesting, eth] = await Promise.all([
64      getPortfolio(TREASURY_ADDRESSES),
65      getPortfolio(VESTING_ADDRESS),
66      getRegistrarETH(),
67    ])
68
69    const portfolio = [
70      ...treasury.portfolio,
71      ...vesting.portfolio.map((portfolioItem: any) => ({ ...portfolioItem, vesting: true })),
72    ]
73
74    for (const item of portfolio) {
75      if (item.symbol === 'ETH') {
76        item.amount += eth
77        item.value += eth * item.price
78        return portfolio
79      }
80    }
81    throw new Error('No ETH')
82  }
83
84  async function getSnapshotProposals(id: string) {
85    const response = await sdk.http.post('https://hub.snapshot.org/graphql', {
86      query: `query Proposals($space: String!) {
87        proposals (
88          first: 5,
89          skip: 0,
90          where: { space_in: [$space] },
91          orderBy: "created",
92          orderDirection: desc
93        ) {
94          id
95          title
96          start
97          end
98          state
99          link
100        }
101      }`,
102      variables: { space: id },
103    });
104
105    return response.data.proposals;
106  }
107
108  sdk.register({
109    id: 'ens',
110    queries: {
111      currentTreasuryUSD: getTreasuryInUSD,
112      currentLiquidTreasuryUSD: getLiquidTreasuryInUSD,
113      currentTreasuryPortfolio: getTreasuryPortfolio,
114      recentProposals: () => getSnapshotProposals('ens.eth'),
115    },
116    metadata: {
117      icon: sdk.ipfs.getDataURILoader('QmVmFQeYcLjeEm2fFhyyS762KytMQQhwdEXyGXAid1Rf8B', 'image/svg+xml'),
118      name: 'ENS',
119      website: 'https://ens.domains',
120      treasuries: [REGISTRAR, GNOSIS, TIMELOCK, VESTING_ADDRESS],
121    },
122  })
123}
124

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

QmbkYifgnC442Ei9tMhA5VJXvcxZ8M12sK4vNPMtSmgcnZ

CID (source)

QmX3PtcZu2kPkAaV1hDheJQdWdJ4zBjZTDwD85YthwVdZd

Collections

Author

mihal.eth