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
1export const name = 'ENS Treasuries';
2export const version = '0.2.2';
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://cryptostats-api-proxy.vercel.app/api/v1/zapper/${key}`)
17 .then(result => {
18 if (result.success) {
19 return result.value
20 }
21 sdk.log.error(`https://cryptostats-api-proxy.vercel.app/api/v1/zapper/${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 [portfolio, vestingPortfolio, eth] = await Promise.all([
35 getPortfolio(TREASURY_ADDRESSES),
36 getPortfolio(VESTING_ADDRESS),
37 getRegistrarETH(),
38 ])
39
40 let totalValue = 0;
41
42
43 for (const portItem of portfolio) {
44 if (portItem.context.symbol === 'ETH') {
45 totalValue += portItem.balanceUSD + (eth * portItem.context.price)
46 } else {
47 totalValue += portItem.balanceUSD;
48 }
49
50 }
51
52 for (const portItem of vestingPortfolio) {
53 totalValue += portItem.balanceUSD;
54 }
55 return totalValue
56 };
57
58
59 const getLiquidTreasuryInUSD = async () => {
60 const [portfolio, eth] = await Promise.all([
61 getPortfolio(TREASURY_ADDRESSES),
62 getRegistrarETH(),
63 ])
64
65 let totalLiquid = 0;
66
67 for (const portItem of portfolio) {
68 if (portItem.context.symbol === 'ETH') {
69 totalLiquid += portItem.balanceUSD + (eth * portItem.context.price)
70 } else {
71 totalLiquid += portItem.balanceUSD
72 }
73 }
74 return totalLiquid
75 }
76
77 const getTreasuryPortfolio = async () => {
78 const [portfolio, vestingPortfolio, eth] = await Promise.all([
79 getPortfolio(TREASURY_ADDRESSES),
80 getPortfolio(VESTING_ADDRESS),
81 getRegistrarETH(),
82 ])
83
84 const fullPortfolio = [];
85
86 for (const portItem of portfolio) {
87 if (portItem.context.symbol === 'ETH') {
88 fullPortfolio.push({
89 address: portItem.address,
90 amount: portItem.context.balance + eth,
91 name: portItem.context.symbol,
92 symbol:portItem.context.symbol,
93 icon:portItem.displayProps.images[0],
94 price:portItem.context.price,
95 value:(portItem.context.balance + eth) * portItem.context.price
96 })
97 } else {
98 fullPortfolio.push({
99 address: portItem.address,
100 amount: portItem.context.balance,
101 name: portItem.context.symbol,
102 symbol:portItem.context.symbol,
103 icon:portItem.displayProps.images[0],
104 price:portItem.context.price,
105 value:portItem.balanceUSD,
106 })
107 }
108 }
109
110 for (const portItem of vestingPortfolio) {
111 fullPortfolio.push({
112 address: portItem.address,
113 amount: portItem.context.balance,
114 name: portItem.context.symbol,
115 symbol:portItem.context.symbol,
116 icon:portItem.displayProps.images[0],
117 price:portItem.context.price,
118 value:portItem.balanceUSD,
119 vesting: true
120 })
121 }
122 return fullPortfolio;
123 }
124
125
126 async function getSnapshotProposals(id: string) {
127 const response = await sdk.http.post('https://hub.snapshot.org/graphql', {
128 query: `query Proposals($space: String!) {
129 proposals (
130 first: 5,
131 skip: 0,
132 where: { space_in: [$space] },
133 orderBy: "created",
134 orderDirection: desc
135 ) {
136 id
137 title
138 start
139 end
140 state
141 link
142 }
143 }`,
144 variables: { space: id },
145 });
146
147 return response.data.proposals;
148 }
149
150 sdk.register({
151 id: 'ens',
152 queries: {
153 currentTreasuryUSD: getTreasuryInUSD,
154 currentLiquidTreasuryUSD: getLiquidTreasuryInUSD,
155 currentTreasuryPortfolio: getTreasuryPortfolio,
156 recentProposals: () => getSnapshotProposals('ens.eth'),
157 },
158 metadata: {
159 icon: sdk.ipfs.getDataURILoader('QmVmFQeYcLjeEm2fFhyyS762KytMQQhwdEXyGXAid1Rf8B', 'image/svg+xml'),
160 name: 'ENS',
161 website: 'https://ens.domains',
162 treasuries: [REGISTRAR, GNOSIS, TIMELOCK, VESTING_ADDRESS],
163 },
164 })
165}
166
It's something off?
Report it to the discussion board on Discord, we will take care of it.