Sub-Adapters 1
Preview and test each sub adapter.
bZx (bzx)
Metadata
- ID
- bzx
- name
"bZx"
- icon
- website
"https://bzx.network"
- governanceForum
"https://forum.bzx.network"
- governanceSite
"https://snapshot.org/#/bzx.eth"
- treasuries
[ "0xfedC4dD5247B93feb41e899A09C44cFaBec29Cbc" ]
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'bzx Treasury - Clone';
2export const version = '0.1.2';
3export const license = 'MIT';
4
5const TREASURY_ADDRESS = '0xfedC4dD5247B93feb41e899A09C44cFaBec29Cbc'
6
7export async function setup(sdk: Context) {
8 let treasuryPortfolioPromise: Promise<any> | null
9 const getTresuryPortfolio = (): Promise<any> => {
10 if (!treasuryPortfolioPromise) {
11 treasuryPortfolioPromise = sdk.http.get(`https://zerion-api.vercel.app/api/portfolio/${TREASURY_ADDRESS}`)
12 .then(result => {
13 if (result.success) {
14 return result.value
15 }
16 throw new Error(result.error)
17 })
18 }
19 return treasuryPortfolioPromise
20 }
21
22 const getTreasuryInUSD = async () => {
23 const treasury = await getTresuryPortfolio()
24 return treasury.totalValue
25 }
26
27 const getPortfolio = async () => {
28 const portfolio = await getTresuryPortfolio()
29
30 const withVesting = portfolio.portfolio.map((item: any) => item.symbol === 'vBZRX' ? {
31 ...item,
32 vesting: true,
33 } : item)
34
35 return withVesting
36 }
37
38 const getLiquidTreasuryInUSD = async () => {
39 const portfolio = await getPortfolio()
40
41 const liquidTreasury = portfolio
42 .filter((item: any) => item.symbol !== 'vBZRX')
43 .reduce((acc: number, item: any) => acc + item.value, 0)
44
45 return liquidTreasury
46 }
47
48
49 async function getSnapshotProposals(id: string) {
50 const response = await sdk.http.post('https://hub.snapshot.org/graphql', {
51 query: `query Proposals($space: String!) {
52 proposals (
53 first: 5,
54 skip: 0,
55 where: { space_in: [$space] },
56 orderBy: "created",
57 orderDirection: desc
58 ) {
59 id
60 title
61 start
62 end
63 state
64 link
65 }
66 }`,
67 variables: { space: id },
68 });
69
70 return response.data.proposals;
71 }
72
73 sdk.register({
74 id: 'bzx',
75 queries: {
76 currentTreasuryUSD: getTreasuryInUSD,
77 currentLiquidTreasuryUSD: getLiquidTreasuryInUSD,
78 currentTreasuryPortfolio: getPortfolio,
79 recentProposals: () => getSnapshotProposals('bzx.eth'),
80 },
81 metadata: {
82 name: 'bZx',
83 icon: sdk.ipfs.getDataURILoader('QmYhs7n7pGCPbbLdcQTb2ThX2WgQ7nSTgdhsX4UXzXCxG5', 'image/svg+xml'),
84 website: 'https://bzx.network',
85 governanceForum: 'https://forum.bzx.network',
86 governanceSite: 'https://snapshot.org/#/bzx.eth',
87 treasuries: [TREASURY_ADDRESS],
88 },
89 })
90}
91
It's something off?
Report it to the discussion board on Discord, we will take care of it.