-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from cbergz/master
DIP 24
- Loading branch information
Showing
12 changed files
with
270 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/migrations/update-merkle-distributor-rewards-parameters-dip24.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
|
||
import { | ||
DydxGovernor__factory, | ||
} from '../../types'; | ||
import { getDeployConfig } from '../deploy-config'; | ||
import { getDeployerSigner } from '../deploy-config/get-deployer-address'; | ||
import { getHre } from '../hre'; | ||
import { log } from '../lib/logging'; | ||
import { waitForTx } from '../lib/util'; | ||
import { Proposal } from '../types'; | ||
|
||
export async function updateMerkleDistributorRewardsParametersDIP24Proposal({ | ||
proposalIpfsHashHex, | ||
governorAddress, | ||
merkleDistributorAddress, | ||
shortTimelockAddress, | ||
signer, | ||
}: { | ||
proposalIpfsHashHex: string, | ||
governorAddress: string, | ||
merkleDistributorAddress: string, | ||
shortTimelockAddress: string, | ||
signer?: SignerWithAddress, | ||
}) { | ||
const hre = getHre(); | ||
const deployConfig = getDeployConfig(); | ||
const deployer = signer || await getDeployerSigner(); | ||
const deployerAddress = deployer.address; | ||
log(`Creating Update Merkle Distributor Rewards Parameters DIP 24 proposal with proposer ${deployerAddress}.\n`); | ||
|
||
const governor = await new DydxGovernor__factory(deployer).attach(governorAddress); | ||
const proposalId = await governor.getProposalsCount(); | ||
const proposal: Proposal = [ | ||
shortTimelockAddress, | ||
[merkleDistributorAddress], | ||
['0'], | ||
['setRewardsParameters(uint256,uint256,uint256)'], | ||
[hre.ethers.utils.defaultAbiCoder.encode( | ||
['uint256', 'uint256', 'uint256'], | ||
[ | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_LP_REWARDS_AMOUNT_DIP24, | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_TRADER_REWARDS_AMOUNT_DIP24, | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_ALPHA_PARAMETER_DIP24, | ||
], | ||
)], | ||
[false], | ||
proposalIpfsHashHex, | ||
]; | ||
|
||
await waitForTx(await governor.create(...proposal)); | ||
|
||
return { | ||
proposalId, | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
tasks/deployment/update-merkle-distributor-rewards-parameters-dip24.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { types } from 'hardhat/config'; | ||
|
||
import mainnetAddresses from '../../src/deployed-addresses/mainnet.json'; | ||
import { hardhatTask } from '../../src/hre'; | ||
import { DIP_24_IPFS_HASH } from '../../src/lib/constants'; | ||
import { updateMerkleDistributorRewardsParametersDIP24Proposal } from '../../src/migrations/update-merkle-distributor-rewards-parameters-dip24'; | ||
|
||
hardhatTask('deploy:update-merkle-distributor-rewards-parameters-dip24-proposal', 'Create DIP24 proposal to update merkle distributor rewards parameters') | ||
.addParam('proposalIpfsHashHex', 'IPFS hash for the uploaded DIP describing the proposal', DIP_24_IPFS_HASH, types.string) | ||
.addParam('governorAddress', 'Address of the deployed DydxGovernor contract', mainnetAddresses.governor, types.string) | ||
.addParam('shortTimelockAddress', 'Address of the deployed short timelock Executor contract', mainnetAddresses.shortTimelock, types.string) | ||
.addParam('merkleDistributorAddress', 'Address of the deployed merkle distributor contract', mainnetAddresses.merkleDistributor, types.string) | ||
.setAction(async (args) => { | ||
await updateMerkleDistributorRewardsParametersDIP24Proposal(args); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
test/migrations/update-merkle-distributor-rewards-parameters-dip24.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import BNJS from 'bignumber.js'; | ||
import { BigNumberish } from 'ethers'; | ||
|
||
import config from '../../src/config'; | ||
import { getDeployConfig } from '../../src/deploy-config'; | ||
import { getDeployerSigner } from '../../src/deploy-config/get-deployer-address'; | ||
import { DIP_24_IPFS_HASH } from '../../src/lib/constants'; | ||
import { log } from '../../src/lib/logging'; | ||
import { waitForTx } from '../../src/lib/util'; | ||
import { impersonateAndFundAccount } from '../../src/migrations/helpers/impersonate-account'; | ||
import { updateMerkleDistributorRewardsParametersDIP24Proposal } from '../../src/migrations/update-merkle-distributor-rewards-parameters-dip24'; | ||
import { DydxGovernor__factory, DydxToken__factory, MerkleDistributorV1__factory } from '../../types'; | ||
import { advanceBlock, increaseTimeAndMine } from '../helpers/evm'; | ||
|
||
export async function updateMerkleDistributorRewardsParametersDIP24NoProposal({ | ||
merkleDistributorAddress, | ||
shortTimelockAddress, | ||
}: { | ||
merkleDistributorAddress: string, | ||
shortTimelockAddress: string, | ||
}) { | ||
const deployConfig = getDeployConfig(); | ||
const shortTimelockSigner = await impersonateAndFundAccount(shortTimelockAddress); | ||
const merkleDistributor = new MerkleDistributorV1__factory(shortTimelockSigner).attach(merkleDistributorAddress); | ||
|
||
await merkleDistributor.setRewardsParameters( | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_LP_REWARDS_AMOUNT_DIP24, | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_TRADER_REWARDS_AMOUNT_DIP24, | ||
deployConfig.UPDATE_MERKLE_DISTRIBUTOR_ALPHA_PARAMETER_DIP24, | ||
); | ||
} | ||
|
||
export async function updateMerkleDistributorRewardsParametersDIP24ViaProposal({ | ||
dydxTokenAddress, | ||
governorAddress, | ||
merkleDistributorAddress, | ||
shortTimelockAddress, | ||
}: { | ||
dydxTokenAddress: string, | ||
governorAddress: string, | ||
merkleDistributorAddress: string, | ||
shortTimelockAddress: string, | ||
}) { | ||
const deployConfig = getDeployConfig(); | ||
const deployer = await getDeployerSigner(); | ||
const dydxToken = new DydxToken__factory(deployer).attach(dydxTokenAddress); | ||
const governor = new DydxGovernor__factory(deployer).attach(governorAddress); | ||
|
||
// Pick a voter with enough tokens to meet the quorum requirement. | ||
const voterAddress = deployConfig.TOKEN_ALLOCATIONS.DYDX_TRADING.ADDRESS; | ||
const voter = await impersonateAndFundAccount(voterAddress); | ||
const voterBalance = await dydxToken.balanceOf(voterAddress); | ||
|
||
if (voterBalance.lt(new BNJS('2e25').toFixed())) { | ||
throw new Error('Not enough votes to pass the proposal.'); | ||
} | ||
|
||
// Vote on an existing proposal (can be used with mainnet forking). | ||
let proposalId: BigNumberish; | ||
|
||
if (config.UPDATE_MERKLE_DISTRIBUTOR_REWARDS_PARAMETERS_DIP24_PROPOSAL_ID !== null) { | ||
proposalId = config.UPDATE_MERKLE_DISTRIBUTOR_REWARDS_PARAMETERS_DIP24_PROPOSAL_ID; | ||
} else { | ||
log('Creating proposal'); | ||
({ proposalId } = await updateMerkleDistributorRewardsParametersDIP24Proposal({ | ||
proposalIpfsHashHex: DIP_24_IPFS_HASH, | ||
governorAddress, | ||
merkleDistributorAddress, | ||
shortTimelockAddress, | ||
signer: voter, | ||
})); | ||
|
||
log('Waiting for voting to begin'); | ||
for (let i = 0; i < deployConfig.VOTING_DELAY_BLOCKS + 1; i++) { | ||
if (i > 0 && i % 2000 === 0) { | ||
log('mining', i); | ||
} | ||
await advanceBlock(); | ||
} | ||
} | ||
|
||
let proposalState = await governor.getProposalState(proposalId); | ||
if (proposalState !== 2) { | ||
throw new Error('Expected proposal to be in the voting phase.'); | ||
} | ||
|
||
log('Submitting vote'); | ||
await waitForTx(await governor.connect(voter).submitVote(proposalId, true)); | ||
|
||
log('Waiting for voting to end'); | ||
let minedCount = 0; | ||
for (; ;) { | ||
for (let i = 0; i < 2000; i++) { | ||
await advanceBlock(); | ||
minedCount++; | ||
} | ||
log('mining', minedCount); | ||
proposalState = await governor.getProposalState(proposalId); | ||
if (proposalState !== 2) { | ||
break; | ||
} | ||
} | ||
|
||
if (proposalState !== 4) { | ||
throw new Error(`Expected proposal to have succeeded but state was ${proposalState}`); | ||
} | ||
|
||
log('Queueing the proposal'); | ||
await waitForTx(await governor.queue(proposalId)); | ||
const delaySeconds = deployConfig.SHORT_TIMELOCK_CONFIG.DELAY; | ||
await increaseTimeAndMine(delaySeconds); | ||
|
||
log('Executing the proposal'); | ||
await waitForTx(await governor.execute(proposalId)); | ||
log('Proposal executed'); | ||
|
||
log('\n=== UPDATE MERKLE DISTRIBUTOR REWARDS PARAMETERS DIP24 COMPLETE ===\n'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
test/misc/update-merkle-distributor-rewards-parameters-dip24.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect } from 'chai'; | ||
import { BigNumber } from 'ethers'; | ||
|
||
import { DIP_24_IPFS_HASH } from '../../src/lib/constants'; | ||
import { describeContract, TestContext } from '../helpers/describe-contract'; | ||
|
||
// LP rewards should be reduced by 50% (115068500000000000000000 => 575343000000000000000000) | ||
// Trader rewards should stay the same (1582192000000000000000000) | ||
// Alpha parameter show stay the same (0) | ||
|
||
function init() { } | ||
|
||
describeContract('update-merkle-distributor-rewards-parameters-dip24', init, (ctx: TestContext) => { | ||
|
||
it('Proposal IPFS hash is correct', async () => { | ||
const updateMerkleDistributorRewardsParametersDIP24Proposal = 14; | ||
const proposal = await ctx.governor.getProposalById(updateMerkleDistributorRewardsParametersDIP24Proposal); | ||
expect(proposal.ipfsHash).to.equal(DIP_24_IPFS_HASH); | ||
}); | ||
|
||
it('Merkle distributor reward parameters are updated for DIP 24', async () => { | ||
const [ | ||
lpRewardsAmount, | ||
traderRewardsAmount, | ||
alphaParameter, | ||
]: [ | ||
BigNumber, | ||
BigNumber, | ||
BigNumber, | ||
] = await ctx.merkleDistributor.getRewardsParameters(); | ||
|
||
|
||
expect(lpRewardsAmount.toString()).to.equal('575343000000000000000000'); | ||
expect(traderRewardsAmount.toString()).to.equal('1582192000000000000000000'); | ||
expect(alphaParameter).to.equal(0); | ||
}); | ||
}); |