Sub-Adapters 1

Preview and test each sub adapter.

MakerDAO (makerdao)

Metadata

ID
makerdao
icon
category

"app"

name

"MakerDAO"

website

"https://makerdao.com"

governanceSite

"https://vote.makerdao.com"

governanceForum

"https://forum.makerdao.com"

governanceModel

""

treasuries

[ "0xbe8e3e3618f7474f8cb1d074a26affef007e98fb" ]

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'MakerDAO Treasury';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5const VAT_ADDRESS = '0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b'
6const PAUSE_ADDRESS = '0xbe8e3e3618f7474f8cb1d074a26affef007e98fb'
7
8const vatABI = [
9  'function dai(address holder) external view returns (uint256)',
10  'function sin(address holder) external view returns (uint256)',
11]
12
13export async function setup(sdk: Context) {
14  let pausePortfolioPromise: Promise<any> | null
15  const getPausePortfolio = (): Promise<any> => {
16    if (!pausePortfolioPromise) {
17      pausePortfolioPromise = sdk.http.get(`https://cryptostats-api-proxy.vercel.app/api/v1/zapper/${PAUSE_ADDRESS}`)
18        .then(result => {
19          if (result.success) {
20            return result.value
21          }
22          throw new Error(result.error)
23        })
24    }
25    return pausePortfolioPromise
26  }
27
28  const getDaiSurplus = async () => {
29    const vat = sdk.ethers.getContract(VAT_ADDRESS, vatABI)
30    const [dai, sin] = await Promise.all([
31      vat.dai('0xA950524441892A31ebddF91d3cEEFa04Bf454466'),
32      vat.sin('0xA950524441892A31ebddF91d3cEEFa04Bf454466'),
33    ])
34
35    const daiSurplus = dai.sub(sin).toString() / 1e45
36    return daiSurplus
37  }
38
39  const getTreasuryInUSD = async () => {
40    const [daiSurplus, pausePortfolio] = await Promise.all([
41      getDaiSurplus(),
42      getPausePortfolio(),
43    ])
44
45    let totalValue = 0;
46
47    for (const portItem of pausePortfolio) {
48      if (portItem.context.symbol === 'DAI') {
49        totalValue += (daiSurplus + portItem.context.balance) * portItem.context.price
50      } else {
51        totalValue += portItem.balanceUSD;
52      }
53  }
54  return totalValue
55  }
56
57  const getPortfolio = async () => {
58    const [pausePortfolio, daiSurplus] = await Promise.all([
59      getPausePortfolio(),
60      getDaiSurplus(),
61    ])
62
63    let portfolio = []
64
65    for (const portItem of pausePortfolio) {
66      if (portItem.context.symbol === 'DAI') {
67        portfolio.push({
68          address: portItem.address, 
69          amount: daiSurplus + portItem.context.balance,
70          name: portItem.context.symbol, 
71          symbol:portItem.context.symbol, 
72          icon:portItem.displayProps.images[0],
73          price:portItem.context.price, 
74          value:portItem.balanceUSD + (daiSurplus * portItem.context.price)
75        })
76      } else {
77         portfolio.push({
78          address: portItem.address, 
79          amount: portItem.context.balance,
80          name: portItem.context.symbol, 
81          symbol:portItem.context.symbol, 
82          icon:portItem.displayProps.images[0],
83          price:portItem.context.price, 
84          value:portItem.balanceUSD
85        })
86      }
87    }
88
89    return portfolio
90  }
91
92  sdk.register({
93    id: 'makerdao',
94    queries: {
95      currentTreasuryUSD: getTreasuryInUSD,
96      currentLiquidTreasuryUSD: getTreasuryInUSD,
97      currentTreasuryPortfolio: getPortfolio,
98      recentProposals: async () => [], // TODO: Fetch actual proposals
99    },
100    metadata: {
101      icon: sdk.ipfs.getDataURILoader('QmNuxELX7oWXJtJKveaCFDC7niZ4APtkWgPn1NZm2FLSJV', 'image/svg+xml'),
102      category: 'app',
103      name: 'MakerDAO',
104      website: 'https://makerdao.com',
105      governanceSite: 'https://vote.makerdao.com',
106      governanceForum: 'https://forum.makerdao.com',
107      governanceModel: '',
108      treasuries: [PAUSE_ADDRESS],
109    },
110  })
111}
112

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

QmdXzYbLsjxHm1o6tvtCoFgCirrqp2NfbP3fFELuqXR5o5

CID (source)

QmXguyGLiETop7xsgassyBA5w45R3tDBtLyCKU5SJptLPF

Collections

Author

0x70c0EE6bd4a42e9Dc5487e30a765370b65e670A5