Skip to content

Commit

Permalink
trying to calc percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
Aodhgan committed Mar 31, 2021
1 parent 3a6c06a commit 142edde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
6 changes: 6 additions & 0 deletions contracts/ConfigurableReserve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "./IConfigurableReserve.sol";
import "./IPrizePool.sol";

import "hardhat/console.sol";

///@title implementation of IConfigurable reserve
contract ConfigurableReserve is IConfigurableReserve, Ownable {

Expand All @@ -28,9 +30,13 @@ contract ConfigurableReserve is IConfigurableReserve, Ownable {
/// @return The reserve rate as a fixed point 18 number, like Ether. A rate of 0.05 = 50000000000000000
function reserveRateMantissa(address source) external override view returns (uint256){
if(prizePoolMantissas[source].useCustom == false){
console.log("returning default rate for ", source);
console.log("default rate is ", defaultReserveRateMantissa);
return uint256(defaultReserveRateMantissa);
}
// else return the custom rate
console.log("returning custom reserve rate for ", source);
console.log("reserve rate ",prizePoolMantissas[source].rateMantissa);
return prizePoolMantissas[source].rateMantissa;
}

Expand Down
29 changes: 18 additions & 11 deletions scripts/setupReserve.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
fork test script that sets up the reserve on mainnet for the governance pools.
Configure a reserve for some of the gov pools, then reward all of them.
Ensure default is respected and custom reserve works.
**/

// To use: in another terminal window run `yarn start-fork`. Open a second window and run `yarn fork-run ./scripts/setupReserve.js`

// 1. after fork, deploy ConfigurableReserve, from any signer.
// 2. set default rate
// 3. add the governace pools (dai, usdc, uni etc.)
// 4. transfer ownership of the configurable reserve?

// 5. set custom rate for one or two of the pools
// 6. fast forward and capture reserve
// 4. transfer ownership of the configurable reserve to the timelock
// 5. set custom rate for one or two of the pools (done in step 3)
// 6. fast forward and capture reserve by calling startAward() and completeAward()
// 7. call withdrawReserve on both default and custom rate prize pools
// 8. calculate if correct reserve rate has been extracted


const chalk = require('chalk');
Expand Down Expand Up @@ -44,13 +45,9 @@ async function runForkScript(){
})
green(`Deployed Configurable Reserve at: ${configurableReserveResult.address}`)



const configurableReserve = await ethers.getContract("ConfigurableReserve", deployer)

console.log("configurable reserve contract owner is ", await configurableReserve.owner())

// set global default reserve rate
// set global default reserve rate
await configurableReserve.setDefaultReserveRateMantissa(ethers.utils.parseEther("0.05"))

// add prize pools to cofigurable reserve
Expand Down Expand Up @@ -96,7 +93,11 @@ async function runForkScript(){
dim(`Increasing time by ${remainingTime} seconds...`)
await increaseTime(remainingTime.toNumber())

// if we cannot complete, let's startt it
let daiReserveFee
let usdcReserveFee


// if we cannot complete, let's start it
if (await prizeStrategy.canStartAward()) {
dim(`Starting award...`)
await prizeStrategy.startAward()
Expand All @@ -108,6 +109,12 @@ async function runForkScript(){
dim(`Completing award (will probably fail the first time on a fresh fork)....`)
const completeAwardTx = await prizeStrategy.completeAward()
const completeAwardReceipt = await ethers.provider.getTransactionReceipt(completeAwardTx.hash)
const completeAwardEvents = completeAwardReceipt.logs.reduce((array, log) =>
{ try { array.push(prizePool.interface.parseLog(log)) } catch (e) {} return array }, [])
const daiReserveFeeEvent = completeAwardEvents.filter(event => event.name === 'ReserveFeeCaptured')

daiReserveFee = (daiReserveFeeEvent[0].args.amount).toString()
console.log("the dai reserve fee was ", daiReserveFee)
}

//update reserve registry to point at ConfigurableReserve
Expand Down

0 comments on commit 142edde

Please sign in to comment.