forked from circlefin/stablecoin-evm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.js
171 lines (136 loc) · 5.12 KB
/
validate.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2023, Circle Internet Financial, LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Address of the FiatToken Implementation
const fiatTokenAddress = "0x0882477e7895bdc5cea7cb1552ed914ab157fe56";
// Address of the FiatToken Proxy
const fiatTokenProxyAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
// role addresses
const MASTER_MINTER = 0x1500a138523709ce66c8b9abe678abc1b6c5a7b7;
const PAUSER = 0xe8e13e1b6d363c270ef3a5ab466ebad8326311bb;
const UPGRADER = 0x69005ff70072c57547dc44ea975d85ea60e5b196;
const OWNER = 0xa61e278899a8553d93d14eb19ba2791e05069e87;
const BLACKLISTER = 0x063d13783a0a2ce65b1ca00d9e897e6c8b1ec86b;
// Addresses of known minters - currently fake minters
// If replacing with real minters need to modify printMinterInfo
const minters = ["0x0000", "0x0001"];
const NAME = "USD//C";
const SYMBOL = "USDC";
const CURRENCY = "USD";
const DECIMALS = 6;
const TOTALSUPPLY = 0;
const PAUSED = false;
// Name of current implementation artifact as stored in ./build/contracts/*.json
const FiatTokenV1 = artifacts.require("FiatTokenV1");
// Name of current proxy artifact as stored in ./build/contracts/*.json
artifacts.require("FiatTokenProxy");
//
//
// Validation code
//
//
const adminSlot =
"0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b";
const implSlot =
"0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3";
const asyncGetStorageAt = (address, slot) =>
new Promise((resolve, reject) => {
web3.eth.getStorageAt(address, slot, (err, result) => {
if (err) {
return reject(err);
}
resolve(result);
});
});
async function printMinterInfo(proxiedToken) {
for (const minter of minters) {
console.log("\nMinter: " + minter);
const isMinter = await proxiedToken.isMinter.call(minter);
print("isMinter", isMinter, false);
const minterAllowance = await proxiedToken.minterAllowance.call(minter);
print("mintAllowance", minterAllowance, 0);
const balanceOf = await proxiedToken.balanceOf.call(minter);
print("balanceOf", balanceOf, 0);
const isBlacklisted = await proxiedToken.isBlacklisted.call(minter);
print("isBlacklisted", isBlacklisted, false);
}
}
function getAddressFromSlotData(slotData) {
const rawAddress = slotData.substring(26, 86);
return "0x" + rawAddress;
}
function compare(actual, expected) {
if (actual === expected) {
return "(ok)";
} else {
return "(expect " + expected + ")";
}
}
function print(name, actual, expected) {
console.log(name + "\t" + actual + "\t" + compare(actual, expected));
}
async function Validate() {
console.log("Connecting to contract...");
await FiatTokenV1.at(fiatTokenAddress);
console.log("Token found.");
const proxiedToken = await FiatTokenV1.at(fiatTokenProxyAddress);
console.log("Proxied token created.");
// initialized needs to retrieved manually
let slot8Data = await asyncGetStorageAt(proxiedToken.address, 8);
let initialized = slot8Data.substring(24, 26);
print("init proxy", initialized, "01");
slot8Data = await asyncGetStorageAt(fiatTokenAddress, 8);
initialized = slot8Data.substring(24, 26);
print("init logic", initialized, "01");
const name = await proxiedToken.name.call();
print("name ", name, NAME);
const symbol = await proxiedToken.symbol.call();
print("symbol ", symbol, SYMBOL);
const decimals = await proxiedToken.decimals.call();
print("decimals", decimals, DECIMALS);
const currency = await proxiedToken.currency.call();
print("currency", currency, CURRENCY);
const totalSupply = await proxiedToken.totalSupply.call();
print("totalSupply", totalSupply, TOTALSUPPLY);
const paused = await proxiedToken.paused.call();
print("paused ", paused, PAUSED);
// implementation
const implementation = await asyncGetStorageAt(
proxiedToken.address,
implSlot
);
print("implement", getAddressFromSlotData(implementation), fiatTokenAddress);
const admin = await asyncGetStorageAt(proxiedToken.address, adminSlot);
print("upgrader", getAddressFromSlotData(admin), UPGRADER);
const owner = await proxiedToken.owner.call();
print("owner ", owner, OWNER);
const masterMinter = await proxiedToken.masterMinter.call();
print("masterMinter", masterMinter, MASTER_MINTER);
const pauser = await proxiedToken.pauser.call();
print("pauser ", pauser, PAUSER);
const blacklister = await proxiedToken.blacklister.call();
print("blacklister", blacklister, BLACKLISTER);
await printMinterInfo(proxiedToken);
}
module.exports = async (callback) => {
try {
await Validate();
} catch (e) {
// continue
}
callback();
};