@gooddollar/goodprotocol 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +12 -0
  2. package/artifacts/abis/AdminWallet.min.json +1 -1
  3. package/artifacts/abis/AdminWalletFuse.min.json +1 -1
  4. package/artifacts/abis/GenericDistributionHelperTest.min.json +1 -0
  5. package/artifacts/abis/GenericDistributionHelperTestHelper.min.json +1 -0
  6. package/artifacts/abis/IBancorExchangeProvider.min.json +1 -1
  7. package/artifacts/abis/IUniswapV3Pool.min.json +1 -1
  8. package/artifacts/abis/IdentityV3.min.json +1 -1
  9. package/artifacts/abis/MentoExchange.min.json +1 -1
  10. package/artifacts/abis/UpdateReserveRatioAfterXDC.min.json +1 -0
  11. package/artifacts/contracts/IUniswapV3.sol/INonfungiblePositionManager.dbg.json +1 -1
  12. package/artifacts/contracts/IUniswapV3.sol/IUniswapV3Pool.dbg.json +1 -1
  13. package/artifacts/contracts/IUniswapV3.sol/IUniswapV3Pool.json +13 -0
  14. package/artifacts/contracts/MentoInterfaces.sol/IBancorExchangeProvider.dbg.json +1 -1
  15. package/artifacts/contracts/MentoInterfaces.sol/IBancorExchangeProvider.json +13 -0
  16. package/artifacts/contracts/MentoInterfaces.sol/IBroker.dbg.json +1 -1
  17. package/artifacts/contracts/MentoInterfaces.sol/IGoodDollarExchangeProvider.dbg.json +1 -1
  18. package/artifacts/contracts/MentoInterfaces.sol/IGoodDollarExpansionController.dbg.json +1 -1
  19. package/artifacts/contracts/MentoInterfaces.sol/IMentoReserve.dbg.json +1 -1
  20. package/artifacts/contracts/MentoInterfaces.sol/ITradingLimits.dbg.json +1 -1
  21. package/artifacts/contracts/identity/IdentityV3.sol/IdentityV3.dbg.json +1 -1
  22. package/artifacts/contracts/identity/IdentityV3.sol/IdentityV3.json +40 -2
  23. package/artifacts/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTest.dbg.json +4 -0
  24. package/artifacts/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTest.json +931 -0
  25. package/artifacts/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTestHelper.dbg.json +4 -0
  26. package/artifacts/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTestHelper.json +957 -0
  27. package/artifacts/contracts/reserve/GenericDistributionHelper.sol/GenericDistributionHelper.dbg.json +1 -1
  28. package/artifacts/contracts/reserve/GenericDistributionHelper.sol/GenericDistributionHelper.json +2 -2
  29. package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.dbg.json +1 -1
  30. package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.json +36 -2
  31. package/artifacts/contracts/utils/AdminWalletFuse.sol/AdminWalletFuse.dbg.json +1 -1
  32. package/artifacts/contracts/utils/AdminWalletFuse.sol/AdminWalletFuse.json +36 -2
  33. package/artifacts/contracts/utils/BulkWhitelist.sol/BulkWhitelist.dbg.json +1 -1
  34. package/artifacts/contracts/utils/BulkWhitelist.sol/BulkWhitelist.json +2 -2
  35. package/artifacts/contracts/utils/BuyFromReserveHelper.sol/BuyFromReserveHelper.dbg.json +1 -1
  36. package/artifacts/contracts/utils/BuyFromReserveHelper.sol/BuyFromReserveHelper.json +2 -2
  37. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.dbg.json +1 -1
  38. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.dbg.json +1 -1
  39. package/artifacts/contracts/utils/BuyGDClone.sol/DonateGDClone.dbg.json +1 -1
  40. package/artifacts/contracts/utils/ProtoclUpgradeV4Mento.sol/MentoExchange.dbg.json +1 -1
  41. package/artifacts/contracts/utils/ProtoclUpgradeV4Mento.sol/ProtocolUpgradeV4Mento.dbg.json +1 -1
  42. package/artifacts/contracts/utils/ProtoclUpgradeV4Mento.sol/ProtocolUpgradeV4Mento.json +2 -2
  43. package/artifacts/contracts/utils/UpdateReserveRatioAfterXDC.sol/MentoExchange.dbg.json +4 -0
  44. package/artifacts/contracts/utils/UpdateReserveRatioAfterXDC.sol/MentoExchange.json +24 -0
  45. package/artifacts/contracts/utils/UpdateReserveRatioAfterXDC.sol/UpdateReserveRatioAfterXDC.dbg.json +4 -0
  46. package/artifacts/contracts/utils/UpdateReserveRatioAfterXDC.sol/UpdateReserveRatioAfterXDC.json +50 -0
  47. package/contracts/IUniswapV3.sol +2 -0
  48. package/contracts/identity/IdentityV3.sol +2 -0
  49. package/contracts/mocks/GenericDistributionHelperTest.sol +31 -0
  50. package/contracts/reserve/GenericDistributionHelper.sol +43 -21
  51. package/contracts/utils/AdminWallet.sol +27 -0
  52. package/contracts/utils/AdminWalletFuse.sol +27 -0
  53. package/contracts/utils/UpdateReserveRatioAfterXDC.sol +64 -0
  54. package/hardhat.config.ts +9 -12
  55. package/package.json +3 -2
  56. package/releases/deployment.json +4 -1
  57. package/scripts/bulkWhitelist.ts +31 -0
  58. package/scripts/multichain-deploy/helpers.ts +13 -6
  59. package/scripts/proposals/gip-25-xdc-deploy-reserve.ts +425 -0
  60. package/scripts/proposals/gip-25-xdc-upgrade-ubi.ts +334 -31
  61. package/test/governance/ClaimersDistribution.test.ts +1 -1
  62. package/test/reserve/GenericDistributionHelper.test.ts +315 -0
  63. package/test/ubi/UBISchemeCycle.test.ts +30 -63
  64. package/types/contracts/IUniswapV3.sol/IUniswapV3Pool.ts +14 -1
  65. package/types/contracts/MentoInterfaces.sol/IBancorExchangeProvider.ts +14 -0
  66. package/types/contracts/fuseFaucet/Faucet copy.sol/DebugFaucet.ts +1439 -0
  67. package/types/contracts/fuseFaucet/Faucet copy.sol/index.ts +4 -0
  68. package/types/contracts/identity/IdentityV3.ts +46 -0
  69. package/types/contracts/index.ts +0 -2
  70. package/types/contracts/mocks/GenericDistributionHelperTest.sol/CeloDistributionHelperTestHelper.ts +1357 -0
  71. package/types/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTest.ts +1305 -0
  72. package/types/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTestHelper.ts +1357 -0
  73. package/types/contracts/mocks/GenericDistributionHelperTest.sol/index.ts +5 -0
  74. package/types/contracts/mocks/index.ts +2 -0
  75. package/types/contracts/utils/AdminWallet.ts +45 -0
  76. package/types/contracts/utils/AdminWalletFuse.ts +45 -0
  77. package/types/contracts/utils/BuyGDClone.sol/BuyGDCloneV2.ts +464 -0
  78. package/types/contracts/utils/UpdateReserveRatioAfterXDC.sol/MentoExchange.ts +81 -0
  79. package/types/contracts/utils/UpdateReserveRatioAfterXDC.sol/UpdateReserveRatioAfterXDC.ts +117 -0
  80. package/types/contracts/utils/UpdateReserveRatioAfterXDC.sol/index.ts +5 -0
  81. package/types/contracts/utils/UpdateReserveSettingsForXdc.sol/MentoExchange.ts +81 -0
  82. package/types/contracts/utils/UpdateReserveSettingsForXdc.sol/UpdateReserveRatioAfterXDC.ts +122 -0
  83. package/types/contracts/utils/UpdateReserveSettingsForXdc.sol/index.ts +5 -0
  84. package/types/contracts/utils/index.ts +4 -0
  85. package/types/factories/contracts/IUniswapV3.sol/IUniswapV3Pool__factory.ts +13 -0
  86. package/types/factories/contracts/MentoInterfaces.sol/IBancorExchangeProvider__factory.ts +13 -0
  87. package/types/factories/contracts/fuseFaucet/Faucet copy.sol/DebugFaucet__factory.ts +945 -0
  88. package/types/factories/contracts/fuseFaucet/Faucet copy.sol/index.ts +4 -0
  89. package/types/factories/contracts/identity/IdentityV3__factory.ts +39 -1
  90. package/types/factories/contracts/index.ts +0 -1
  91. package/types/factories/contracts/mocks/GenericDistributionHelperTest.sol/CeloDistributionHelperTestHelper__factory.ts +1017 -0
  92. package/types/factories/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTestHelper__factory.ts +1021 -0
  93. package/types/factories/contracts/mocks/GenericDistributionHelperTest.sol/GenericDistributionHelperTest__factory.ts +989 -0
  94. package/types/factories/contracts/mocks/GenericDistributionHelperTest.sol/index.ts +5 -0
  95. package/types/factories/contracts/mocks/index.ts +1 -0
  96. package/types/factories/contracts/reserve/GenericDistributionHelper__factory.ts +1 -1
  97. package/types/factories/contracts/utils/AdminWalletFuse__factory.ts +35 -1
  98. package/types/factories/contracts/utils/AdminWallet__factory.ts +35 -1
  99. package/types/factories/contracts/utils/BulkWhitelist__factory.ts +1 -1
  100. package/types/factories/contracts/utils/BuyFromReserveHelper__factory.ts +1 -1
  101. package/types/factories/contracts/utils/BuyGDClone.sol/BuyGDCloneV2__factory.ts +415 -0
  102. package/types/factories/contracts/utils/ProtoclUpgradeV4Mento.sol/ProtocolUpgradeV4Mento__factory.ts +1 -1
  103. package/types/factories/contracts/utils/UpdateReserveRatioAfterXDC.sol/MentoExchange__factory.ts +39 -0
  104. package/types/factories/contracts/utils/UpdateReserveRatioAfterXDC.sol/UpdateReserveRatioAfterXDC__factory.ts +110 -0
  105. package/types/factories/contracts/utils/UpdateReserveRatioAfterXDC.sol/index.ts +5 -0
  106. package/types/factories/contracts/utils/UpdateReserveSettingsForXdc.sol/MentoExchange__factory.ts +39 -0
  107. package/types/factories/contracts/utils/UpdateReserveSettingsForXdc.sol/UpdateReserveRatioAfterXDC__factory.ts +115 -0
  108. package/types/factories/contracts/utils/UpdateReserveSettingsForXdc.sol/index.ts +5 -0
  109. package/types/factories/contracts/utils/index.ts +2 -0
  110. package/types/hardhat.d.ts +54 -9
  111. package/types/index.ts +6 -0
  112. package/artifacts/contracts/IQuoter.sol/IQuoterV2.dbg.json +0 -4
  113. package/artifacts/contracts/IQuoter.sol/IQuoterV2.json +0 -211
@@ -0,0 +1,425 @@
1
+ // Part 2 Reserve
2
+ // upgrade bridge + identity on all networks
3
+ // create uniswap pools on xdc
4
+ // calculate how much G$s each reserve is backing
5
+ // deploy mento reserve to xdc with calculated parameters
6
+ // give mento broker minting rights on xdc
7
+ // deploy distribution helper
8
+ // transfer usdc to xdc reserve
9
+ // update celo reserve parameters accordingly
10
+
11
+ import { network, ethers, upgrades } from "hardhat";
12
+ import { reset } from "@nomicfoundation/hardhat-network-helpers";
13
+ import { defaultsDeep, last } from "lodash";
14
+ import prompt from "prompt";
15
+
16
+ import {
17
+ executeViaGuardian,
18
+ executeViaSafe,
19
+ verifyContract,
20
+ verifyProductionSigner
21
+ } from "../multichain-deploy/helpers";
22
+
23
+ import dao from "../../releases/deployment.json";
24
+ import { Controller, IdentityV3, IGoodDollar, IMessagePassingBridge, UBISchemeV2 } from "../../types";
25
+ let { name: networkName } = network;
26
+ const isSimulation = network.name === "hardhat" || network.name === "fork" || network.name === "localhost";
27
+ const bridgeUpgradeImpl = {
28
+ "production-celo": "0xF3eAB7018d74E7Df95A5d8dC70987C0539bDF48f",
29
+ production: "0xFB62aA509a7B260b6697B671C969a184d6c39E90",
30
+ "production-mainnet": "0x12ab702f015D3302f3cc0c4AbA0626A127D06A07",
31
+ "production-xdc": "0xe4CFA18A3d0a7d77fAA42961ee943c9221d61937"
32
+ };
33
+ export const upgradeCeloStep2 = async (network, checksOnly) => {
34
+ let [root] = await ethers.getSigners();
35
+
36
+ const isProduction = networkName.includes("production");
37
+
38
+ if (isProduction) verifyProductionSigner(root);
39
+
40
+ let networkEnv = networkName;
41
+ let guardian = root;
42
+ if (isSimulation) {
43
+ networkEnv = network;
44
+ }
45
+
46
+ let release: { [key: string]: any } = dao[networkEnv];
47
+
48
+ console.log("signer:", root.address, { networkEnv, isSimulation, isProduction, release });
49
+
50
+ if (isSimulation) {
51
+ networkEnv = network;
52
+ guardian = await ethers.getImpersonatedSigner(release.GuardiansSafe);
53
+
54
+ await root.sendTransaction({
55
+ value: ethers.utils.parseEther("1"),
56
+ to: release.GuardiansSafe
57
+ });
58
+ }
59
+
60
+ const identityImpl = await ethers.deployContract("IdentityV3");
61
+ const reserveUpdate = await ethers.deployContract("UpdateReserveRatioAfterXDC")
62
+ const bridgeImpl = bridgeUpgradeImpl[networkEnv];
63
+
64
+ // Extract the first four bytes as the function selector
65
+ console.log("deployed new impls", { identityImpl: identityImpl.address });
66
+
67
+
68
+ const proposalActions = [
69
+ [
70
+ release.Identity,
71
+ "upgradeTo(address)",
72
+ ethers.utils.defaultAbiCoder.encode(["address"], [identityImpl.address]),
73
+ "0"
74
+ ], //upgrade identity
75
+ [
76
+ release.MpbBridge,
77
+ "upgradeTo(address)",
78
+ ethers.utils.defaultAbiCoder.encode(["address"], [bridgeImpl]),
79
+ "0"
80
+ ], //upgrade bridge
81
+ [
82
+ release.Controller,
83
+ "registerScheme(address,bytes32,bytes4,address)",
84
+ ethers.utils.defaultAbiCoder.encode(
85
+ ["address", "bytes32", "bytes4", "address"],
86
+ [reserveUpdate.address, ethers.constants.HashZero, "0x0000001f", release.Avatar]
87
+ ),
88
+ "0"
89
+ ] //give generic call rights to update reserve ratio
90
+
91
+ ];
92
+
93
+ console.log({
94
+ networkEnv,
95
+ guardian: guardian.address,
96
+ isSimulation,
97
+ isProduction,
98
+ release
99
+ });
100
+
101
+ const proposalContracts = proposalActions.map(a => a[0]);
102
+ const proposalFunctionSignatures = proposalActions.map(a => a[1]);
103
+ const proposalFunctionInputs = proposalActions.map(a => a[2]);
104
+ const proposalEthValues = proposalActions.map(a => a[3]);
105
+ if (isProduction && !checksOnly) {
106
+ await executeViaSafe(
107
+ proposalContracts,
108
+ proposalEthValues,
109
+ proposalFunctionSignatures,
110
+ proposalFunctionInputs,
111
+ release.GuardiansSafe,
112
+ "celo"
113
+ );
114
+ } else if (!checksOnly) {
115
+ await executeViaGuardian(
116
+ proposalContracts,
117
+ proposalEthValues,
118
+ proposalFunctionSignatures,
119
+ proposalFunctionInputs,
120
+ guardian,
121
+ networkEnv
122
+ );
123
+ }
124
+
125
+ };
126
+
127
+ export const upgradeFuseStep2 = async (network, checksOnly) => {
128
+ let [root] = await ethers.getSigners();
129
+
130
+ const isProduction = networkName.includes("production");
131
+
132
+ if (isProduction) verifyProductionSigner(root);
133
+
134
+ let networkEnv = networkName;
135
+ let guardian = root;
136
+ if (isSimulation) {
137
+ networkEnv = network;
138
+ }
139
+
140
+ let release: { [key: string]: any } = dao[networkEnv];
141
+
142
+ console.log("signer:", root.address, { networkEnv, isSimulation, isProduction, release });
143
+
144
+ if (isSimulation) {
145
+ networkEnv = network;
146
+ guardian = await ethers.getImpersonatedSigner(release.GuardiansSafe);
147
+
148
+ await root.sendTransaction({
149
+ value: ethers.utils.parseEther("1"),
150
+ to: release.GuardiansSafe
151
+ });
152
+ }
153
+
154
+ const identityImpl = await ethers.deployContract("IdentityV3");
155
+ const bridgeImpl = bridgeUpgradeImpl[networkEnv];
156
+
157
+ // Extract the first four bytes as the function selector
158
+ console.log("deployed new impls", { identityImpl: identityImpl.address });
159
+
160
+ const proposalActions = [
161
+ [
162
+ release.Identity,
163
+ "upgradeTo(address)",
164
+ ethers.utils.defaultAbiCoder.encode(["address"], [identityImpl.address]),
165
+ "0"
166
+ ], //upgrade identity
167
+ [
168
+ release.MpbBridge,
169
+ "upgradeTo(address)",
170
+ ethers.utils.defaultAbiCoder.encode(["address"], [bridgeImpl]),
171
+ "0"
172
+ ], //upgrade bridge
173
+ ];
174
+
175
+ console.log({
176
+ networkEnv,
177
+ guardian: guardian.address,
178
+ isSimulation,
179
+ isProduction,
180
+ release
181
+ });
182
+
183
+ const proposalContracts = proposalActions.map(a => a[0]);
184
+ const proposalFunctionSignatures = proposalActions.map(a => a[1]);
185
+ const proposalFunctionInputs = proposalActions.map(a => a[2]);
186
+ const proposalEthValues = proposalActions.map(a => a[3]);
187
+ if (isProduction && !checksOnly) {
188
+ await executeViaSafe(
189
+ proposalContracts,
190
+ proposalEthValues,
191
+ proposalFunctionSignatures,
192
+ proposalFunctionInputs,
193
+ release.GuardiansSafe,
194
+ "fuse"
195
+ );
196
+ } else if (!checksOnly) {
197
+ await executeViaGuardian(
198
+ proposalContracts,
199
+ proposalEthValues,
200
+ proposalFunctionSignatures,
201
+ proposalFunctionInputs,
202
+ guardian,
203
+ networkEnv
204
+ );
205
+ }
206
+ };
207
+
208
+ export const upgradeEthStep2 = async (network, checksOnly) => {
209
+ let [root] = await ethers.getSigners();
210
+
211
+ const isProduction = networkName.includes("production");
212
+
213
+ if (isProduction) verifyProductionSigner(root);
214
+
215
+ let networkEnv = networkName;
216
+ let guardian = root;
217
+ if (isSimulation) {
218
+ networkEnv = network;
219
+ }
220
+
221
+ let release: { [key: string]: any } = dao[networkEnv];
222
+
223
+ console.log("signer:", root.address, { networkEnv, isSimulation, isProduction, release });
224
+
225
+ if (isSimulation) {
226
+ networkEnv = network;
227
+ guardian = await ethers.getImpersonatedSigner(release.GuardiansSafe);
228
+
229
+ await root.sendTransaction({
230
+ value: ethers.utils.parseEther("1"),
231
+ to: release.GuardiansSafe
232
+ });
233
+ }
234
+
235
+ const bridgeImpl = bridgeUpgradeImpl[networkEnv];
236
+
237
+ const proposalActions = [
238
+ [
239
+ release.MpbBridge,
240
+ "upgradeTo(address)",
241
+ ethers.utils.defaultAbiCoder.encode(["address"], [bridgeImpl]),
242
+ "0"
243
+ ] //upgrade bridge
244
+ ];
245
+
246
+ console.log({
247
+ networkEnv,
248
+ guardian: guardian.address,
249
+ isSimulation,
250
+ isProduction,
251
+ release
252
+ });
253
+
254
+ const proposalContracts = proposalActions.map(a => a[0]);
255
+ const proposalFunctionSignatures = proposalActions.map(a => a[1]);
256
+ const proposalFunctionInputs = proposalActions.map(a => a[2]);
257
+ const proposalEthValues = proposalActions.map(a => a[3]);
258
+ if (isProduction && !checksOnly) {
259
+ await executeViaSafe(
260
+ proposalContracts,
261
+ proposalEthValues,
262
+ proposalFunctionSignatures,
263
+ proposalFunctionInputs,
264
+ release.GuardiansSafe,
265
+ "mainnet"
266
+ );
267
+ } else if (!checksOnly) {
268
+ await executeViaGuardian(
269
+ proposalContracts,
270
+ proposalEthValues,
271
+ proposalFunctionSignatures,
272
+ proposalFunctionInputs,
273
+ guardian,
274
+ networkEnv
275
+ );
276
+ }
277
+ };
278
+
279
+ export const upgradeXdcStep2 = async (network, checksOnly) => {
280
+ let [root] = await ethers.getSigners();
281
+
282
+ const isProduction = networkName.includes("production");
283
+
284
+ if (isProduction) verifyProductionSigner(root);
285
+
286
+ let networkEnv = networkName;
287
+ let guardian = root;
288
+ if (isSimulation) {
289
+ networkEnv = network;
290
+ }
291
+
292
+ let release: { [key: string]: any } = dao[networkEnv];
293
+
294
+ console.log("signer:", root.address, { networkEnv, isSimulation, isProduction, release });
295
+
296
+ if (isSimulation) {
297
+ networkEnv = network;
298
+ guardian = await ethers.getImpersonatedSigner(release.GuardiansSafe);
299
+
300
+ await root.sendTransaction({
301
+ value: ethers.utils.parseEther("1"),
302
+ to: release.GuardiansSafe
303
+ });
304
+ }
305
+
306
+ const bridgeImpl = bridgeUpgradeImpl[networkEnv];
307
+ const proposalActions = [
308
+ [release.MpbBridge, "upgradeTo(address)", ethers.utils.defaultAbiCoder.encode(["address"], [bridgeImpl]), "0"] //upgrade bridge
309
+ ];
310
+
311
+ console.log({
312
+ networkEnv,
313
+ guardian: guardian.address,
314
+ isSimulation,
315
+ isProduction,
316
+ release
317
+ });
318
+
319
+ const proposalContracts = proposalActions.map(a => a[0]);
320
+ const proposalFunctionSignatures = proposalActions.map(a => a[1]);
321
+ const proposalFunctionInputs = proposalActions.map(a => a[2]);
322
+ const proposalEthValues = proposalActions.map(a => a[3]);
323
+ if (isProduction && !checksOnly) {
324
+ await executeViaSafe(
325
+ proposalContracts,
326
+ proposalEthValues,
327
+ proposalFunctionSignatures,
328
+ proposalFunctionInputs,
329
+ release.GuardiansSafe,
330
+ "xdc"
331
+ );
332
+ } else if (!checksOnly) {
333
+ await executeViaGuardian(
334
+ proposalContracts,
335
+ proposalEthValues,
336
+ proposalFunctionSignatures,
337
+ proposalFunctionInputs,
338
+ guardian,
339
+ networkEnv
340
+ );
341
+ }
342
+ };
343
+
344
+ const calculateReserveParams = async () => {
345
+ const celoProvider = new ethers.providers.JsonRpcProvider("https://forno.celo.org");
346
+ const gd = await ethers.getContractAt("GoodDollar", dao["production-celo"].GoodDollar);
347
+ const celoCusd = (await ethers.getContractAt("IERC20", dao["production-celo"].CUSD)).connect(celoProvider);
348
+ const gdCelo = gd.connect(celoProvider);
349
+ const totalSupplyCelo = await gdCelo.totalSupply();
350
+ const reserveBalance = await celoCusd.balanceOf(dao["production-celo"].MentoReserve);
351
+ const xdcReserveBalance = ethers.utils.parseUnits("200000", 18); //200k in xdc
352
+ const totalUSD = reserveBalance.add(xdcReserveBalance); //reserve + 200k in xdc
353
+ const xdcSupplyShare = xdcReserveBalance.mul(1e8).div(totalUSD);
354
+ const xdcGdSupplyEquivalent = totalSupplyCelo.mul(xdcSupplyShare).div(1e8);
355
+ const price = ethers.utils.parseUnits("0.00013", 8);
356
+ const celoGdSupplyEquivalent = totalSupplyCelo.sub(xdcGdSupplyEquivalent);
357
+
358
+ console.log({
359
+ totalSupplyCelo,
360
+ reserveBalance,
361
+ totalUSD,
362
+ xdcSupplyShare,
363
+ xdcGdSupplyEquivalent,
364
+ celoGdSupplyEquivalent
365
+ });
366
+
367
+ // uint32 reserveRatio = uint32(
368
+ // (cUSDBalance * 1e18 * 1e8) / (price * totalGlobalSupply)
369
+ // );
370
+ //calculate reserve ratio
371
+ const reserveRatioXdc = xdcReserveBalance
372
+ .mul(ethers.BigNumber.from("100000000")) //1e8
373
+ .mul(ethers.BigNumber.from("1000000000000000000")) //1e18
374
+ .div(xdcGdSupplyEquivalent.mul(price));
375
+ console.log(
376
+ "recommended reserve ratio for xdc:",
377
+ reserveRatioXdc.toString(),
378
+ reserveRatioXdc.div("10000000000").toNumber() / 1e8
379
+ );
380
+
381
+ //calcualte reserve ratio for celo
382
+ const reserveRatioCelo = reserveBalance
383
+ .mul(ethers.BigNumber.from("100000000")) //1e8
384
+ .mul(ethers.BigNumber.from("1000000000000000000")) //1e18
385
+ .div(celoGdSupplyEquivalent.mul(price));
386
+
387
+ console.log(
388
+ "recommended reserve ratio for celo:",
389
+ reserveRatioCelo.toString(),
390
+ reserveRatioCelo.div("10000000000").toNumber() / 1e8
391
+ );
392
+ };
393
+
394
+ export const main = async () => {
395
+ // await calculateReserveParams();
396
+ // return;
397
+ prompt.start();
398
+ const { network } = await prompt.get(["network"]);
399
+
400
+ console.log("running step:", { network });
401
+ const chain = last(network.split("-")) || "fuse";
402
+ console.log("detected chain:", chain, network);
403
+ switch (chain) {
404
+ case "mainnet":
405
+ await upgradeEthStep2(network, false);
406
+
407
+ break;
408
+ case "production":
409
+ case "fuse":
410
+ await upgradeFuseStep2(network, false);
411
+
412
+ break;
413
+ case "celo":
414
+ await upgradeCeloStep2(network, false);
415
+
416
+ break;
417
+ }
418
+ };
419
+
420
+ // upgradeCeloFix("production-celo", false).catch(console.log);
421
+ // upgradeEthFix("production-mainnet", false).catch(console.log);
422
+ upgradeFuseFix("production", false).catch(console.log);
423
+ // upgradeXdcFix("production-xdc", false).catch(console.log);
424
+ // verifyUpgradeCeloStep1("production-celo");
425
+ // main().catch(console.log);