Skip to content

Commit

Permalink
contracts: migration: Add claim test
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Apr 30, 2021
1 parent f69cc89 commit 1ce8164
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/contracts/hardhat.config.mainnet-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ require("@nomiclabs/hardhat-truffle5");
require("@nomiclabs/hardhat-ethers");
require("solidity-coverage");
require("hardhat-gas-reporter");
const accounts = require("./hardhatAccountsList2k.js");
const accountsList = accounts.accountsList

const fs = require('fs')
const alchemyUrl = () => {
Expand Down Expand Up @@ -55,13 +53,12 @@ module.exports = {
},
networks: {
hardhat: {
accounts: accountsList,
gas: 10000000, // tx gas limit
blockGasLimit: 12500000,
gasPrice: 20000000000,
blockGasLimit: 12500000,
gasPrice: process.env.GAS_PRICE ? parseInt(process.env.GAS_PRICE) : 20000000000,
forking: {
url: alchemyUrl(),
blockNumber: 12152522
blockNumber: process.env.BLOCK_NUMBER ? parseInt(process.env.BLOCK_NUMBER) : 12152522
}
}
},
Expand Down
89 changes: 89 additions & 0 deletions packages/contracts/migration/test/ClaimTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const { TestHelper: { dec, toBN, logBN } } = require("../../utils/testHelpers.js")
const deploymentHelper = require("../../utils/deploymentHelpers.js")

const { ORIGINAL_DEPLOYMENT_BLOCK_NUMBER, MIGRATION_BLOCK_NUMBER, lqtyAddresses } = require('../constants.js')
const { getUnipoolProgress, getCurveUnipoolProgress } = require('../query.js')

contract('Migration claim', async accounts => {
let merkleTree
let merkleDistributor
let lqtyTokenV2

before(async () => {
merkleTree = require('../output/merkleTree.json')
const migrationTimestamp = (await web3.eth.getBlock(MIGRATION_BLOCK_NUMBER)).timestamp

const coreContracts = await deploymentHelper.deployLiquityCore()

const originalDeploymentTime = (await web3.eth.getBlock(ORIGINAL_DEPLOYMENT_BLOCK_NUMBER)).timestamp
const LQTYContracts = await deploymentHelper.deployLQTYContractsHardhatV2(
originalDeploymentTime,
lqtyAddresses.bounty,
lqtyAddresses.multisig,
merkleTree
)
merkleDistributor = LQTYContracts.merkleDistributor
lqtyTokenV2 = LQTYContracts.lqtyToken

await deploymentHelper.connectLQTYContracts(LQTYContracts)
await deploymentHelper.connectCoreContracts(coreContracts, LQTYContracts)
await deploymentHelper.connectLQTYContractsToCoreV2(LQTYContracts, coreContracts, migrationTimestamp)

// transfer
const unipoolProgress = await getUnipoolProgress()
const curveUnipoolProgress = await getCurveUnipoolProgress()
const merkleDistributorAmount = curveUnipoolProgress.rewarded .add(unipoolProgress.rewarded)
logBN('merkleDistributorAmount', merkleDistributorAmount)
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [lqtyAddresses.bounty]
})
logBN('bounty bal', await lqtyTokenV2.balanceOf(lqtyAddresses.bounty))
await lqtyTokenV2.transfer(merkleDistributor.address, merkleDistributorAmount, { from: lqtyAddresses.bounty })
logBN('bounty bal', await lqtyTokenV2.balanceOf(lqtyAddresses.bounty))
await network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [lqtyAddresses.bounty]
})

const merkleBalance = await lqtyTokenV2.balanceOf(merkleDistributor.address)
logBN('merkleBalance', merkleBalance)
})

const claim = async (user) => {
// get claim
const claim = merkleTree.claims[web3.utils.toChecksumAddress(user)]
//logBN('amount', web3.utils.hexToNumberString(claim.amount))
// claim
await network.provider.request({
method: "hardhat_impersonateAccount",
params: [user]
})
await merkleDistributor.claim(claim.index, user, claim.amount, claim.proof, { from: user })
await network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [user]
})
assert.equal((await lqtyTokenV2.balanceOf(user)).toString(), web3.utils.hexToNumberString(claim.amount))

return toBN(web3.utils.hexToNumberString(claim.amount))
}

it('can claim', async () => {
const balances = require('../output/migrationBalances.json')
console.log(`Number of accounts: ${Object.keys(balances).length}`)
const balancesTotal = Object.keys(balances).reduce((t, user) => t.add(toBN('0x' + balances[user])), toBN(0))
logBN('Total account balances', balancesTotal)
logBN('Total Mekle tree ', toBN(merkleTree.tokenTotal))

let i = 0
let total = toBN(0)
for (const user in balances) {
//console.log(i++, user)
const amount = await claim(user)
total = total.add(amount)
//logBN('Claimed so far', total)
}
logBN('Total claimed', total)
})
})
45 changes: 45 additions & 0 deletions packages/contracts/utils/deploymentHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const LQTYStaking = artifacts.require("./LQTYStaking.sol")
const LQTYToken = artifacts.require("./LQTYToken.sol")
const LockupContractFactory = artifacts.require("./LockupContractFactory.sol")
const CommunityIssuance = artifacts.require("./CommunityIssuance.sol")
const LQTYTokenV2 = artifacts.require("LQTYTokenV2.sol")
const CommunityIssuanceV2 = artifacts.require("CommunityIssuanceV2.sol")
const MerkleDistributor = artifacts.require("MerkleDistributor.sol")

const Unipool = artifacts.require("./Unipool.sol")

Expand Down Expand Up @@ -187,6 +190,31 @@ class DeploymentHelper {
return LQTYContracts
}

static async deployLQTYContractsHardhatV2(originalDeploymentTime, bountyAddress, multisigAddress, merkleTree) {
const lqtyStaking = await LQTYStaking.new()
const lockupContractFactory = await LockupContractFactory.new()
const communityIssuance = await CommunityIssuanceV2.new(originalDeploymentTime)

// Deploy LQTY Token, passing Community Issuance and Factory addresses to the constructor
const lqtyToken = await LQTYTokenV2.new(
communityIssuance.address,
lqtyStaking.address,
lockupContractFactory.address,
bountyAddress,
multisigAddress
)

const merkleDistributor = await MerkleDistributor.new(lqtyToken.address, merkleTree.merkleRoot)

return {
lqtyStaking,
lockupContractFactory,
communityIssuance,
lqtyToken,
merkleDistributor
}
}

static async deployLQTYTesterContractsHardhat(bountyAddress, lpRewardsAddress, multisigAddress) {
const lqtyStaking = await LQTYStaking.new()
const lockupContractFactory = await LockupContractFactory.new()
Expand Down Expand Up @@ -423,6 +451,23 @@ class DeploymentHelper {
)
}

static async connectLQTYContractsToCoreV2(LQTYContracts, coreContracts, migrationTimestamp) {
await LQTYContracts.lqtyStaking.setAddresses(
LQTYContracts.lqtyToken.address,
coreContracts.lusdToken.address,
coreContracts.troveManager.address,
coreContracts.borrowerOperations.address,
coreContracts.activePool.address
)

await LQTYContracts.communityIssuance.setParams(
LQTYContracts.lqtyToken.address,
coreContracts.stabilityPool.address,
LQTYContracts.merkleDistributor.address,
migrationTimestamp
)
}

static async connectUnipool(uniPool, LQTYContracts, uniswapPairAddr, duration) {
await uniPool.setParams(LQTYContracts.lqtyToken.address, uniswapPairAddr, duration)
}
Expand Down

0 comments on commit 1ce8164

Please sign in to comment.