Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
"bracketSpacing": true,
"explicitTypes": "always"
}
},
{
"files": "test/**/*.ts",
"options": {
"printWidth": 80
}
}
],
"printWidth": 120,
Expand All @@ -24,4 +18,4 @@
"explicitTypes": "always",
"trailingComma": "none",
"arrowParens": "avoid"
}
}
2 changes: 2 additions & 0 deletions contracts/IUniswapV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface IUniswapV3Pool {

function token1() external view returns (address);

function fee() external view returns (uint24);

function slot0()
external
view
Expand Down
31 changes: 31 additions & 0 deletions contracts/mocks/GenericDistributionHelperTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pragma solidity >=0.8;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import "../reserve/GenericDistributionHelper.sol";

contract GenericDistributionHelperTest is GenericDistributionHelper {
function onDistribution(uint256 _amount) external override {
revert();
}
}

contract GenericDistributionHelperTestHelper is GenericDistributionHelper {
IMessagePassingBridge bridge;

function setOracle(IStaticOracle oracle) external {
STATIC_ORACLE = oracle;
}

function getBridge() public view override returns (IMessagePassingBridge) {
return bridge;
}

function setBridges(address _mpbBridge) external {
bridge = IMessagePassingBridge(_mpbBridge);
}
}
60 changes: 36 additions & 24 deletions contracts/reserve/GenericDistributionHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "@gooddollar/bridge-contracts/contracts/messagePassingBridge/IMessagePass
import "@uniswap/v2-periphery/contracts/interfaces/IWETH.sol";

import "../utils/DAOUpgradeableContract.sol";
import "../IUniswapV3.sol";

// import "hardhat/console.sol";

Expand Down Expand Up @@ -67,7 +68,11 @@ contract GenericDistributionHelper is
);
event RecipientUpdated(DistributionRecipient recipient, uint256 index);
event RecipientAdded(DistributionRecipient recipient, uint256 index);
event BuyNativeFailed(string reason);
event BuyNativeFailed(
string reason,
uint256 amountToSell,
uint256 amountOutMinimum
);

receive() external payable {}

Expand All @@ -90,7 +95,7 @@ contract GenericDistributionHelper is
_setReserveToken(_reserveToken);
}

function getBridge() public view returns (IMessagePassingBridge) {
function getBridge() public view virtual returns (IMessagePassingBridge) {
return IMessagePassingBridge(nameService.getAddress("MPBBRIDGE_CONTRACT"));
}

Expand All @@ -101,19 +106,15 @@ contract GenericDistributionHelper is
}

function _setReserveToken(address _reserveToken) internal {
uint24[] memory fees = new uint24[](1);
fees[0] = 100;
reserveToken = _reserveToken;
STATIC_ORACLE.prepareSpecificFeeTiersWithTimePeriod(
STATIC_ORACLE.prepareAllAvailablePoolsWithTimePeriod(
reserveToken,
address(nativeToken()),
fees,
60
);
STATIC_ORACLE.prepareSpecificFeeTiersWithTimePeriod(
STATIC_ORACLE.prepareAllAvailablePoolsWithTimePeriod(
reserveToken,
gasToken,
fees,
60
);
}
Expand Down Expand Up @@ -148,9 +149,9 @@ contract GenericDistributionHelper is
try IWETH(gasToken).withdraw(boughtNative) {
// success
} catch Error(string memory reason) {
emit BuyNativeFailed(reason);
emit BuyNativeFailed(reason, boughtNative, 0);
} catch {
emit BuyNativeFailed("WETH withdraw failed");
emit BuyNativeFailed("WETH withdraw failed", boughtNative, 0);
}
}

Expand Down Expand Up @@ -239,48 +240,41 @@ contract GenericDistributionHelper is
function calcGDToSell(
uint256 maxAmountToSell
) public view returns (uint256 gdToSell, uint256 minReceived) {
uint24[] memory fees = new uint24[](1);
fees[0] = 100;
uint256 nativeToBuy = feeSettings.minBalanceForFees *
3 -
address(this).balance;
(uint256 nativeValueInUSD, ) = STATIC_ORACLE
.quoteSpecificFeeTiersWithTimePeriod(
.quoteAllAvailablePoolsWithTimePeriod(
uint128(nativeToBuy),
gasToken,
reserveToken,
fees,
60 //last 1 minute
);

(gdToSell, ) = STATIC_ORACLE.quoteSpecificFeeTiersWithTimePeriod(
(gdToSell, ) = STATIC_ORACLE.quoteAllAvailablePoolsWithTimePeriod(
uint128(nativeValueInUSD),
reserveToken,
address(nativeToken()),
fees,
60 //last 1 minute
);

minReceived = nativeToBuy;
if (gdToSell > maxAmountToSell) {
gdToSell = maxAmountToSell;

fees[0] = 100;
// gdToSell = (nativeValueInUSD * 1e18) / gdPriceInUSD; // mul by 1e18 so result is in 18 decimals
(uint256 minReceivedCUSD, ) = STATIC_ORACLE
.quoteSpecificFeeTiersWithTimePeriod(
.quoteAllAvailablePoolsWithTimePeriod(
uint128(gdToSell),
address(nativeToken()),
reserveToken,
fees,
60 //last 1 minute
);

(minReceived, ) = STATIC_ORACLE.quoteSpecificFeeTiersWithTimePeriod(
(minReceived, ) = STATIC_ORACLE.quoteAllAvailablePoolsWithTimePeriod(
uint128(minReceivedCUSD),
reserveToken,
gasToken,
fees,
60 //last 1 minute
);
}
Expand All @@ -290,15 +284,33 @@ contract GenericDistributionHelper is
uint256 amountToSell,
uint256 minReceived
) internal returns (uint256 nativeBought) {
address[] memory gdPools = STATIC_ORACLE.getAllPoolsForPair(
reserveToken,
address(nativeToken())
);
address[] memory gasPools = STATIC_ORACLE.getAllPoolsForPair(
reserveToken,
gasToken
);
uint24 gasFee = IUniswapV3Pool(gasPools[0]).fee();
uint24 gdFee = IUniswapV3Pool(gdPools[0]).fee();
for (uint i = 1; i < gasPools.length; i++) {
uint24 fee = IUniswapV3Pool(gasPools[i]).fee();
gasFee = gasFee < fee ? gasFee : fee;
}
for (uint i = 1; i < gdPools.length; i++) {
uint24 fee = IUniswapV3Pool(gdPools[i]).fee();
gdFee = gasFee < fee ? gasFee : fee;
}
ERC20(nativeToken()).approve(address(ROUTER), amountToSell);
uint256 amountOutMinimum = (minReceived * (100 - feeSettings.maxSlippage)) /
100; // 5% slippage
ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
path: abi.encodePacked(
nativeToken(),
uint24(100),
gdFee,
reserveToken,
uint24(100),
gasFee,
gasToken
),
recipient: address(this),
Expand All @@ -308,7 +320,7 @@ contract GenericDistributionHelper is
try ROUTER.exactInput(params) returns (uint256 amountOut) {
return amountOut;
} catch Error(string memory reason) {
emit BuyNativeFailed(reason);
emit BuyNativeFailed(reason, amountToSell, amountOutMinimum);
return 0;
}
}
Expand Down
5 changes: 3 additions & 2 deletions contracts/ubi/UBISchemeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ contract UBISchemeV2 is DAOUpgradeableContract {
dailyCyclePool /
max((prevDayClaimers * reserveFactor) / 10000, minActiveUsers);
//update minActiveUsers as claimers grow
minActiveUsers = max(prevDayClaimers / 2, minActiveUsers);
minActiveUsers = (prevDayClaimers + minActiveUsers * 29) / 30; //smooth it a bit

emit UBICalculated(currentDay, dailyUbi, block.number);
}
Expand Down Expand Up @@ -347,7 +347,8 @@ contract UBISchemeV2 is DAOUpgradeableContract {
bool shouldStartEarlyCycle = currentDayInCycle() + 1 >=
currentCycleLength ||
nextDailyPool > (dailyCyclePool * 105) / 100 ||
currentBalance < (dailyCyclePool * (cycleLength - currentDayInCycle()));
currentBalance <
(dailyCyclePool * (cycleLength - currentDayInCycle() - 1));

uint256 _dailyCyclePool = dailyCyclePool;
uint256 _dailyUbi;
Expand Down
1 change: 1 addition & 0 deletions contracts/utils/ProxyFactory1967.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT

//pragma solidity =0.8.16; // xdc deployed version
pragma solidity >=0.8;

import "@openzeppelin/contracts/proxy/Proxy.sol";
Expand Down
9 changes: 6 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { sumStakersGdRewards } from "./scripts/staking/stakersGdRewardsCalculati
import { verify } from "./scripts/verify";
import { ethers } from "ethers";
import { fstat, readFileSync, writeFileSync } from "fs";
import * as envEnc from "@chainlink/env-enc";
envEnc.config();

config();

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

const xdc = {
accounts: { mnemonic },
url: "https://rpc.xdc.network",
url: "https://rpc.ankr.com/xdc/ef07ba6590dc46db9275bba237aed203ed6d5fb3e3203ff237a82a841f75b2ce",
gas: 3000000,
gasPrice: 12.5e9,
chainId: 50
Expand Down Expand Up @@ -286,8 +289,8 @@ const hhconfig: HardhatUserConfig = {
accounts: [deployerPrivateKey]
},
"development-xdc": {
...xdc,
accounts: [deployerPrivateKey]
...xdc
// url: "http://localhost:8545"
}
},
mocha: {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gooddollar/goodprotocol",
"version": "2.0.34-beta.2",
"version": "2.1.0",
"description": "GoodDollar Protocol",
"engines": {
"node": ">=16.x"
Expand Down Expand Up @@ -66,6 +66,7 @@
"@babel/preset-env": "*",
"@babel/register": "*",
"@celo-tools/celo-ethers-wrapper": "^0.4.0",
"@chainlink/env-enc": "^1.0.5",
"@gnosis.pm/safe-core-sdk": "^3.2.0",
"@gnosis.pm/safe-core-sdk-types": "^1.7.0",
"@gnosis.pm/safe-ethers-lib": "^1.7.0",
Expand All @@ -82,7 +83,7 @@
"@openzeppelin/contracts": "^4.8.0",
"@openzeppelin/contracts-upgradeable": "^4.8.0",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@safe-global/api-kit": "^3.0.1",
"@safe-global/api-kit": "^4.0.0",
"@safe-global/protocol-kit": "^6.0.2",
"@safe-global/types-kit": "^2.0.1",
"@superfluid-finance/ethereum-contracts": "1.8.1",
Expand Down
17 changes: 17 additions & 0 deletions releases/deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -667,5 +667,22 @@
"MentoExchangeProvider": "0x1fad5a713da1f51e2a1ac4ca2e1d621919f0aba0",
"MentoExpansionController": "0xe69bd25ca06264780e377e8d81a59271299adb36",
"MentoProxyAdmin": "0x54f44fBE2943c2196D94831288E716cdeAF5657"
},
"production-xdc": {
"ProxyFactory": "0x5BE34022c26FA03a8d6926314a42414c7ca2dF51",
"GuardiansSafe": "0xE0c5daa7CC6F88d29505f702a53bb5E67600e7Ec",
"CUSD": "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
"ReserveToken": "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
"Identity": "0x27a4a02C9ed591E1a86e2e5D05870292c34622C9",
"DAOCreator": "0xa2B9993D198904e4bdCE48379FDff65405607F42",
"FeeFormula": "0xf4e9Af892A09F04B7408266777198206E7f80D46",
"NameService": "0x1e5154Bf5e31FF56051bbd45958b879Fb7a290FE",
"Avatar": "0x21eaC3fE218307BeE0463F77EBcA3b50F452C0Ce",
"GoodDollar": "0xEC2136843a983885AebF2feB3931F73A8eBEe50c",
"Controller": "0x75a8bE0C2dEaDEd8Fc9ECEB5F01ad0B979b7AD03",
"AdminWallet": "0x66fc1bE551f752706130b6f54d84141F8c2Ae8Bb",
"Faucet": "0x7344Da1Be296f03fbb8082aDaC5696058B5a9bd9",
"Invites": "0x6bd698566632bf2e81e2278f1656CB24aAF06D2e",
"UBIScheme": "0x22867567E2D80f2049200E25C6F31CB6Ec2F0faf"
}
}
7 changes: 4 additions & 3 deletions scripts/multichain-deploy/0_proxyFactory-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const deployUniversalProxyFactory = async () => {
if (name.includes("staging")) {
deployTx.gasLimit = 892000;
} else if (name.includes("production")) {
deployTx.gasLimit = 890000;
// deployTx.gasLimit = 890000; // was used on celo
deployTx.gasLimit = 1500000; //xdc needs more gas
}

const rawTx = ethers.utils.serializeTransaction(deployTx);
Expand Down Expand Up @@ -121,8 +122,8 @@ const deployProxyMethod2 = async (defaultAdmin = null) => {
await verifyContract(deployed.address, artifact.sourceName + ":" + artifact.contractName);
};
export const main = async (networkName = name) => {
// await deployProxy();
await deployProxyMethod2();
await deployProxy();
// await deployProxyMethod2();
};

if (process.argv[1].includes("proxyFactory-deploy")) {
Expand Down
Loading
Loading