@gooddollar/goodprotocol 2.0.34-beta.1 → 2.0.34-beta.3
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.
- package/artifacts/abis/GenericDistributionHelper.min.json +1 -0
- package/artifacts/abis/INonfungiblePositionManager.min.json +1 -0
- package/artifacts/abis/IUniswapV3Pool.min.json +1 -0
- package/artifacts/abis/UBISchemeV2.min.json +1 -1
- package/artifacts/contracts/IUniswapV3.sol/INonfungiblePositionManager.dbg.json +4 -0
- package/artifacts/contracts/IUniswapV3.sol/INonfungiblePositionManager.json +102 -0
- package/artifacts/contracts/IUniswapV3.sol/IUniswapV3Pool.dbg.json +4 -0
- package/artifacts/contracts/IUniswapV3.sol/IUniswapV3Pool.json +93 -0
- package/artifacts/contracts/reserve/GenericDistributionHelper.sol/GenericDistributionHelper.dbg.json +4 -0
- package/artifacts/contracts/reserve/GenericDistributionHelper.sol/GenericDistributionHelper.json +931 -0
- package/artifacts/contracts/ubi/UBISchemeV2.sol/UBISchemeV2.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBISchemeV2.sol/UBISchemeV2.json +7 -2
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.json +2 -2
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.json +2 -2
- package/contracts/IUniswapV3.sol +51 -0
- package/contracts/reserve/GenericDistributionHelper.sol +319 -0
- package/contracts/ubi/UBISchemeV2.sol +8 -4
- package/contracts/utils/ProxyFactory1967.sol +16 -18
- package/hardhat.config.ts +14 -6
- package/package.json +1 -1
- package/releases/deploy-settings.json +15 -2
- package/releases/deployment.json +72 -46
- package/scripts/multichain-deploy/0_proxyFactory-deploy.ts +4 -3
- package/scripts/multichain-deploy/1_basicdao-deploy.ts +18 -9
- package/scripts/multichain-deploy/4_ubi-deploy.ts +1 -1
- package/scripts/multichain-deploy/8_disthelper-deploy.ts +152 -0
- package/scripts/multichain-deploy/createUniswapTestPools.ts +163 -0
- package/scripts/multichain-deploy/helpers.ts +76 -6
- package/scripts/proposals/gip-25-xdc-upgrade.ts +438 -0
- package/test/helpers.ts +1 -1
- package/test/ubi/UBISchemeV2.test.ts +35 -108
- package/types/@uniswap/index.ts +2 -0
- package/types/@uniswap/v2-periphery/contracts/index.ts +5 -0
- package/types/@uniswap/v2-periphery/contracts/interfaces/IWETH.ts +159 -0
- package/types/@uniswap/v2-periphery/contracts/interfaces/index.ts +4 -0
- package/types/@uniswap/v2-periphery/index.ts +5 -0
- package/types/contracts/IUniswapV3.sol/INonfungiblePositionManager.ts +151 -0
- package/types/contracts/IUniswapV3.sol/IUniswapV3Factory.ts +155 -0
- package/types/contracts/IUniswapV3.sol/IUniswapV3Pool.ts +179 -0
- package/types/contracts/IUniswapV3.sol/index.ts +5 -0
- package/types/contracts/index.ts +2 -0
- package/types/contracts/reserve/GenericDistributionHelper copy.sol/GenericDistributionHelper.ts +1247 -0
- package/types/contracts/reserve/GenericDistributionHelper copy.sol/index.ts +4 -0
- package/types/contracts/reserve/GenericDistributionHelper.ts +1304 -0
- package/types/contracts/reserve/index.ts +1 -0
- package/types/contracts/ubi/UBISchemeV2.ts +14 -3
- package/types/factories/@uniswap/index.ts +1 -0
- package/types/factories/@uniswap/v2-periphery/contracts/index.ts +4 -0
- package/types/factories/@uniswap/v2-periphery/contracts/interfaces/IWETH__factory.ts +67 -0
- package/types/factories/@uniswap/v2-periphery/contracts/interfaces/index.ts +4 -0
- package/types/factories/@uniswap/v2-periphery/index.ts +4 -0
- package/types/factories/contracts/IUniswapV3.sol/INonfungiblePositionManager__factory.ts +121 -0
- package/types/factories/contracts/IUniswapV3.sol/IUniswapV3Factory__factory.ts +84 -0
- package/types/factories/contracts/IUniswapV3.sol/IUniswapV3Pool__factory.ts +108 -0
- package/types/factories/contracts/IUniswapV3.sol/index.ts +5 -0
- package/types/factories/contracts/index.ts +1 -0
- package/types/factories/contracts/reserve/GenericDistributionHelper copy.sol/GenericDistributionHelper__factory.ts +935 -0
- package/types/factories/contracts/reserve/GenericDistributionHelper copy.sol/index.ts +4 -0
- package/types/factories/contracts/reserve/GenericDistributionHelper__factory.ts +987 -0
- package/types/factories/contracts/reserve/index.ts +1 -0
- package/types/factories/contracts/ubi/UBISchemeV2__factory.ts +6 -1
- package/types/factories/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy__factory.ts +1 -1
- package/types/factories/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967__factory.ts +1 -1
- package/types/hardhat.d.ts +36 -0
- package/types/index.ts +8 -0
|
@@ -24,6 +24,7 @@ import ProtocolSettings from "../../releases/deploy-settings.json";
|
|
|
24
24
|
import dao from "../../releases/deployment.json";
|
|
25
25
|
import { TransactionResponse } from "@ethersproject/providers";
|
|
26
26
|
import { getImplementationAddress } from "@openzeppelin/upgrades-core";
|
|
27
|
+
import { IdentityV3 } from "../../types";
|
|
27
28
|
const printDeploy = async (c: Contract | TransactionResponse): Promise<Contract | TransactionResponse> => {
|
|
28
29
|
if (c instanceof Contract) {
|
|
29
30
|
await c.deployed();
|
|
@@ -60,8 +61,8 @@ export const createDAO = async () => {
|
|
|
60
61
|
const FeeFormulaFactory = new ethers.ContractFactory(FeeFormulaABI.abi, FeeFormulaABI.bytecode, root);
|
|
61
62
|
|
|
62
63
|
console.log("deploying identity");
|
|
63
|
-
let Identity;
|
|
64
|
-
if (release.Identity) Identity = await ethers.getContractAt("IdentityV3", release.Identity);
|
|
64
|
+
let Identity: IdentityV3;
|
|
65
|
+
if (release.Identity) Identity = (await ethers.getContractAt("IdentityV3", release.Identity)) as IdentityV3;
|
|
65
66
|
else
|
|
66
67
|
Identity = (await deployDeterministic(
|
|
67
68
|
{
|
|
@@ -70,7 +71,7 @@ export const createDAO = async () => {
|
|
|
70
71
|
isUpgradeable: true
|
|
71
72
|
},
|
|
72
73
|
[root.address, ethers.constants.AddressZero]
|
|
73
|
-
).then(printDeploy)) as
|
|
74
|
+
).then(printDeploy)) as IdentityV3;
|
|
74
75
|
|
|
75
76
|
let daoCreator;
|
|
76
77
|
if (release.DAOCreator) daoCreator = await DAOCreatorFactory.attach(release.DAOCreator);
|
|
@@ -131,10 +132,7 @@ export const createDAO = async () => {
|
|
|
131
132
|
).then(printDeploy)) as Contract;
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
// await Identity.setAuthenticationPeriod(365).then(printDeploy);
|
|
136
|
-
|
|
137
|
-
const avatar = await daoCreator.avatar();
|
|
135
|
+
const avatar = release.Avatar || (await daoCreator.avatar());
|
|
138
136
|
let Avatar = new ethers.Contract(
|
|
139
137
|
avatar,
|
|
140
138
|
["function owner() view returns (address)", "function nativeToken() view returns (address)"],
|
|
@@ -151,7 +149,7 @@ export const createDAO = async () => {
|
|
|
151
149
|
["function owner() view returns (address)", "function nativeToken() view returns (address)"],
|
|
152
150
|
root
|
|
153
151
|
);
|
|
154
|
-
let schemes = [daoOwner,
|
|
152
|
+
let schemes = [daoOwner, release.GuardiansSafe];
|
|
155
153
|
|
|
156
154
|
console.log("setting schemes", schemes);
|
|
157
155
|
|
|
@@ -160,7 +158,7 @@ export const createDAO = async () => {
|
|
|
160
158
|
Avatar.address,
|
|
161
159
|
schemes,
|
|
162
160
|
schemes.map(_ => ethers.constants.HashZero),
|
|
163
|
-
["0x0000001f", "
|
|
161
|
+
["0x0000001f", "0x0000001f"],
|
|
164
162
|
""
|
|
165
163
|
)
|
|
166
164
|
.then(printDeploy);
|
|
@@ -172,6 +170,7 @@ export const createDAO = async () => {
|
|
|
172
170
|
|
|
173
171
|
const controller = await Avatar.owner();
|
|
174
172
|
|
|
173
|
+
console.log("deploying nameservice");
|
|
175
174
|
const NameService = await deployDeterministic({ name: "NameService", isUpgradeable: true }, [
|
|
176
175
|
controller,
|
|
177
176
|
["CONTROLLER", "AVATAR", "IDENTITY", "GOODDOLLAR"].map(_ => ethers.utils.keccak256(ethers.utils.toUtf8Bytes(_))),
|
|
@@ -189,6 +188,16 @@ export const createDAO = async () => {
|
|
|
189
188
|
if (isProduction) {
|
|
190
189
|
console.log("renouncing minting rights on production env");
|
|
191
190
|
await GoodDollar.renounceMinter().then(printDeploy);
|
|
191
|
+
const ctrl = await ethers.getContractAt("Controller", await Avatar.owner());
|
|
192
|
+
console.log("setting identity authentication period to 180 days");
|
|
193
|
+
await ctrl
|
|
194
|
+
.genericCall(
|
|
195
|
+
Identity.address,
|
|
196
|
+
Identity.interface.encodeFunctionData("setAuthenticationPeriod", [180]),
|
|
197
|
+
Avatar.address,
|
|
198
|
+
0
|
|
199
|
+
)
|
|
200
|
+
.then(printDeploy);
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
const daoOwnerDaoPermissions = await Controller.getSchemePermissions(daoOwner, Avatar.address);
|
|
@@ -60,7 +60,7 @@ export const deployHelpers = async () => {
|
|
|
60
60
|
factory: await ethers.getContractFactory("UBISchemeV2"),
|
|
61
61
|
isUpgradeable: true
|
|
62
62
|
},
|
|
63
|
-
[release.NameService]
|
|
63
|
+
[release.NameService, protocolSettings.ubi.minActiveUsers]
|
|
64
64
|
).then(printDeploy)) as Contract;
|
|
65
65
|
|
|
66
66
|
const torelease = {
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/***
|
|
2
|
+
* Deploy helper contracts
|
|
3
|
+
* AdminWallet, Faucet, Invites
|
|
4
|
+
*/
|
|
5
|
+
import { network, ethers, upgrades, run } from "hardhat";
|
|
6
|
+
import { Contract } from "ethers";
|
|
7
|
+
import { defaultsDeep } from "lodash";
|
|
8
|
+
import { getImplementationAddress } from "@openzeppelin/upgrades-core";
|
|
9
|
+
import {
|
|
10
|
+
deployDeterministic,
|
|
11
|
+
executeViaGuardian,
|
|
12
|
+
executeViaSafe,
|
|
13
|
+
verifyContract,
|
|
14
|
+
verifyProductionSigner
|
|
15
|
+
} from "./helpers";
|
|
16
|
+
import releaser from "../releaser";
|
|
17
|
+
import ProtocolSettings from "../../releases/deploy-settings.json";
|
|
18
|
+
import dao from "../../releases/deployment.json";
|
|
19
|
+
import { TransactionResponse } from "@ethersproject/providers";
|
|
20
|
+
import { keccak256, toUtf8Bytes } from "ethers/lib/utils";
|
|
21
|
+
|
|
22
|
+
const { name } = network;
|
|
23
|
+
|
|
24
|
+
const printDeploy = async (c: Contract | TransactionResponse): Promise<Contract | TransactionResponse> => {
|
|
25
|
+
if (c instanceof Contract) {
|
|
26
|
+
await c.deployed();
|
|
27
|
+
console.log("deployed to: ", c.address);
|
|
28
|
+
}
|
|
29
|
+
if (c.wait) {
|
|
30
|
+
await c.wait();
|
|
31
|
+
console.log("tx done:", c.hash);
|
|
32
|
+
}
|
|
33
|
+
return c;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const deployHelpers = async () => {
|
|
37
|
+
const viaGuardians = false;
|
|
38
|
+
|
|
39
|
+
let protocolSettings = defaultsDeep({}, ProtocolSettings[network.name], ProtocolSettings["default"]);
|
|
40
|
+
let release: { [key: string]: any } = dao[network.name];
|
|
41
|
+
|
|
42
|
+
let [root, ...signers] = await ethers.getSigners();
|
|
43
|
+
const isProduction = network.name.includes("production");
|
|
44
|
+
let networkEnv = network.name.split("-")[0];
|
|
45
|
+
const celoNetwork = networkEnv + "-celo";
|
|
46
|
+
|
|
47
|
+
if (isProduction) verifyProductionSigner(root);
|
|
48
|
+
//generic call permissions
|
|
49
|
+
let schemeMock = root;
|
|
50
|
+
|
|
51
|
+
console.log("got signers:", {
|
|
52
|
+
network,
|
|
53
|
+
root: root.address,
|
|
54
|
+
schemeMock: schemeMock.address,
|
|
55
|
+
balance: await ethers.provider.getBalance(root.address).then(_ => _.toString())
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log("deploying dist helper");
|
|
59
|
+
const DistHelper = (await deployDeterministic(
|
|
60
|
+
{
|
|
61
|
+
name: "DistributionHelper",
|
|
62
|
+
factory: await ethers.getContractFactory("GenericDistributionHelper"),
|
|
63
|
+
isUpgradeable: true
|
|
64
|
+
},
|
|
65
|
+
[
|
|
66
|
+
release.NameService,
|
|
67
|
+
release.StaticOracle,
|
|
68
|
+
protocolSettings.reserve.gasToken,
|
|
69
|
+
protocolSettings.reserve.reserveToken,
|
|
70
|
+
release.UniswapV3Router,
|
|
71
|
+
[ethers.utils.parseEther("100"), ethers.utils.parseEther("100"), 5, 5]
|
|
72
|
+
]
|
|
73
|
+
).then(printDeploy)) as Contract;
|
|
74
|
+
|
|
75
|
+
const torelease = {
|
|
76
|
+
DistributionHelper: DistHelper.address
|
|
77
|
+
};
|
|
78
|
+
release = {
|
|
79
|
+
...release,
|
|
80
|
+
...torelease
|
|
81
|
+
};
|
|
82
|
+
await releaser(torelease, network.name, "deployment", false);
|
|
83
|
+
|
|
84
|
+
console.log("setting nameservice addresses via guardian");
|
|
85
|
+
const proposalActions = [
|
|
86
|
+
[
|
|
87
|
+
release.NameService, //nameservice
|
|
88
|
+
"setAddresses(bytes32[],address[])", //add ubischeme
|
|
89
|
+
ethers.utils.defaultAbiCoder.encode(
|
|
90
|
+
["bytes32[]", "address[]"],
|
|
91
|
+
[[keccak256(toUtf8Bytes("DISTRIBUTION_HELPER"))], [DistHelper.address]]
|
|
92
|
+
),
|
|
93
|
+
0
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
DistHelper.address,
|
|
97
|
+
"addOrUpdateRecipient((uint32,uint32,address,uint8))",
|
|
98
|
+
ethers.utils.defaultAbiCoder.encode(
|
|
99
|
+
["uint32", "uint32", "address", "uint8"],
|
|
100
|
+
[dao[celoNetwork].CommunitySafe ? 9000 : 10000, network.config.chainId, release.UBIScheme, 1] //90% to ubi scheme
|
|
101
|
+
),
|
|
102
|
+
0
|
|
103
|
+
]
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
if (dao[celoNetwork].CommunitySafe) {
|
|
107
|
+
proposalActions.push([
|
|
108
|
+
DistHelper.address,
|
|
109
|
+
"addOrUpdateRecipient((uint32,uint32,address,uint8))",
|
|
110
|
+
ethers.utils.defaultAbiCoder.encode(
|
|
111
|
+
["uint32", "uint32", "address", "uint8"],
|
|
112
|
+
[1000, 42220, dao[celoNetwork].CommunitySafe, network.name === celoNetwork ? 1 : 0] //10% to celo community safe, use LZ bridge if not on celo
|
|
113
|
+
),
|
|
114
|
+
0
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
const [proposalContracts, proposalFunctionSignatures, proposalFunctionInputs, proposalEthValues] = [
|
|
118
|
+
proposalActions.map(_ => _[0]),
|
|
119
|
+
proposalActions.map(_ => _[1]),
|
|
120
|
+
proposalActions.map(_ => _[2]),
|
|
121
|
+
proposalActions.map(_ => _[3])
|
|
122
|
+
];
|
|
123
|
+
try {
|
|
124
|
+
if (viaGuardians) {
|
|
125
|
+
await executeViaSafe(
|
|
126
|
+
proposalContracts,
|
|
127
|
+
proposalEthValues,
|
|
128
|
+
proposalFunctionSignatures,
|
|
129
|
+
proposalFunctionInputs,
|
|
130
|
+
protocolSettings.guardiansSafe
|
|
131
|
+
);
|
|
132
|
+
} else {
|
|
133
|
+
await executeViaGuardian(
|
|
134
|
+
proposalContracts,
|
|
135
|
+
proposalEthValues,
|
|
136
|
+
proposalFunctionSignatures,
|
|
137
|
+
proposalFunctionInputs,
|
|
138
|
+
root
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.error("proposal execution failed...", e.message);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let impl = await getImplementationAddress(ethers.provider, DistHelper.address);
|
|
146
|
+
await verifyContract(impl, "contracts/reserve/GenericDistributionHelper.sol:GenericDistributionHelper", network.name);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const main = async (networkName = name) => {
|
|
150
|
+
await deployHelpers();
|
|
151
|
+
};
|
|
152
|
+
main();
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { network, ethers, upgrades, run } from "hardhat";
|
|
2
|
+
import ProtocolSettings from "../../releases/deploy-settings.json";
|
|
3
|
+
import dao from "../../releases/deployment.json";
|
|
4
|
+
import { defaultsDeep } from "lodash";
|
|
5
|
+
|
|
6
|
+
import { IUniswapV3Factory, IUniswapV3Pool, INonfungiblePositionManager, IERC20 } from "../../types";
|
|
7
|
+
const V3Factory = "0x30f317a9ec0f0d06d5de0f8d248ec3506b7e4a8a";
|
|
8
|
+
const NFPM = "0x6d22833398772d7da9a7cbcfdee98342cce154d4";
|
|
9
|
+
const STABLE_DECIMALS = 6; //USDC
|
|
10
|
+
const GASPRICE_STABLE = 0.08;
|
|
11
|
+
const POOL_FEE = 100; // 0.01%
|
|
12
|
+
const main = async () => {
|
|
13
|
+
let protocolSettings = defaultsDeep({}, ProtocolSettings[network.name], ProtocolSettings["default"]);
|
|
14
|
+
let release: { [key: string]: any } = dao[network.name];
|
|
15
|
+
let [root] = await ethers.getSigners();
|
|
16
|
+
console.log("got signers:", {
|
|
17
|
+
root: root.address,
|
|
18
|
+
balance: await ethers.provider.getBalance(root.address).then(_ => _.toString())
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const v3Factory = (await ethers.getContractAt("IUniswapV3Factory", V3Factory)) as IUniswapV3Factory;
|
|
22
|
+
const nfpm = (await ethers.getContractAt("INonfungiblePositionManager", NFPM)) as INonfungiblePositionManager;
|
|
23
|
+
|
|
24
|
+
// create G$<>Stable pool
|
|
25
|
+
console.log("creating G$<>Stable pool", {
|
|
26
|
+
gd: release.GoodDollar,
|
|
27
|
+
stable: protocolSettings.reserve.reserveToken,
|
|
28
|
+
fee: POOL_FEE
|
|
29
|
+
});
|
|
30
|
+
const poolExists = await v3Factory.getPool(protocolSettings.reserve.reserveToken, release.GoodDollar, POOL_FEE);
|
|
31
|
+
if (poolExists !== ethers.constants.AddressZero) {
|
|
32
|
+
console.log("pool already exists at:", poolExists);
|
|
33
|
+
} else {
|
|
34
|
+
await (
|
|
35
|
+
await v3Factory.createPool(protocolSettings.reserve.reserveToken, release.GoodDollar, POOL_FEE, {
|
|
36
|
+
gasLimit: 5000000
|
|
37
|
+
})
|
|
38
|
+
).wait();
|
|
39
|
+
}
|
|
40
|
+
const gdstablePool = (await ethers.getContractAt(
|
|
41
|
+
"IUniswapV3Pool",
|
|
42
|
+
await v3Factory.getPool(release.GoodDollar, protocolSettings.reserve.reserveToken, POOL_FEE)
|
|
43
|
+
)) as IUniswapV3Pool;
|
|
44
|
+
|
|
45
|
+
//get pool price
|
|
46
|
+
const { sqrtPriceX96 } = await gdstablePool.slot0();
|
|
47
|
+
|
|
48
|
+
const existingPrice = (Number(sqrtPriceX96.toString()) / 2 ** 96) ** 2;
|
|
49
|
+
console.log("created pool at:", gdstablePool.address, { existingPrice });
|
|
50
|
+
let price = BigInt(Math.sqrt(10000 * (10 ** (18 - STABLE_DECIMALS))) * 2 ** 96); //1 G$ = 0.0001 Stable
|
|
51
|
+
let amount1 = ethers.utils.parseUnits("50000", 18);
|
|
52
|
+
let amount0 = ethers.utils.parseUnits("5", STABLE_DECIMALS);
|
|
53
|
+
|
|
54
|
+
if ((await gdstablePool.token0()).toLowerCase() === release.GoodDollar.toLowerCase()) {
|
|
55
|
+
price = BigInt(Math.sqrt(0.0001 * (10 ** (STABLE_DECIMALS - 18))) * 2 ** 96);
|
|
56
|
+
amount0 = ethers.utils.parseUnits("50000", 18);
|
|
57
|
+
amount1 = ethers.utils.parseUnits("5", STABLE_DECIMALS);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (existingPrice > 0) {
|
|
61
|
+
console.log("pool already initialized");
|
|
62
|
+
price = BigInt(Math.sqrt(existingPrice) * 2 ** 96); //1 G$ = 0.0001 Stable
|
|
63
|
+
} else {
|
|
64
|
+
await (await gdstablePool.initialize(price)).wait();
|
|
65
|
+
console.log("initialized pool with price:", price.toString(), { amount0, amount1 });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// print allowance for nfpm
|
|
69
|
+
const stable = (await ethers.getContractAt("IERC20", protocolSettings.reserve.reserveToken)) as IERC20;
|
|
70
|
+
const gd = (await ethers.getContractAt("IERC20", release.GoodDollar)) as IERC20;
|
|
71
|
+
let stableAllowance = await stable.allowance(root.address, NFPM);
|
|
72
|
+
const gdAllowance = await gd.allowance(root.address, NFPM);
|
|
73
|
+
console.log("stable allowance for NFPM:", ethers.utils.formatUnits(stableAllowance, STABLE_DECIMALS));
|
|
74
|
+
console.log("G$ allowance for NFPM:", ethers.utils.formatUnits(gdAllowance, 18));
|
|
75
|
+
|
|
76
|
+
await (
|
|
77
|
+
await nfpm.mint({
|
|
78
|
+
token0: await gdstablePool.token0(),
|
|
79
|
+
token1: await gdstablePool.token1(),
|
|
80
|
+
fee: POOL_FEE,
|
|
81
|
+
tickLower: -887220,
|
|
82
|
+
tickUpper: 887220,
|
|
83
|
+
amount0Desired: amount0,
|
|
84
|
+
amount1Desired: amount1,
|
|
85
|
+
amount0Min: amount0.mul(8).div(10),
|
|
86
|
+
amount1Min: amount1.mul(8).div(10),
|
|
87
|
+
recipient: root.address,
|
|
88
|
+
deadline: Math.floor(Date.now() / 1000) + 60 * 10
|
|
89
|
+
})
|
|
90
|
+
).wait();
|
|
91
|
+
|
|
92
|
+
console.log("creating gastoken<>Stable pool", {
|
|
93
|
+
gasToken: protocolSettings.reserve.gasToken,
|
|
94
|
+
stable: protocolSettings.reserve.reserveToken,
|
|
95
|
+
fee: POOL_FEE
|
|
96
|
+
});
|
|
97
|
+
const gaspoolExists = await v3Factory.getPool(
|
|
98
|
+
protocolSettings.reserve.gasToken,
|
|
99
|
+
protocolSettings.reserve.reserveToken,
|
|
100
|
+
POOL_FEE
|
|
101
|
+
);
|
|
102
|
+
if (gaspoolExists !== ethers.constants.AddressZero) {
|
|
103
|
+
console.log("pool already exists at:", gaspoolExists);
|
|
104
|
+
} else {
|
|
105
|
+
await (
|
|
106
|
+
await v3Factory.createPool(protocolSettings.reserve.gasToken, protocolSettings.reserve.reserveToken, POOL_FEE, {
|
|
107
|
+
gasLimit: 5000000
|
|
108
|
+
})
|
|
109
|
+
).wait();
|
|
110
|
+
}
|
|
111
|
+
const gasstablePool = (await ethers.getContractAt(
|
|
112
|
+
"IUniswapV3Pool",
|
|
113
|
+
await v3Factory.getPool(protocolSettings.reserve.gasToken, protocolSettings.reserve.reserveToken, POOL_FEE)
|
|
114
|
+
)) as IUniswapV3Pool;
|
|
115
|
+
|
|
116
|
+
//get pool price
|
|
117
|
+
const { sqrtPriceX96: gasSqrtPriceX96 } = await gasstablePool.slot0();
|
|
118
|
+
|
|
119
|
+
const gasexistingPrice = (Number(gasSqrtPriceX96.toString()) / 2 ** 96) ** 2;
|
|
120
|
+
console.log("created pool at:", gasstablePool.address, { gasexistingPrice });
|
|
121
|
+
price = BigInt(Math.sqrt(GASPRICE_STABLE * (10 ** (18 - STABLE_DECIMALS))) * 2 ** 96); //1 G$ = 0.0001 Stable
|
|
122
|
+
amount1 = ethers.utils.parseUnits((5 / GASPRICE_STABLE).toString(), 18);
|
|
123
|
+
amount0 = ethers.utils.parseUnits("5", STABLE_DECIMALS);
|
|
124
|
+
|
|
125
|
+
if ((await gasstablePool.token0()).toLowerCase() === protocolSettings.reserve.gasToken.toLowerCase()) {
|
|
126
|
+
price = BigInt(Math.sqrt(1 / GASPRICE_STABLE / (10 ** (18 - STABLE_DECIMALS))) * 2 ** 96);
|
|
127
|
+
let temp = amount0;
|
|
128
|
+
amount0 = amount1;
|
|
129
|
+
amount1 = temp;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (gasexistingPrice > 0) {
|
|
133
|
+
console.log("pool already initialized");
|
|
134
|
+
price = BigInt(Math.sqrt(gasexistingPrice) * 2 ** 96); //1 G$ = 0.0001 Stable
|
|
135
|
+
} else {
|
|
136
|
+
await (await gasstablePool.initialize(price)).wait();
|
|
137
|
+
console.log("initialized pool with price:", price.toString(), { amount0, amount1 });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// print allowance for nfpm
|
|
141
|
+
const gasToken = (await ethers.getContractAt("IERC20", protocolSettings.reserve.gasToken)) as IERC20;
|
|
142
|
+
stableAllowance = await stable.allowance(root.address, NFPM);
|
|
143
|
+
const gasAllowance = await gasToken.allowance(root.address, NFPM);
|
|
144
|
+
console.log("stable allowance for NFPM:", ethers.utils.formatUnits(stableAllowance, STABLE_DECIMALS));
|
|
145
|
+
console.log("weth allowance for NFPM:", ethers.utils.formatUnits(gasAllowance, 18));
|
|
146
|
+
|
|
147
|
+
await (
|
|
148
|
+
await nfpm.mint({
|
|
149
|
+
token0: await gasstablePool.token0(),
|
|
150
|
+
token1: await gasstablePool.token1(),
|
|
151
|
+
fee: POOL_FEE,
|
|
152
|
+
tickLower: -887220,
|
|
153
|
+
tickUpper: 887220,
|
|
154
|
+
amount0Desired: amount0,
|
|
155
|
+
amount1Desired: amount1,
|
|
156
|
+
amount0Min: amount0.mul(8).div(10),
|
|
157
|
+
amount1Min: amount1.mul(8).div(10),
|
|
158
|
+
recipient: root.address,
|
|
159
|
+
deadline: Math.floor(Date.now() / 1000) + 60 * 10
|
|
160
|
+
})
|
|
161
|
+
).wait();
|
|
162
|
+
};
|
|
163
|
+
main();
|
|
@@ -67,6 +67,7 @@ export const deploySuperGoodDollar = async (
|
|
|
67
67
|
[superfluidHost]
|
|
68
68
|
).then(printDeploy)) as Contract;
|
|
69
69
|
|
|
70
|
+
console.log("supergoodollar logic deployed:", SuperGoodDollar.address);
|
|
70
71
|
const uupsFactory = await ethers.getContractFactory("UUPSProxy");
|
|
71
72
|
const GoodDollarProxy = (await deployDeterministic(
|
|
72
73
|
{
|
|
@@ -75,9 +76,13 @@ export const deploySuperGoodDollar = async (
|
|
|
75
76
|
},
|
|
76
77
|
[]
|
|
77
78
|
).then(printDeploy)) as Contract;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
console.log("supergoodollar proxy deployed:", GoodDollarProxy.address);
|
|
80
|
+
try {
|
|
81
|
+
await GoodDollarProxy.initializeProxy(SuperGoodDollar.address).then(printDeploy);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.log("failed initialized supergd proxy. probably already was init");
|
|
84
|
+
}
|
|
85
|
+
console.log("supergoodollar proxy initialized:", GoodDollarProxy.address);
|
|
81
86
|
let OutFlowNFT = await ethers.getContractAt("ConstantOutflowNFT", ethers.constants.AddressZero);
|
|
82
87
|
let InFlowNFT = await ethers.getContractAt("ConstantOutflowNFT", ethers.constants.AddressZero);
|
|
83
88
|
|
|
@@ -103,9 +108,13 @@ export const deploySuperGoodDollar = async (
|
|
|
103
108
|
await InFlowNFT.initializeProxy(superfluidInflowNFTLogic);
|
|
104
109
|
}
|
|
105
110
|
console.log("initializing supergooddollar");
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
111
|
+
try {
|
|
112
|
+
await SuperGoodDollar.attach(GoodDollarProxy.address)[
|
|
113
|
+
"initialize(string,string,uint256,address,address,address,address)"
|
|
114
|
+
](...tokenArgs);
|
|
115
|
+
} catch (e) {
|
|
116
|
+
console.log("failed initializing supergd. probably already was init");
|
|
117
|
+
}
|
|
109
118
|
|
|
110
119
|
const GoodDollar = await ethers.getContractAt("ISuperGoodDollar", GoodDollarProxy.address);
|
|
111
120
|
|
|
@@ -224,6 +233,67 @@ export const deployDeterministic = async (contract, args: any[], factoryOpts = {
|
|
|
224
233
|
}
|
|
225
234
|
};
|
|
226
235
|
|
|
236
|
+
export const upgradeDeterministicToNewImplViaGuardian = async (contract, factoryOpts = {}) => {
|
|
237
|
+
try {
|
|
238
|
+
let proxyFactory: ProxyFactory1967;
|
|
239
|
+
proxyFactory = (await ethers.getContractAt("ProxyFactory1967", release.ProxyFactory)) as ProxyFactory1967;
|
|
240
|
+
const Contract =
|
|
241
|
+
(contract.factory as ContractFactory) || (await ethers.getContractFactory(contract.name, factoryOpts));
|
|
242
|
+
|
|
243
|
+
const salt = ethers.BigNumber.from(
|
|
244
|
+
ethers.utils.keccak256(ethers.utils.toUtf8Bytes(contract.salt || contract.name))
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
if (contract.isUpgradeable === true) {
|
|
248
|
+
const proxyAddr = await proxyFactory["getDeploymentAddress(uint256,address)"](
|
|
249
|
+
salt,
|
|
250
|
+
await proxyFactory.signer.getAddress()
|
|
251
|
+
);
|
|
252
|
+
const code = await ethers.provider.getCode(proxyAddr);
|
|
253
|
+
if (code && code !== "0x") {
|
|
254
|
+
const implAddr = await getImplementationAddress(ethers.provider, proxyAddr).catch(e => "0x");
|
|
255
|
+
if (implAddr && implAddr !== "0x") {
|
|
256
|
+
console.log("proxy exists and impl set already:", contract.name, proxyAddr, implAddr);
|
|
257
|
+
console.log("Deploying:", contract.name, " implementation", {
|
|
258
|
+
proxyAddr
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
const tx = await Contract.deploy(GAS_SETTINGS);
|
|
262
|
+
const impl = await tx.deployed();
|
|
263
|
+
console.log("implementation deployed:", contract.name, impl.address);
|
|
264
|
+
await countTotalGas(tx, contract.name);
|
|
265
|
+
|
|
266
|
+
const proposalContracts = [release.DistributionHelper];
|
|
267
|
+
|
|
268
|
+
const proposalEthValues = proposalContracts.map(_ => 0);
|
|
269
|
+
|
|
270
|
+
const proposalFunctionSignatures = [
|
|
271
|
+
"upgradeTo(address)" //add ubischeme
|
|
272
|
+
];
|
|
273
|
+
|
|
274
|
+
const proposalFunctionInputs = [ethers.utils.defaultAbiCoder.encode(["address"], [impl.address])];
|
|
275
|
+
let [root] = await ethers.getSigners();
|
|
276
|
+
await executeViaGuardian(
|
|
277
|
+
proposalContracts,
|
|
278
|
+
proposalEthValues,
|
|
279
|
+
proposalFunctionSignatures,
|
|
280
|
+
proposalFunctionInputs,
|
|
281
|
+
root
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
console.log("proxy upgraded:", contract.name, { proxyAddr, implAddr: impl.address });
|
|
285
|
+
return Contract.attach(proxyAddr);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
console.log("This contract is not upgradeable");
|
|
290
|
+
}
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.log("Failed deploying contract:", { contract });
|
|
293
|
+
throw e;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
227
297
|
export const executeViaGuardian = async (
|
|
228
298
|
contracts,
|
|
229
299
|
ethValues,
|