-
Notifications
You must be signed in to change notification settings - Fork 0
/
adamant.js
102 lines (97 loc) · 3.22 KB
/
adamant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const fs = require('fs')
const fetch = async (browser) => {
const page = await browser.newPage()
await page.goto('https://adamant.finance/home')
await page.waitForFunction(() => {
const cards = document.querySelectorAll('.farms-card-item')
return cards.length > 100
})
const result = await page.$$eval('.farms-card-item', (farms) => {
return farms
.map((farm) => {
const getPoolName = (p) => {
const name = p.nameOverride ?? p.singleAsset ? p.token1Name : p.token0Name + '/' + p.token1Name + ' LP'
return p.beta
? name + ' (Beta)'
: 'cometh' == p.platform
? name + ' (Cometh)'
: 'sushi' == p.platform
? name + ' (Sushi)'
: 'elk' == p.platform
? name + ' (Elk)'
: 'polyzap' == p.platform
? name + ' (PolyZap)'
: 'mai' == p.platform
? name + ' (QiDao)'
: 'curve' == p.platform
? name + ' (Curve)'
: 'wault' == p.platform
? name + ' (Wault)'
: 'quick' == p.platform
? name + ' (Quick)'
: 'augury' == p.platform
? name + ' (Augury)'
: 'jet' == p.platform
? name + ' (Jet)'
: 'ape' == p.platform
? name + ' (Ape)'
: 'dino' == p.platform
? name + ' (Dino)'
: 'yeld' == p.platform
? 'sushi' == p.exchange
? name + ' (Sushi)'
: 'ape' == p.exchange
? name + ' (Ape)'
: name + ' (Quick)'
: name
}
const rkey = Object.keys(farm).find((k) => k.startsWith('__reactInternalInstance'))
try {
if (farm.href && farm.href.includes('/stakeaddy')) {
return {
name: 'Staking Addy',
apr: farm.querySelector('.apy').innerText.split('%')[0],
}
}
const p = farm[rkey].return.memoizedProps.pool
if (!p) return undefined
if (p.addyFeeShareApr) {
return {
name: 'ADDY/WETH LP (Quick)',
apr: p.apr,
addyFeeShareApr: p.addyFeeShareApr,
}
}
return {
name: getPoolName(p),
lpAddress: p.lpAddress,
vaultAddress: p.vaultAddress,
strategyAddress: p.strategyAddress,
apy: p.apy,
baseApr: p.baseApr,
addyTokenApr: p.addyTokenApr,
}
} catch (err) {
return undefined
}
})
.filter(Boolean)
})
await page.close()
if (result.length > 1) return result
return null
}
module.exports = async (browser) => {
const newPools = await fetch(browser)
if (!newPools) return
let currentPools = []
try {
currentPools = JSON.parse(fs.readFileSync('./pools.json').toString())
} catch (e) {}
const newVaultAddressList = newPools.map((p) => p.vaultAddress).filter(Boolean)
for (const pool of currentPools.filter((p) => p.vaultAddress)) {
if (newVaultAddressList.includes(pool.vaultAddress)) continue
newPools.push({ ...pool, deprecated: true })
}
fs.writeFileSync('./pools.json', JSON.stringify(newPools, null, 2))
}