Skip to content

Commit

Permalink
chore: Hardhat task for weekly emissions
Browse files Browse the repository at this point in the history
  • Loading branch information
naddison36 committed Dec 8, 2021
1 parent a479daf commit 4988fa4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
1 change: 1 addition & 0 deletions tasks-fork-polygon.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./tasks/deployEmissionsController"
import "./tasks/deployIntegration"
import "./tasks/deployFeeders"
import "./tasks/deployPolygon"
import "./tasks/emissions"
import "./tasks/feeder"
import "./tasks/mUSD"
import "./tasks/token"
Expand Down
1 change: 1 addition & 0 deletions tasks-fork.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./tasks/deployPolygon"
import "./tasks/deployRevenueForwarder"
import "./tasks/deployBriber"
import "./tasks/deploySavingsManager"
import "./tasks/emissions"
import "./tasks/feeder"
import "./tasks/mBTC"
import "./tasks/mUSD"
Expand Down
1 change: 1 addition & 0 deletions tasks.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "./tasks/deployPolygon"
import "./tasks/deployRevenueForwarder"
import "./tasks/deployBriber"
import "./tasks/deploySavingsManager"
import "./tasks/emissions"
import "./tasks/feeder"
import "./tasks/mBTC"
import "./tasks/mUSD"
Expand Down
2 changes: 1 addition & 1 deletion tasks/deployEmissionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ task("deploy-emissions-polly", "Deploys L2EmissionsController and L2 Bridge Reci
const signer = await getSigner(hre, taskArgs.speed)

const l2EmissionsController = await deployL2EmissionsController(signer, hre)
console.log(`Set L2EmissionsController contract name in networkAddressFactory to ${l2EmissionsController.address}`)
console.log(`Set EmissionsController contract name in networkAddressFactory to ${l2EmissionsController.address}`)

const bridgeRecipient = await deployL2BridgeRecipients(signer, hre, l2EmissionsController.address)
console.log(`Set PmUSD bridgeRecipient to ${bridgeRecipient.address}`)
Expand Down
74 changes: 74 additions & 0 deletions tasks/emissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* eslint-disable no-restricted-syntax */
import { subtask, task, types } from "hardhat/config"
import { DisperseForwarder__factory, EmissionsController__factory, IERC20__factory } from "types/generated"
import { logTxDetails } from "./utils"
import { getSigner } from "./utils/signerFactory"
import { getChain, resolveAddress } from "./utils/networkAddressFactory"

subtask("emission-calc", "Calculate the weekly emissions")
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const signer = await getSigner(hre, taskArgs.speed)
const chain = getChain(hre)

// Resolve the vault addresses from the asset symbols
const emissionsControllerAddress = resolveAddress("EmissionsController", chain)
const emissionsController = EmissionsController__factory.connect(emissionsControllerAddress, signer)

const tx = await emissionsController.calculateRewards()
await logTxDetails(tx, "Calculate Rewards")
})
task("emission-calc").setAction(async (_, __, runSuper) => {
await runSuper()
})

subtask("emission-dist", "Distribute the weekly emissions")
.addOptionalParam("dials", "The number of dials starting at 0", 15, types.int)
.addOptionalParam("dialIds", "A comma separated list of dial ids", undefined, types.string)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const signer = await getSigner(hre, taskArgs.speed)
const chain = getChain(hre)

const emissionsControllerAddress = resolveAddress("EmissionsController", chain)
const emissionsController = EmissionsController__factory.connect(emissionsControllerAddress, signer)

const dialIds = taskArgs.dialIds ? taskArgs.dialIds.split(",").map(Number) : [...Array(taskArgs.dials).keys()]

const tx = await emissionsController.distributeRewards(dialIds)
await logTxDetails(tx, "Distribute Rewards")
})
task("emission-dist").setAction(async (_, __, runSuper) => {
await runSuper()
})

subtask("emission-disperse-bal", "Disperse Polygon Balancer Pool MTA rewards in a DisperseForwarder contract")
.addParam("report", "Report number from the bal-mining-script repo. eg 79", undefined, types.int)
.addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", types.string)
.setAction(async (taskArgs, hre) => {
const signer = await getSigner(hre, taskArgs.speed)
const chain = getChain(hre)

const disperseForwarderAddress = resolveAddress("DisperseForwarder", chain)
const disperseForwarder = DisperseForwarder__factory.connect(disperseForwarderAddress, signer)

const mtaAddress = resolveAddress("MTA", chain)
const mtaToken = IERC20__factory.connect(mtaAddress, signer)

// Get the amount of MTA in the DisperseForwarder contract
const mtaBalance = await mtaToken.balanceOf(disperseForwarderAddress)

// TODO need get the MTA report from the bal-mining-script repo under the reports folder.
// The Polygon MTA rewards for will be in the __polygon_0xF501dd45a1198C2E1b5aEF5314A68B9006D842E0.json file under the report folder with a week number.
// eg https://github.com/balancer-labs/bal-mining-scripts/blob/master/reports/79/__polygon_0xF501dd45a1198C2E1b5aEF5314A68B9006D842E0.json
// The amounts in this file assumes 15k MTA is being distributed but this will not be the case with the emissions controller.
// Need to proportion the MTA balance in the DisperseForwarder contract to the recipients based off the bal-mining-script report.

const recipients = []
const values = []
const tx = await disperseForwarder.disperseToken(recipients, values)
await logTxDetails(tx, `Disperse Balancer Pool MTA rewards to ${recipients.length} recipients`)
})
task("emission-disperse-bal").setAction(async (_, __, runSuper) => {
await runSuper()
})
6 changes: 4 additions & 2 deletions tasks/utils/networkAddressFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const contractNames = [
// Will become the EmissionsController
"RewardsDistributor",
"EmissionsController",
"L2EmissionsController",
"PolygonPoSBridge",
"PolygonRootChainManager",
"BoostDirector",
Expand Down Expand Up @@ -49,6 +48,7 @@ export const contractNames = [
"CompController",
"CurveRegistryExchange",
"Disperse",
"DisperseForwarder",
"QuickSwapRouter",
"UniswapRouterV3",
"UniswapQuoterV3",
Expand Down Expand Up @@ -213,14 +213,16 @@ export const getChainAddress = (contractName: ContractNames, chain: Chain): stri
return "0xc929E040b6C8F2fEFE6B45c6bFEB55508554F3E2"
case "FeederInterestValidator":
return "0x4A268958BC2f0173CDd8E0981C4c0a259b5cA291"
case "L2EmissionsController":
case "EmissionsController":
return "0x82182Ac492fef111FB458FCe8f4228553Ed59a19"
case "AaveIncentivesController":
return "0x357D51124f59836DeD84c8a1730D72B749d8BC23"
case "AaveLendingPoolAddressProvider":
return "0xd05e3E715d945B59290df0ae8eF85c1BdB684744"
case "Disperse":
return "0xD152f549545093347A162Dce210e7293f1452150"
case "DisperseForwarder":
return "0x5783458E67B380d19a84514F11054ABDc326EB07"
case "QuickSwapRouter":
return "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff"
case "MStableYieldSource":
Expand Down

0 comments on commit 4988fa4

Please sign in to comment.