Skip to content

Commit c37c38c

Browse files
authored
Xdc deploy (#283)
* add: improve ubi calculations * add: more verbose error * add: disthelper deployer with recipients * fix: cross chain community treasury * add: improve ubi smoothing * add: verified erc1967proxy * add: xdc gip-25 step1 ready * fix: correct expected bridge impl per chain address * fix: safe proposal and mpb settings * fix: ubi updates tests * add: env-enc * fix: claimcycle unit test * add: remove need for specific pool fee
1 parent 62d50df commit c37c38c

19 files changed

+1090
-172
lines changed

.prettierrc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
"bracketSpacing": true,
1111
"explicitTypes": "always"
1212
}
13-
},
14-
{
15-
"files": "test/**/*.ts",
16-
"options": {
17-
"printWidth": 80
18-
}
1913
}
2014
],
2115
"printWidth": 120,
@@ -24,4 +18,4 @@
2418
"explicitTypes": "always",
2519
"trailingComma": "none",
2620
"arrowParens": "avoid"
27-
}
21+
}

contracts/IUniswapV3.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ interface IUniswapV3Pool {
88

99
function token1() external view returns (address);
1010

11+
function fee() external view returns (uint24);
12+
1113
function slot0()
1214
external
1315
view
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pragma solidity >=0.8;
2+
3+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
4+
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5+
import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
6+
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
7+
import "@openzeppelin/contracts/utils/math/Math.sol";
8+
9+
import "../reserve/GenericDistributionHelper.sol";
10+
11+
contract GenericDistributionHelperTest is GenericDistributionHelper {
12+
function onDistribution(uint256 _amount) external override {
13+
revert();
14+
}
15+
}
16+
17+
contract GenericDistributionHelperTestHelper is GenericDistributionHelper {
18+
IMessagePassingBridge bridge;
19+
20+
function setOracle(IStaticOracle oracle) external {
21+
STATIC_ORACLE = oracle;
22+
}
23+
24+
function getBridge() public view override returns (IMessagePassingBridge) {
25+
return bridge;
26+
}
27+
28+
function setBridges(address _mpbBridge) external {
29+
bridge = IMessagePassingBridge(_mpbBridge);
30+
}
31+
}

contracts/reserve/GenericDistributionHelper.sol

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "@gooddollar/bridge-contracts/contracts/messagePassingBridge/IMessagePass
99
import "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";
1010

1111
import "../utils/DAOUpgradeableContract.sol";
12+
import "../IUniswapV3.sol";
1213

1314
// import "hardhat/console.sol";
1415

@@ -67,7 +68,11 @@ contract GenericDistributionHelper is
6768
);
6869
event RecipientUpdated(DistributionRecipient recipient, uint256 index);
6970
event RecipientAdded(DistributionRecipient recipient, uint256 index);
70-
event BuyNativeFailed(string reason);
71+
event BuyNativeFailed(
72+
string reason,
73+
uint256 amountToSell,
74+
uint256 amountOutMinimum
75+
);
7176

7277
receive() external payable {}
7378

@@ -90,7 +95,7 @@ contract GenericDistributionHelper is
9095
_setReserveToken(_reserveToken);
9196
}
9297

93-
function getBridge() public view returns (IMessagePassingBridge) {
98+
function getBridge() public view virtual returns (IMessagePassingBridge) {
9499
return IMessagePassingBridge(nameService.getAddress("MPBBRIDGE_CONTRACT"));
95100
}
96101

@@ -101,19 +106,15 @@ contract GenericDistributionHelper is
101106
}
102107

103108
function _setReserveToken(address _reserveToken) internal {
104-
uint24[] memory fees = new uint24[](1);
105-
fees[0] = 100;
106109
reserveToken = _reserveToken;
107-
STATIC_ORACLE.prepareSpecificFeeTiersWithTimePeriod(
110+
STATIC_ORACLE.prepareAllAvailablePoolsWithTimePeriod(
108111
reserveToken,
109112
address(nativeToken()),
110-
fees,
111113
60
112114
);
113-
STATIC_ORACLE.prepareSpecificFeeTiersWithTimePeriod(
115+
STATIC_ORACLE.prepareAllAvailablePoolsWithTimePeriod(
114116
reserveToken,
115117
gasToken,
116-
fees,
117118
60
118119
);
119120
}
@@ -148,9 +149,9 @@ contract GenericDistributionHelper is
148149
try IWETH(gasToken).withdraw(boughtNative) {
149150
// success
150151
} catch Error(string memory reason) {
151-
emit BuyNativeFailed(reason);
152+
emit BuyNativeFailed(reason, boughtNative, 0);
152153
} catch {
153-
emit BuyNativeFailed("WETH withdraw failed");
154+
emit BuyNativeFailed("WETH withdraw failed", boughtNative, 0);
154155
}
155156
}
156157

@@ -239,48 +240,41 @@ contract GenericDistributionHelper is
239240
function calcGDToSell(
240241
uint256 maxAmountToSell
241242
) public view returns (uint256 gdToSell, uint256 minReceived) {
242-
uint24[] memory fees = new uint24[](1);
243-
fees[0] = 100;
244243
uint256 nativeToBuy = feeSettings.minBalanceForFees *
245244
3 -
246245
address(this).balance;
247246
(uint256 nativeValueInUSD, ) = STATIC_ORACLE
248-
.quoteSpecificFeeTiersWithTimePeriod(
247+
.quoteAllAvailablePoolsWithTimePeriod(
249248
uint128(nativeToBuy),
250249
gasToken,
251250
reserveToken,
252-
fees,
253251
60 //last 1 minute
254252
);
255253

256-
(gdToSell, ) = STATIC_ORACLE.quoteSpecificFeeTiersWithTimePeriod(
254+
(gdToSell, ) = STATIC_ORACLE.quoteAllAvailablePoolsWithTimePeriod(
257255
uint128(nativeValueInUSD),
258256
reserveToken,
259257
address(nativeToken()),
260-
fees,
261258
60 //last 1 minute
262259
);
263260

264261
minReceived = nativeToBuy;
265262
if (gdToSell > maxAmountToSell) {
266263
gdToSell = maxAmountToSell;
267264

268-
fees[0] = 100;
269265
// gdToSell = (nativeValueInUSD * 1e18) / gdPriceInUSD; // mul by 1e18 so result is in 18 decimals
270266
(uint256 minReceivedCUSD, ) = STATIC_ORACLE
271-
.quoteSpecificFeeTiersWithTimePeriod(
267+
.quoteAllAvailablePoolsWithTimePeriod(
272268
uint128(gdToSell),
273269
address(nativeToken()),
274270
reserveToken,
275-
fees,
276271
60 //last 1 minute
277272
);
278273

279-
(minReceived, ) = STATIC_ORACLE.quoteSpecificFeeTiersWithTimePeriod(
274+
(minReceived, ) = STATIC_ORACLE.quoteAllAvailablePoolsWithTimePeriod(
280275
uint128(minReceivedCUSD),
281276
reserveToken,
282277
gasToken,
283-
fees,
284278
60 //last 1 minute
285279
);
286280
}
@@ -290,15 +284,33 @@ contract GenericDistributionHelper is
290284
uint256 amountToSell,
291285
uint256 minReceived
292286
) internal returns (uint256 nativeBought) {
287+
address[] memory gdPools = STATIC_ORACLE.getAllPoolsForPair(
288+
reserveToken,
289+
address(nativeToken())
290+
);
291+
address[] memory gasPools = STATIC_ORACLE.getAllPoolsForPair(
292+
reserveToken,
293+
gasToken
294+
);
295+
uint24 gasFee = IUniswapV3Pool(gasPools[0]).fee();
296+
uint24 gdFee = IUniswapV3Pool(gdPools[0]).fee();
297+
for (uint i = 1; i < gasPools.length; i++) {
298+
uint24 fee = IUniswapV3Pool(gasPools[i]).fee();
299+
gasFee = gasFee < fee ? gasFee : fee;
300+
}
301+
for (uint i = 1; i < gdPools.length; i++) {
302+
uint24 fee = IUniswapV3Pool(gdPools[i]).fee();
303+
gdFee = gasFee < fee ? gasFee : fee;
304+
}
293305
ERC20(nativeToken()).approve(address(ROUTER), amountToSell);
294306
uint256 amountOutMinimum = (minReceived * (100 - feeSettings.maxSlippage)) /
295307
100; // 5% slippage
296308
ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
297309
path: abi.encodePacked(
298310
nativeToken(),
299-
uint24(100),
311+
gdFee,
300312
reserveToken,
301-
uint24(100),
313+
gasFee,
302314
gasToken
303315
),
304316
recipient: address(this),
@@ -308,7 +320,7 @@ contract GenericDistributionHelper is
308320
try ROUTER.exactInput(params) returns (uint256 amountOut) {
309321
return amountOut;
310322
} catch Error(string memory reason) {
311-
emit BuyNativeFailed(reason);
323+
emit BuyNativeFailed(reason, amountToSell, amountOutMinimum);
312324
return 0;
313325
}
314326
}

contracts/ubi/UBISchemeV2.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ contract UBISchemeV2 is DAOUpgradeableContract {
269269
dailyCyclePool /
270270
max((prevDayClaimers * reserveFactor) / 10000, minActiveUsers);
271271
//update minActiveUsers as claimers grow
272-
minActiveUsers = max(prevDayClaimers / 2, minActiveUsers);
272+
minActiveUsers = (prevDayClaimers + minActiveUsers * 29) / 30; //smooth it a bit
273273

274274
emit UBICalculated(currentDay, dailyUbi, block.number);
275275
}
@@ -347,7 +347,8 @@ contract UBISchemeV2 is DAOUpgradeableContract {
347347
bool shouldStartEarlyCycle = currentDayInCycle() + 1 >=
348348
currentCycleLength ||
349349
nextDailyPool > (dailyCyclePool * 105) / 100 ||
350-
currentBalance < (dailyCyclePool * (cycleLength - currentDayInCycle()));
350+
currentBalance <
351+
(dailyCyclePool * (cycleLength - currentDayInCycle() - 1));
351352

352353
uint256 _dailyCyclePool = dailyCyclePool;
353354
uint256 _dailyUbi;

contracts/utils/ProxyFactory1967.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: MIT
22

3+
//pragma solidity =0.8.16; // xdc deployed version
34
pragma solidity >=0.8;
45

56
import "@openzeppelin/contracts/proxy/Proxy.sol";

hardhat.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { sumStakersGdRewards } from "./scripts/staking/stakersGdRewardsCalculati
2323
import { verify } from "./scripts/verify";
2424
import { ethers } from "ethers";
2525
import { fstat, readFileSync, writeFileSync } from "fs";
26+
import * as envEnc from "@chainlink/env-enc";
27+
envEnc.config();
28+
2629
config();
2730

2831
const mnemonic = process.env.MNEMONIC || "test test test test test test test test test test test junk";
@@ -38,7 +41,7 @@ const MAINNET_URL = "https://mainnet.infura.io/v3/" + infura_api;
3841

3942
const xdc = {
4043
accounts: { mnemonic },
41-
url: "https://rpc.xdc.network",
44+
url: "https://rpc.ankr.com/xdc/ef07ba6590dc46db9275bba237aed203ed6d5fb3e3203ff237a82a841f75b2ce",
4245
gas: 3000000,
4346
gasPrice: 12.5e9,
4447
chainId: 50
@@ -286,8 +289,8 @@ const hhconfig: HardhatUserConfig = {
286289
accounts: [deployerPrivateKey]
287290
},
288291
"development-xdc": {
289-
...xdc,
290-
accounts: [deployerPrivateKey]
292+
...xdc
293+
// url: "http://localhost:8545"
291294
}
292295
},
293296
mocha: {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gooddollar/goodprotocol",
3-
"version": "2.0.34-beta.2",
3+
"version": "2.1.0",
44
"description": "GoodDollar Protocol",
55
"engines": {
66
"node": ">=16.x"
@@ -66,6 +66,7 @@
6666
"@babel/preset-env": "*",
6767
"@babel/register": "*",
6868
"@celo-tools/celo-ethers-wrapper": "^0.4.0",
69+
"@chainlink/env-enc": "^1.0.5",
6970
"@gnosis.pm/safe-core-sdk": "^3.2.0",
7071
"@gnosis.pm/safe-core-sdk-types": "^1.7.0",
7172
"@gnosis.pm/safe-ethers-lib": "^1.7.0",
@@ -82,7 +83,7 @@
8283
"@openzeppelin/contracts": "^4.8.0",
8384
"@openzeppelin/contracts-upgradeable": "^4.8.0",
8485
"@openzeppelin/hardhat-upgrades": "^1.22.1",
85-
"@safe-global/api-kit": "^3.0.1",
86+
"@safe-global/api-kit": "^4.0.0",
8687
"@safe-global/protocol-kit": "^6.0.2",
8788
"@safe-global/types-kit": "^2.0.1",
8889
"@superfluid-finance/ethereum-contracts": "1.8.1",

releases/deployment.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,5 +667,22 @@
667667
"MentoExchangeProvider": "0x1fad5a713da1f51e2a1ac4ca2e1d621919f0aba0",
668668
"MentoExpansionController": "0xe69bd25ca06264780e377e8d81a59271299adb36",
669669
"MentoProxyAdmin": "0x54f44fBE2943c2196D94831288E716cdeAF5657"
670+
},
671+
"production-xdc": {
672+
"ProxyFactory": "0x5BE34022c26FA03a8d6926314a42414c7ca2dF51",
673+
"GuardiansSafe": "0xE0c5daa7CC6F88d29505f702a53bb5E67600e7Ec",
674+
"CUSD": "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
675+
"ReserveToken": "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
676+
"Identity": "0x27a4a02C9ed591E1a86e2e5D05870292c34622C9",
677+
"DAOCreator": "0xa2B9993D198904e4bdCE48379FDff65405607F42",
678+
"FeeFormula": "0xf4e9Af892A09F04B7408266777198206E7f80D46",
679+
"NameService": "0x1e5154Bf5e31FF56051bbd45958b879Fb7a290FE",
680+
"Avatar": "0x21eaC3fE218307BeE0463F77EBcA3b50F452C0Ce",
681+
"GoodDollar": "0xEC2136843a983885AebF2feB3931F73A8eBEe50c",
682+
"Controller": "0x75a8bE0C2dEaDEd8Fc9ECEB5F01ad0B979b7AD03",
683+
"AdminWallet": "0x66fc1bE551f752706130b6f54d84141F8c2Ae8Bb",
684+
"Faucet": "0x7344Da1Be296f03fbb8082aDaC5696058B5a9bd9",
685+
"Invites": "0x6bd698566632bf2e81e2278f1656CB24aAF06D2e",
686+
"UBIScheme": "0x22867567E2D80f2049200E25C6F31CB6Ec2F0faf"
670687
}
671688
}

scripts/multichain-deploy/0_proxyFactory-deploy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export const deployUniversalProxyFactory = async () => {
3232
if (name.includes("staging")) {
3333
deployTx.gasLimit = 892000;
3434
} else if (name.includes("production")) {
35-
deployTx.gasLimit = 890000;
35+
// deployTx.gasLimit = 890000; // was used on celo
36+
deployTx.gasLimit = 1500000; //xdc needs more gas
3637
}
3738

3839
const rawTx = ethers.utils.serializeTransaction(deployTx);
@@ -121,8 +122,8 @@ const deployProxyMethod2 = async (defaultAdmin = null) => {
121122
await verifyContract(deployed.address, artifact.sourceName + ":" + artifact.contractName);
122123
};
123124
export const main = async (networkName = name) => {
124-
// await deployProxy();
125-
await deployProxyMethod2();
125+
await deployProxy();
126+
// await deployProxyMethod2();
126127
};
127128

128129
if (process.argv[1].includes("proxyFactory-deploy")) {

0 commit comments

Comments
 (0)