Adapter

dxDAO Treasury

DXdao is a decentralized collective that builds and governs decentralized products and services.

Sub-Adapters 1

Preview and test each sub adapter.

DXdao (dxdao)

Metadata

ID
dxdao
icon
name

"DXdao"

description

"DXdao is a decentralized collective that builds and governs decentralized products and services."

website

"https://dxdao.eth.link"

governanceSite

"https://alchemy.daostack.io/dao/0x519b70055af55a007110b4ff99b0ea33071c720a"

governanceForum

"https://daotalk.org/c/dx-dao"

governanceModel

""

treasuries

[ "0x519b70055af55a007110b4ff99b0ea33071c720a", "0xa1d65e8fb6e87b60feccbc582f7f97804b725521" ]

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'dxDAO Treasury';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5const TREASURY_ADDRESS = '0x519b70055af55a007110b4ff99b0ea33071c720a'
6const DXD_TOKEN = '0xa1d65e8fb6e87b60feccbc582f7f97804b725521'
7const USDC_TOKEN = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'
8
9export async function setup(sdk: Context) {
10  let treasuryPortfolioPromise: Promise<any> | null
11  const getTreasuryPortfolio = (): Promise<any> => {
12    if (!treasuryPortfolioPromise) {
13      treasuryPortfolioPromise = sdk.http.get(`https://cryptostats-api-proxy.vercel.app/api/v1/zapper/${TREASURY_ADDRESS}`)
14        .then(result => {
15          if (result.success) {
16            return result.value
17          }
18          throw new Error(result.error)
19        })
20    }
21    return treasuryPortfolioPromise
22  }
23
24  const getBondingCurve = async () => {
25    const [dxdPrice, dxdBalance, usdcBalance] = await Promise.all([
26      sdk.coinGecko.getCurrentPrice('dxdao'),
27      sdk.ethers.getERC20Contract(DXD_TOKEN).balanceOf(DXD_TOKEN),
28      sdk.ethers.getERC20Contract(USDC_TOKEN).balanceOf(DXD_TOKEN),
29    ])
30
31    const totalValue = (usdcBalance.toString() / 1e6) + (dxdPrice * dxdBalance.toString() / 1e18)
32    const portfolio = [
33      {
34        address: USDC_TOKEN,
35        amount: usdcBalance.toString() / 1e6,
36        value: usdcBalance.toString() / 1e6,
37        price: 1,
38        name: 'USDC',
39        symbol: 'USDC',
40        icon: `https://s3.amazonaws.com/token-icons/${USDC_TOKEN}.png`,
41      },
42      {
43        address: DXD_TOKEN,
44        amount: dxdBalance.toString() / 1e18,
45        value: dxdPrice * dxdBalance.toString() / 1e18,
46        price: dxdPrice,
47        name: 'DXdao',
48        symbol: 'DXD',
49        icon: `https://s3.amazonaws.com/token-icons/${DXD_TOKEN}.png`,
50      },
51    ]
52
53    return { totalValue, portfolio }
54  }
55
56  const getTreasuryInUSD = async () => {
57    const [treasury, { totalValue: bondingCurveVal }] = await Promise.all([
58      getTreasuryPortfolio(),
59      getBondingCurve(),
60    ])
61
62    let totalValue = 0;
63
64    for (const portItem of treasury) {
65        totalValue += portItem.balanceUSD;
66    }
67
68    return totalValue + bondingCurveVal
69  }
70
71  const getPortfolio = async () => {
72    const [reservePortfolio, { portfolio: bondingCurvePortfolio }] = await Promise.all([
73      getTreasuryPortfolio(),
74      getBondingCurve(),
75    ])
76
77    let portAssets = [];
78
79    for (const portItem of reservePortfolio) {
80      if (portItem.context.symbol === "DXD") {
81        portAssets.push({
82          address: portItem.address, 
83          amount: portItem.context.balance + bondingCurvePortfolio[0].amount,
84          name: portItem.context.symbol, 
85          symbol:portItem.context.symbol, 
86          icon:portItem.displayProps.images[0],
87          price:portItem.context.price, 
88          value:portItem.balanceUSD + (bondingCurvePortfolio[0].amount * portItem.context.price)
89        }) 
90      } else if (portItem.context.symbol === "USDC") {
91        portAssets.push({
92          address: portItem.address, 
93          amount: portItem.context.balance + bondingCurvePortfolio[1].amount,
94          name: portItem.context.symbol, 
95          symbol:portItem.context.symbol, 
96          icon:portItem.displayProps.images[0],
97          price:portItem.context.price, 
98          value:portItem.balanceUSD + (bondingCurvePortfolio[1].amount * portItem.context.price)
99        }) 
100      } else {
101        portAssets.push({
102          address: portItem.address, 
103          amount: portItem.context.balance,
104          name: portItem.context.symbol, 
105          symbol:portItem.context.symbol, 
106          icon:portItem.displayProps.images[0],
107          price:portItem.context.price, 
108          value:portItem.balanceUSD,
109        })   
110      }
111    }
112
113    return portAssets
114  }
115
116  sdk.register({
117    id: 'dxdao',
118    queries: {
119      currentTreasuryUSD: getTreasuryInUSD,
120      currentLiquidTreasuryUSD: getTreasuryInUSD,
121      currentTreasuryPortfolio: getPortfolio,
122      recentProposals: async () => [],
123    },
124    metadata: {
125      icon: sdk.ipfs.getDataURILoader('QmVvZF3qMp8fx9dpYvkCMV849U6oLaKJJA5BxxUCmabvb4', 'image/svg+xml'),
126      name: 'DXdao',
127      description: 'DXdao is a decentralized collective that builds and governs decentralized products and services.',
128      website: 'https://dxdao.eth.link',
129      governanceSite: 'https://alchemy.daostack.io/dao/0x519b70055af55a007110b4ff99b0ea33071c720a',
130      governanceForum: 'https://daotalk.org/c/dx-dao',
131      governanceModel: '',
132      treasuries: [TREASURY_ADDRESS, DXD_TOKEN],
133    },
134  })
135}
136

It's something off?

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

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

QmZ46Zfin7nkhqznTxvFgT6ubPWyuxUDzo1f6fYF2pVjCw

CID (source)

QmS8yRqAcrh89Ag7R5atrtiYJ5vLA1pjUYvJmHs4mYAhR6

Collections

Author

0x70c0EE6bd4a42e9Dc5487e30a765370b65e670A5