Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
dumedco committed Nov 15, 2023
2 parents 3d8b63c + 0befd89 commit 2e771e2
Show file tree
Hide file tree
Showing 10 changed files with 6,865 additions and 5,744 deletions.
56 changes: 46 additions & 10 deletions contracts/donationMiner/DonationMinerImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ contract DonationMinerImplementation is
_;
}

/**
* @notice Enforces sender to be Staking contract
*/
modifier onlyRecurringCron() {
require(msg.sender == recurringCronAddress, "DonationMiner: You are not allow to call this method");
_;
}

/**
* @notice Used to initialize a new DonationMiner contract
*
Expand Down Expand Up @@ -232,7 +240,7 @@ contract DonationMinerImplementation is
* @notice Returns the current implementation version
*/
function getVersion() external pure override returns (uint256) {
return 4;
return 5;
}

/**
Expand Down Expand Up @@ -410,33 +418,61 @@ contract DonationMinerImplementation is
}

/**
* @notice Transfers cUSD tokens to the treasury contract
* @notice Updates recurring cron address address
*
* @param _newRecurringCronAddress new address of recurring cron
*/
function updateRecurringCronAddress(address _newRecurringCronAddress) external override onlyOwner {
recurringCronAddress = _newRecurringCronAddress;
}

/**
* @notice Transfers tokens to the treasury contract
*
* @param _token address of the token
* @param _amount Amount of cUSD tokens to deposit.
* @param _amount Amount of tokens to deposit.
* @param _delegateAddress the address that will claim the reward for the donation
*/
function donate(
IERC20 _token,
uint256 _amount,
address _delegateAddress
) external override whenNotPaused whenStarted nonReentrant {
require(
_token == cUSD || treasury.isToken(address(_token)),
"DonationMiner::donate: Invalid token"
);
require(treasury.isToken(address(_token)), "DonationMiner::donate: Invalid token");

_token.safeTransferFrom(msg.sender, address(treasury), _amount);

_addDonation(_delegateAddress, _token, _amount, address(treasury));
}

/**
* @notice Transfers tokens from the _from to the treasury contract
*
* @param _from address of the user
* @param _token address of the token
* @param _amount Amount of tokens to deposit.
* @param _delegateAddress the address that will claim the reward for the donation
*/
function donateFrom(
address _from,
IERC20 _token,
uint256 _amount,
address _delegateAddress
) external override onlyRecurringCron whenNotPaused whenStarted nonReentrant {
require(
treasury.isToken(address(_token)), "DonationMiner: Invalid token");

_token.safeTransferFrom(_from, address(treasury), _amount);

_addDonation(_delegateAddress, _token, _amount, address(treasury));
}

/**
* @dev Transfers tokens to the community contract
*
* @param _community address of the community
* @param _token address of the token
* @param _amount amount of cUSD tokens to deposit
* @param _amount amount of tokens to deposit
* @param _delegateAddress the address that will claim the reward for the donation
*/
function donateToCommunity(
Expand All @@ -462,9 +498,9 @@ contract DonationMinerImplementation is
}

/**
* @notice Transfers cUSD tokens to the treasury contract
* @notice Virtual donate tokens to the treasury contract
*
* @param _amount Amount of cUSD tokens to deposit.
* @param _amount Amount of tokens to fake deposit.
* @param _delegateAddress the address that will claim the reward for the donation
*/
function donateVirtual(uint256 _amount, address _delegateAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ import "./DonationMinerStorageV4.sol";
abstract contract DonationMinerStorageV5 is DonationMinerStorageV4 {
IAirdropV3 public override airdropV3;
IMicrocredit public override microcredit;
address public override recurringCronAddress;
}
3 changes: 3 additions & 0 deletions contracts/donationMiner/interfaces/IDonationMiner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface IDonationMiner {
function staking() external view returns (IStaking);
function airdropV3() external view returns (IAirdropV3);
function microcredit() external view returns (IMicrocredit);
function recurringCronAddress() external view returns (address);
function rewardPeriodSize() external view returns (uint256);
function decayNumerator() external view returns (uint256);
function decayDenominator() external view returns (uint256);
Expand Down Expand Up @@ -112,9 +113,11 @@ interface IDonationMiner {
function updateStaking(IStaking _newStaking) external;
function updateAirdropV3(IAirdropV3 _newAirdropV3) external;
function updateMicrocredit(IMicrocredit newMicrocredit) external;
function updateRecurringCronAddress(address newRecurringCronAddress) external;
function donate(IERC20 _token, uint256 _amount, address _delegateAddress) external;
function donateToCommunity(ICommunity _community, IERC20 _token, uint256 _amount, address _delegateAddress) external;
function donateVirtual(uint256 _amount, address _delegateAddress) external;
function donateFrom(address from, IERC20 token, uint256 amount, address delegateAddress) external;
function claimRewards() external;
function claimRewardsPartial(uint256 _lastPeriodNumber) external;
function stakeRewards() external;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
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, toEther} from "../../../test/utils/helpers";
import * as ethersTypes from "ethers";
import {getExchangePathProd} from "../../../test/utils/uniswap";

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

// // mainnet
// const governanceDelegatorAddress = "0x8f8BB984e652Cb8D0aa7C9D6712Ec2020EB1BAb4";
// const donationMinerProxyAddress = "0x1C51657af2ceBA3D5492bA0c5A17E562F7ba6593";
// const proxyAdminAddress = "0xFC641CE792c242EACcD545B7bee2028f187f61EC";
// const recurringCronAddress = "";


// alfajores
const governanceDelegatorAddress = "0x5c27e2600a3eDEF53DE0Ec32F01efCF145419eDF";
const donationMinerProxyAddress = "0x09Cdc8f50994F63103bc165B139631A6ad18EF49";
const proxyAdminAddress = "0x79f9ca5f1A01e1768b9C24AD37FF63A0199E3Fe5";
const recurringCronAddress = "0x8903B83B6e1B1379f41a9cc82080Be10E1c8E6d3";


let GovernanceProxy: ethersTypes.Contract;

let newDonationMinerImplementationAddress: string;


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

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

GovernanceProxy = await ethers.getContractAt(
"PACTDelegate",
governanceDelegatorAddress
);

await deployNewDonationMinerImplementation();
await createCallProposal();
};

async function deployNewDonationMinerImplementation() {
console.log("Deploying new DonationMinerImplementation");
newDonationMinerImplementationAddress = (
await deploy('DonationMinerImplementation', {
from: deployer.address,
args: [],
log: true,
})
).address;
}

async function createCallProposal() {
console.log("Creating new proposal");

await createProposal(
GovernanceProxy,
deployer,
[
proxyAdminAddress,
donationMinerProxyAddress
],
[0, 0],
[
"upgrade(address,address)",
"updateRecurringCronAddress(address)"
],
[
["address", "address"],
["address"]
],
[
[donationMinerProxyAddress, newDonationMinerImplementationAddress],
[recurringCronAddress],
],
'Upgrade DonationMiner and set recurringCronAddress'
);
}

export default func;
func.tags = ["DonationMiner.upgrade+DonationMiner.updateRecurringCronAddress"];
286 changes: 204 additions & 82 deletions deployments/alfajores/DonationMinerImplementation.json

Large diffs are not rendered by default.

Loading

0 comments on commit 2e771e2

Please sign in to comment.