forked from reserve-protocol/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollateral-params.ts
98 lines (84 loc) · 3.56 KB
/
collateral-params.ts
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
import { getChainId } from '#/common/blockchain-utils'
import { formatEther } from 'ethers/lib/utils'
import hre, { ethers } from 'hardhat'
import {
getAssetCollDeploymentFilename,
getDeploymentFile,
IAssetCollDeployments,
} from './deployment/common'
// This prints an MD table of all the collateral plugin parameters
// Usage: npx hardhat run --network mainnet scripts/collateral-params.ts
async function main() {
const header = ['Plugin', 'Tolerance', 'Delay (hrs)', 'Oracle(s)', 'Underlying']
const body: string[][] = []
const chainId = await getChainId(hre)
// Get deployed collateral
const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId, 'mainnet-2.1.0')
const assetCollDeployments = <IAssetCollDeployments>getDeploymentFile(assetCollDeploymentFilename)
const { collateral: collaterals } = assetCollDeployments
for (const [collateral, address] of Object.entries(collaterals)) {
const collateralContract = await ethers.getContractAt('FiatCollateral', address)
const targetPerRef = await collateralContract.targetPerRef()
const pegBottom = await collateralContract.pegBottom()
const delay = await collateralContract.delayUntilDefault()
const underlyingAddr = await collateralContract.erc20()
const chainlinkFeed = await collateralContract.chainlinkFeed()
// we cannot read the chainlink feeds for multi-oracle collateral because we used immutable internal vars :(
const collateralMd = getEtherscanMd(address, collateral)
const underlyingMd = getEtherscanMd(underlyingAddr)
const clFeedMd = getEtherscanMd(chainlinkFeed)
const NEEDS_ATTENTION = ['[cvxMIM3'] // first 8 chars only
body.push([
collateralMd,
`${formatEther(targetPerRef.sub(pegBottom).mul(100))}% ${
NEEDS_ATTENTION.indexOf(collateralMd.substring(0, 8)) >= 0 ? '(needs attention)' : ''
}`,
(delay / 3600).toString(),
clFeedMd,
underlyingMd,
])
}
printTable(header, body)
console.log(
'WARNING: FILL IN "(needs attention)" BEFORE BLINDLY SAVING TO docs/plugin-addresses.md'
)
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})
// Helper function for printing MD table
// This could've come from a library, but I didn't want to add a dependency
const printTable = (headers: string[], body: string[][]) => {
const fmtStrLen = (str: string, len: number) => {
const pre = ' '.repeat(Math.floor((len - str.length) / 2))
const trail = ' '.repeat(Math.ceil((len - str.length) / 2))
return pre.concat(str).concat(trail)
}
const getFieldLength = (fieldOrder: number) => {
let len = headers[fieldOrder].length
body?.forEach((row) => {
const rowLength = row[fieldOrder]?.length ?? 0
len = len > rowLength ? len : rowLength
})
return Math.ceil((len + 2) / 2) * 2
}
const fieldsLengths: number[] = body[0].map((_, idx) => getFieldLength(idx))
const separator = { horizontal: '-', vertical: '|' }
headers.forEach((header, idx) =>
process.stdout.write(separator.vertical + fmtStrLen(header, fieldsLengths[idx]))
)
console.log(separator.vertical)
headers.forEach((_header, _idx) => {
process.stdout.write(separator.vertical + separator.horizontal.repeat(fieldsLengths[_idx]))
})
console.log(separator.vertical)
body.forEach((row) => {
row.forEach((field, idx) =>
process.stdout.write(separator.vertical + fmtStrLen(field ?? '', fieldsLengths[idx]))
)
console.log(separator.vertical)
})
}
const getEtherscanMd = (address: string, name?: string) =>
`[${name || address}](https://etherscan.io/address/${address})`