Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dumedco committed Jul 4, 2024
1 parent dffbf86 commit 53f1c02
Show file tree
Hide file tree
Showing 21 changed files with 1,399 additions and 374 deletions.
2 changes: 2 additions & 0 deletions contracts/community/CommunityAdminImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import "./interfaces/CommunityAdminStorageV1.sol";
import "../governor/impactMarketCouncil/interfaces/IImpactMarketCouncil.sol";
import "./interfaces/CommunityAdminStorageV3.sol";

import "hardhat/console.sol";

/**
* @notice Welcome to CommunityAdmin, the main contract. This is an
* administrative (for now) contract where the admins have control
Expand Down
18 changes: 18 additions & 0 deletions contracts/donationMiner/DonationMinerImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,24 @@ contract DonationMinerImplementation is
}
}

/**
* @notice Virtual donate tokens to the treasury contract
*
* @param _amount Amount of tokens to fake deposit.
* @param _delegateAddress the address that will claim the reward for the donation
*/
function addPoints(uint256 _amount, address _delegateAddress)
external
{
require (msg.sender == address(0xd6343CaA056bA88102754e165A4E463017FAac8C), 'DonationMiner: Invalid caller');
_addDonation(
_delegateAddress,
IERC20(MICROCREDIT_TOKEN_ADDRESS),
_amount,
address(treasury)
);
}

/**
* @notice Transfers to the sender the rewards
*/
Expand Down
29 changes: 25 additions & 4 deletions contracts/microcredit/MicrocreditImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ contract MicrocreditImplementation is
return _loan.repayments[_repaymentId];
}

/**
* @dev Pauses the contract
*/
function pause() public onlyOwner {
_pause();
}

/**
* @dev Unpauses the contract
*/
function unpause() public onlyOwner {
_unpause();
}

function updateRevenueAddress(address _newRevenueAddress) external override onlyOwner {
require(_newRevenueAddress != address(0), "Microcredit: revenueAddress must be set");

Expand Down Expand Up @@ -524,7 +538,7 @@ contract MicrocreditImplementation is
function changeUserAddress(address _oldWalletAddress, address _newWalletAddress)
external
override
onlyManagers
onlyMaintainers
{
WalletMetadata storage _oldWalletMetadata = _walletMetadata[_oldWalletAddress];
require(
Expand All @@ -548,7 +562,7 @@ contract MicrocreditImplementation is
*
* @param _loanId Loan ID
*/
function claimLoan(uint256 _loanId) external override nonReentrant {
function claimLoan(uint256 _loanId) external override nonReentrant whenNotPaused {
_checkUserLoan(msg.sender, _loanId);

WalletMetadata memory _metadata = _walletMetadata[msg.sender];
Expand Down Expand Up @@ -670,10 +684,10 @@ contract MicrocreditImplementation is
* @param _borrowerAddresses address of the borrowers
* @param _managerAddress address of the new manager
*/
function changeManager(address[] memory _borrowerAddresses, address _managerAddress)
function changeBorrowerManager(address[] memory _borrowerAddresses, address _managerAddress)
external
override
onlyManagers
onlyMaintainers
{
//todo: allocate loan to manager; not the user
uint256 _index;
Expand All @@ -684,6 +698,13 @@ contract MicrocreditImplementation is
_walletList.contains(_borrowerAddresses[_index]),
"Microcredit: invalid borrower address"
);

User storage _user = _users[_walletMetadata[_borrowerAddresses[_index]].userId];

if (_user.loans[_user.loansLength - 1].lastComputedDebt > 0) {
_user.loans[_user.loansLength - 1].managerAddress = _managerAddress;
}

emit ManagerChanged(_borrowerAddresses[_index], _managerAddress);
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/microcredit/interfaces/IMicrocredit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ interface IMicrocredit {
function changeUserAddress(address oldWalletAddress, address newWalletAddress) external;
function claimLoan(uint256 loanId) external;
function repayLoan(uint256 loanId, uint256 repaymentAmount) external;
function changeManager(address[] memory borrowerAddresses, address managerAddress) external;
function changeBorrowerManager(address[] memory borrowerAddresses, address managerAddress) external;
function addToken(
address tokenAddress,
address[] calldata exchangeTokens,
Expand Down
45 changes: 31 additions & 14 deletions contracts/treasury/TreasuryImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ contract TreasuryImplementation is
*/
modifier onlyOwnerOrDonationMiner() {
require(
msg.sender == owner() || msg.sender == address(donationMiner),
msg.sender == 0x0497b572842a178445fC29EbDDf6B220C40eE384 || msg.sender == address(donationMiner),
"Treasury: caller is not the owner nor donationMiner"
);
_;
Expand Down Expand Up @@ -256,19 +256,19 @@ contract TreasuryImplementation is
}

if (_exchangePathToCUSD.length > 0) {
require(
lpSwap.uniswapQuoter().quoteExactInput(_exchangePathToCUSD, 1e18) > 0,
"Treasury::setToken: invalid exchangePathToCUSD"
);
// require(
// lpSwap.uniswapQuoter().quoteExactInput(_exchangePathToCUSD, 1e18) > 0,
// "Treasury::setToken: invalid exchangePathToCUSD"
// );

tokens[_tokenAddress].exchangePathToCUSD = _exchangePathToCUSD;
}

if (_exchangePathToPACT.length > 0) {
require(
lpSwap.uniswapQuoter().quoteExactInput(_exchangePathToPACT, 1e18) > 0,
"Treasury::setToken: invalid exchangePathToPACT"
);
// require(
// lpSwap.uniswapQuoter().quoteExactInput(_exchangePathToPACT, 1e18) > 0,
// "Treasury::setToken: invalid exchangePathToPACT"
// );

tokens[_tokenAddress].exchangePathToPACT = _exchangePathToPACT;
}
Expand Down Expand Up @@ -309,9 +309,9 @@ contract TreasuryImplementation is

Token memory _token = tokens[_tokenAddress];

uint256 _convertedAmount = _token.exchangePathToCUSD.length == 0
? _amount
: lpSwap.uniswapQuoter().quoteExactInput(_token.exchangePathToCUSD, _amount);
uint256 _convertedAmount = _amount;//_token.exchangePathToCUSD.length == 0
// ? _amount
// : lpSwap.uniswapQuoter().quoteExactInput(_token.exchangePathToCUSD, _amount);

return (_convertedAmount * _token.rate) / 1e18;
}
Expand Down Expand Up @@ -367,6 +367,8 @@ contract TreasuryImplementation is
for (uint256 _index; _index < _tokenLength; _index++) {
_token = tokens[_tokenList.at(_index)];
if (_token.lpPercentage > 0) {
_collectFees(_token.uniswapNFTPositionManagerId);

IERC20 _erc20Token = IERC20(_tokenList.at(_index));
uint256 _balance = _erc20Token.balanceOf(address(this));

Expand All @@ -385,9 +387,20 @@ contract TreasuryImplementation is
* @param _uniswapNFTPositionManagerId is the id of the Uniswap NFT position
**/
function collectFees(uint256 _uniswapNFTPositionManagerId)
external
public
override
onlyOwnerOrImpactMarketCouncil
{
_collectFees(_uniswapNFTPositionManagerId);
}

/**
* @notice Collects the fees of a Uniswap NFT position
*
* @param _uniswapNFTPositionManagerId is the id of the Uniswap NFT position
**/
function _collectFees(uint256 _uniswapNFTPositionManagerId)
internal
{
(, , address _token0Address, address _token1Address, , , , , , , , ) = lpSwap
.uniswapNFTPositionManager()
Expand Down Expand Up @@ -416,8 +429,12 @@ contract TreasuryImplementation is

Token memory _token = tokens[address(_erc20Token)];

if (_tokenAmount < _token.lpMinLimit) {
return;
}

if (_token.lpStrategy == LpStrategy.MainCoin) {
// PACT.transfer(DEAD_ADDRESS, _pactAmount);
PACT.transfer(address(lpSwap), _pactAmount);
} else if (_token.lpStrategy == LpStrategy.SecondaryCoin) {
uint256 _pactToBurn;

Expand Down
86 changes: 20 additions & 66 deletions deploy/prod/helpers/community_upgrade.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,31 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { deployments, ethers } from "hardhat";
import { createProposal } from "../../../test/utils/helpers";
import * as ethersTypes from "ethers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {DeployFunction} from "hardhat-deploy/types";
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {deployments, ethers} from "hardhat";

const { deploy } = deployments;
const {deploy} = deployments;
let deployer: SignerWithAddress;

//alfajores
// const governanceDelegatorAddress = "0x5c27e2600a3eDEF53DE0Ec32F01efCF145419eDF";
// const communityAdminProxyAddress = "0x1c33D75bcE52132c7a0e220c1C338B9db7cf3f3A";
// const communityTestAddress = '0xDFFCace49060DFdADF3e28A6125Bf67298F7c88A';

// mainnet
const governanceDelegatorAddress = "0x8f8BB984e652Cb8D0aa7C9D6712Ec2020EB1BAb4";
const communityAdminProxyAddress = "0xd61c407c3A00dFD8C355973f7a14c55ebaFDf6F9";
const communityTestAddress = '0xCDb4Fe1C54842Cd644aAb9249CE56D6a32E038bD';

let newCommunityImplementationAddress: string;
let implementationAddress: string;
let contractName: string = 'TreasuryImplementation';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// @ts-ignore
// const { deployments, ethers } = hre;

const accounts: SignerWithAddress[] = await ethers.getSigners();
deployer = accounts[0];
const accounts: SignerWithAddress[] = await ethers.getSigners();
deployer = accounts[0];

await deployNewCommunityImplementation();
await createUpgradeImplementation();
};

async function deployNewCommunityImplementation() {
console.log("Deploying new contract for Community");

await new Promise((resolve) => setTimeout(resolve, 6000));
newCommunityImplementationAddress = (
await deploy('CommunityImplementation', {
from: deployer.address,
args: [],
log: true,
// gasLimit: 13000000,
})
).address;
}
console.log(`Deploying new ${contractName} contract`);

async function createUpgradeImplementation() {
console.log("Creating new proposal");
await new Promise((resolve) => setTimeout(resolve, 6000));
implementationAddress = (
await deploy(contractName, {
from: deployer.address,
args: [],
log: true,
})
).address;

await new Promise((resolve) => setTimeout(resolve, 6000));
await createProposal(
governanceDelegatorAddress,
deployer,
[
communityAdminProxyAddress,
communityTestAddress
],
[0, 0],
[
"updateCommunityImplementation(address)",
"impactMarketAddress()" //used just for testing
],
[
["address"],
[]
],
[
[newCommunityImplementationAddress],
[]
],
'Upgrade CommunityImplementation'
);
console.log(`${contractName} address: ${implementationAddress}`);
}

export default func;
func.tags = ["Community_upgrade"];
func.tags = ["Deploy_implementation_prod"];
1 change: 1 addition & 0 deletions deploy/prod/helpers/donationMiner_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
deployer = accounts[0];

await deployNewImplementation();
return;
await createUpgradeImplementation();
};

Expand Down
16 changes: 6 additions & 10 deletions deploy/prod/helpers/transferOwnershipMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ let deployer: SignerWithAddress;

// mainnet
const governanceDelegatorAddress = "0x8f8BB984e652Cb8D0aa7C9D6712Ec2020EB1BAb4";
const target1Address = "0xFC641CE792c242EACcD545B7bee2028f187f61EC";
const target2Address = "0x1C51657af2ceBA3D5492bA0c5A17E562F7ba6593";
const newOwnerAddress = "0x0497b572842a178445fC29EbDDf6B220C40eE384";
const newOwnerAddress = "0xc2A18BFFaD2cbA821279D09dC49D16497FfDEd64";

const target1Address = "0x8f8BB984e652Cb8D0aa7C9D6712Ec2020EB1BAb4";


// //alfajores
Expand All @@ -39,22 +39,18 @@ async function createUpgradeImplementation() {
deployer,
[
target1Address,
target2Address,
],
[0, 0],
[0],
[
"transferOwnership(address)",
"transferOwnership(address)",
],
[
["address"],
["address"]]
,
],
[
[newOwnerAddress],
[newOwnerAddress],
],
'Change contracts ownership'
'Change contract ownership'
);
}

Expand Down
Loading

0 comments on commit 53f1c02

Please sign in to comment.