Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set rewards wrappers and rewards plans #345

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions contracts/Importer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import "@yield-protocol/yieldspace-tv/src/oracle/PoolOracle.sol";
import "@yield-protocol/utils-v2/src/utils/Timelock.sol";
import "@yield-protocol/utils-v2/src/utils/EmergencyBrake.sol";
import "@yield-protocol/utils-v2/src/utils/Assert.sol";
import "@yield-protocol/utils-v2/src/token/ERC20RewardsWrapper.sol";
import "@yield-protocol/strategy-v2/src/Strategy.sol";
import "@yield-protocol/yvarb/contracts/YieldStEthLever.sol";
import "@yield-protocol/yvarb/contracts/YieldNotionalLever.sol";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@typechain/hardhat": "^6.0.0",
"@types/mocha": "^8.0.0",
"@yield-protocol/strategy-v2": "2.0.3",
"@yield-protocol/utils-v2": "2.6.11",
"@yield-protocol/utils-v2": "2.6.15",
"@yield-protocol/vault-v2": "0.18.12",
"@yield-protocol/yieldspace-tv": "0.1.10",
"chai": "4.2.0",
Expand Down
35 changes: 0 additions & 35 deletions scripts/fragments/emergency/sendTokensProposal.ts

This file was deleted.

37 changes: 0 additions & 37 deletions scripts/fragments/strategies/addEthRewards.ts

This file was deleted.

30 changes: 30 additions & 0 deletions scripts/fragments/strategies/addRewardsPlan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @dev This script adds a rewards plan to a strategy
*/

import { Strategy } from '../../../typechain'
import { indent } from '../../../shared/helpers'
import { RewardsPlan } from '../../governance/confTypes'

export const addRewardsPlan = async (
strategy: Strategy,
rewardsPlan: RewardsPlan,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `ADD_REWARDS_PLAN`))
const proposal: Array<{ target: string; data: string }> = []

proposal.push({
target: strategy.address,
data: strategy.interface.encodeFunctionData('setRewards', [rewardsPlan.start, rewardsPlan.stop, rewardsPlan.rate]),
})
console.log(
indent(
nesting,
`strategy(${await strategy.symbol()}).setRewards(${rewardsPlan.start}, ${rewardsPlan.stop}, ${rewardsPlan.rate})`
)
)

return proposal
}
29 changes: 29 additions & 0 deletions scripts/fragments/strategies/mintRewardsToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @dev This script mints rewards tokens on strategies using the rewards wrapper.
*/

import { BigNumber } from 'ethers'
import { Strategy, ERC20RewardsWrapper__factory } from '../../../typechain'
import { indent } from '../../../shared/helpers'

export const mintRewardsToken = async (
strategy: Strategy,
amount: BigNumber,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `MINT_REWARDS_TOKEN`))
const proposal: Array<{ target: string; data: string }> = []

const wrapper = ERC20RewardsWrapper__factory.connect(await strategy.rewardsToken(), strategy.signer)

proposal.push({
target: wrapper.address,
data: wrapper.interface.encodeFunctionData('mint', [strategy.address, amount]),
})
console.log(
indent(nesting, `wrapper(${await wrapper.symbol()}).mint(${await strategy.symbol()}, ${amount.toString()})`)
)

return proposal
}
38 changes: 38 additions & 0 deletions scripts/fragments/strategies/orchestrateRewardsWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @dev This script orchestrates a rewards wrapper.
*/

import { Timelock, ERC20RewardsWrapper, AccessControl__factory } from '../../../typechain'
import { revokeRoot } from '../permissions/revokeRoot'
import { indent, id } from '../../../shared/helpers'

export const orchestrateRewardsWrapper = async (
deployer: string,
timelock: Timelock,
wrapper: ERC20RewardsWrapper,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `ORCHESTRATE_REWARDS_WRAPPER`))
let proposal: Array<{ target: string; data: string }> = []

proposal.push({
target: wrapper.address,
data: wrapper.interface.encodeFunctionData('grantRoles', [
[
id(wrapper.interface, 'set(address)'),
id(wrapper.interface, 'skim(address,uint256)'),
id(wrapper.interface, 'mint(address,uint256)'),
],
timelock.address,
]),
})
console.log(indent(nesting, `rewards(${await wrapper.symbol()}).grantRoles(gov, timelock)`))

// Revoke ROOT from the deployer
proposal = proposal.concat(
await revokeRoot(AccessControl__factory.connect(wrapper.address, wrapper.signer), deployer, nesting + 1)
)

return proposal
}
24 changes: 24 additions & 0 deletions scripts/fragments/strategies/setRewardsToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @dev This script sets the rewards token on strategies. It can only be called once per strategy.
*/

import { Strategy } from '../../../typechain'
import { indent } from '../../../shared/helpers'

export const setRewardsToken = async (
strategy: Strategy,
rewardsTokenAddress: string,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `SET_REWARDS_TOKEN`))
const proposal: Array<{ target: string; data: string }> = []

proposal.push({
target: strategy.address,
data: strategy.interface.encodeFunctionData('setRewardsToken', [rewardsTokenAddress]),
})
console.log(indent(nesting, `strategy(${await strategy.symbol()}).setRewardsAddress(${rewardsTokenAddress})`))

return proposal
}
24 changes: 24 additions & 0 deletions scripts/fragments/strategies/setRewardsUnderlying.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @dev This script sets the underlying token on rewards wrappers.
*/

import { ERC20RewardsWrapper } from '../../../typechain'
import { indent } from '../../../shared/helpers'

export const setRewardsUnderlying = async (
wrapper: ERC20RewardsWrapper,
underlyingAddress: string,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `SET_REWARDS_UNDERLYING`))
const proposal: Array<{ target: string; data: string }> = []

proposal.push({
target: wrapper.address,
data: wrapper.interface.encodeFunctionData('set', [underlyingAddress]),
})
console.log(indent(nesting, `wrapper(${await wrapper.symbol()}).set(${underlyingAddress})`))

return proposal
}
31 changes: 31 additions & 0 deletions scripts/fragments/utils/sendTokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @dev This script transfers specified tokens from the timelock to destination
*/

import { ERC20, ERC20__factory, Timelock } from '../../../typechain'
import { indent } from '../../../shared/helpers'
import { Transfer } from '../../governance/confTypes'

export const sendTokens = async (
timelock: Timelock,
transfer: Transfer,
nesting: number = 0
): Promise<Array<{ target: string; data: string }>> => {
console.log()
console.log(indent(nesting, `SEND_TOKENS`))
// Build the proposal
const proposal: Array<{ target: string; data: string }> = []

let token: ERC20 | undefined

token = ERC20__factory.connect(transfer.token.address, timelock.signer)

proposal.push({
target: token.address,
data: token.interface.encodeFunctionData('transfer', [transfer.receiver, transfer.amount]),
})

console.log(indent(nesting, `Transferring ${transfer.amount} of ${token.address} to ${token.receiver}`))

return proposal
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getOwnerOrImpersonate, propose } from '../../../../../shared/helpers'
import { addEthRewardsProposal } from '../../../../fragments/strategies/addEthRewards'
import { addEthRewardsProposal } from '../../../../fragments/strategies/addRewardsPlan'
import { Timelock__factory } from '../../../../../typechain'
import { TIMELOCK } from '../../../../../shared/constants'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { USDT } from '../../../../shared/constants'
import { ACCUMULATOR } from '../../../../shared/constants'
import { ONEUSDC } from '../../../../shared/constants'
import { FYUSDT2309, YSUSDT6MMS } from '../../../../shared/constants'

import * as base_config from '../../base.mainnet.config'

export const chainId: number = base_config.chainId
export const developer: string = '0xC7aE076086623ecEA2450e364C838916a043F9a8'
export const deployers: Map<string, string> = base_config.deployers
export const whales: Map<string, string> = base_config.whales

export const governance: Map<string, string> = base_config.governance
export const protocol: Map<string, string> = base_config.protocol
export const assets: Map<string, string> = base_config.assets
export const joins: Map<string, string> = base_config.joins
export const fyTokens: Map<string, string> = base_config.fyTokens
export const pools: Map<string, string> = base_config.pools
export const strategyAddresses: Map<string, string> = base_config.strategyAddresses

export const series: Map<string, Series> = base_config.series
export const strategies: Map<string, Strategy> = base_config.strategies

import { Series, Strategy } from '../../confTypes'

export const ONEUSDT = ONEUSDC

const usdt = base_config.bases.get(USDT)!
const usdtIlks = base_config.ilks.get(USDT)!

const fyUSDT2309: Series = {
seriesId: FYUSDT2309,
base: usdt,
fyToken: {
assetId: FYUSDT2309,
address: fyTokens.getOrThrow(FYUSDT2309)!,
},
chiOracle: protocol.getOrThrow(ACCUMULATOR)!,
pool: {
assetId: FYUSDT2309,
address: pools.getOrThrow(FYUSDT2309)!,
},
ilks: usdtIlks,
}

export const newSeries: Series[] = [fyUSDT2309]

const ysUSDT6MMS: Strategy = {
assetId: YSUSDT6MMS,
address: strategyAddresses.getOrThrow(YSUSDT6MMS)!,
base: usdt,
seriesToInvest: fyUSDT2309,
}

export const rollStrategies: Strategy[] = [ysUSDT6MMS]
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { BigNumber } from 'ethers'
import { ONE64, secondsInOneYear } from '../../../../../shared/constants'
import { YSETH6MJD, RWETH6MJD } from '../../../../../shared/constants'
import { SAFE_ERC20_NAMER, YIELDMATH, ACCUMULATOR } from '../../../../../shared/constants'

import { ContractDeployment } from '../../../confTypes' // Note we use the series id as the asset id

import { readAddressMappingIfExists } from '../../../../../shared/helpers'

import * as base_config from '../../../base.mainnet.config'

export const chainId: number = base_config.chainId
export const developer: string = '0xC7aE076086623ecEA2450e364C838916a043F9a8'
export const whales: Map<string, string> = base_config.whales

export const governance: Map<string, string> = base_config.governance
export const external: Map<string, string> = base_config.external
export const assets: Map<string, string> = base_config.assets
export const protocol = () => readAddressMappingIfExists('protocol.json')
export const joins = () => readAddressMappingIfExists('joins.json')
export const fyTokens = () => readAddressMappingIfExists('fyTokens.json')
export const pools = () => readAddressMappingIfExists('pools.json')
export const strategies = () => readAddressMappingIfExists('strsategies.json')

// ----- deployment parameters -----
export const contractDeployments: ContractDeployment[] = [
/// @notice Deploy rewards wrapper
/// @param name
/// @param symbol
/// @param decimals
{
addressFile: 'strategies.json',
name: RWETH6MJD,
contract: 'ERC20RewardsWrapper',
args: [() => 'RWETH6MJD', () => 'RWETH6MJD', () => 18],
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -eux
export HERE=$(dirname $0)
RUN="npx hardhat run --network localhost"

# Phase 1: Deploy Contracts
export CONF=$PWD/$HERE/rollSep23Series.mainnet.deployments
$RUN $HERE/../../../../shared/deploy.ts

# Phase 2: Proposal
export CONF=$PWD/$HERE/rollSep23Series.mainnet.config
# $RUN $HERE/../../../../tools/poolRollBalances.ts
# $RUN $HERE/../../../../tools/joinLoan.ts

$RUN $HERE/../../../../tools/advanceTimeToMaturity.ts
$RUN $HERE/../rollSeries.ts
$RUN $HERE/../../../../shared/approve.ts
$RUN $HERE/../../../../shared/execute.ts
Loading