|
| 1 | +const { TestHelper: { dec, toBN, logBN } } = require("../../utils/testHelpers.js") |
| 2 | +const deploymentHelper = require("../../utils/deploymentHelpers.js") |
| 3 | + |
| 4 | +const { ORIGINAL_DEPLOYMENT_BLOCK_NUMBER, MIGRATION_BLOCK_NUMBER, lqtyAddresses } = require('../constants.js') |
| 5 | +const { getUnipoolProgress, getCurveUnipoolProgress } = require('../query.js') |
| 6 | + |
| 7 | +contract('Migration claim', async accounts => { |
| 8 | + let merkleTree |
| 9 | + let merkleDistributor |
| 10 | + let lqtyTokenV2 |
| 11 | + |
| 12 | + before(async () => { |
| 13 | + merkleTree = require('../output/merkleTree.json') |
| 14 | + const migrationTimestamp = (await web3.eth.getBlock(MIGRATION_BLOCK_NUMBER)).timestamp |
| 15 | + |
| 16 | + const coreContracts = await deploymentHelper.deployLiquityCore() |
| 17 | + |
| 18 | + const originalDeploymentTime = (await web3.eth.getBlock(ORIGINAL_DEPLOYMENT_BLOCK_NUMBER)).timestamp |
| 19 | + const LQTYContracts = await deploymentHelper.deployLQTYContractsHardhatV2( |
| 20 | + originalDeploymentTime, |
| 21 | + lqtyAddresses.bounty, |
| 22 | + lqtyAddresses.multisig, |
| 23 | + merkleTree |
| 24 | + ) |
| 25 | + merkleDistributor = LQTYContracts.merkleDistributor |
| 26 | + lqtyTokenV2 = LQTYContracts.lqtyToken |
| 27 | + |
| 28 | + await deploymentHelper.connectLQTYContracts(LQTYContracts) |
| 29 | + await deploymentHelper.connectCoreContracts(coreContracts, LQTYContracts) |
| 30 | + await deploymentHelper.connectLQTYContractsToCoreV2(LQTYContracts, coreContracts, migrationTimestamp) |
| 31 | + |
| 32 | + // transfer |
| 33 | + const unipoolProgress = await getUnipoolProgress() |
| 34 | + const curveUnipoolProgress = await getCurveUnipoolProgress() |
| 35 | + const merkleDistributorAmount = curveUnipoolProgress.rewarded .add(unipoolProgress.rewarded) |
| 36 | + logBN('merkleDistributorAmount', merkleDistributorAmount) |
| 37 | + await network.provider.request({ |
| 38 | + method: "hardhat_impersonateAccount", |
| 39 | + params: [lqtyAddresses.bounty] |
| 40 | + }) |
| 41 | + logBN('bounty bal', await lqtyTokenV2.balanceOf(lqtyAddresses.bounty)) |
| 42 | + await lqtyTokenV2.transfer(merkleDistributor.address, merkleDistributorAmount, { from: lqtyAddresses.bounty }) |
| 43 | + logBN('bounty bal', await lqtyTokenV2.balanceOf(lqtyAddresses.bounty)) |
| 44 | + await network.provider.request({ |
| 45 | + method: "hardhat_stopImpersonatingAccount", |
| 46 | + params: [lqtyAddresses.bounty] |
| 47 | + }) |
| 48 | + |
| 49 | + const merkleBalance = await lqtyTokenV2.balanceOf(merkleDistributor.address) |
| 50 | + logBN('merkleBalance', merkleBalance) |
| 51 | + }) |
| 52 | + |
| 53 | + const claim = async (user) => { |
| 54 | + // get claim |
| 55 | + const claim = merkleTree.claims[web3.utils.toChecksumAddress(user)] |
| 56 | + //logBN('amount', web3.utils.hexToNumberString(claim.amount)) |
| 57 | + // claim |
| 58 | + await network.provider.request({ |
| 59 | + method: "hardhat_impersonateAccount", |
| 60 | + params: [user] |
| 61 | + }) |
| 62 | + await merkleDistributor.claim(claim.index, user, claim.amount, claim.proof, { from: user }) |
| 63 | + await network.provider.request({ |
| 64 | + method: "hardhat_stopImpersonatingAccount", |
| 65 | + params: [user] |
| 66 | + }) |
| 67 | + assert.equal((await lqtyTokenV2.balanceOf(user)).toString(), web3.utils.hexToNumberString(claim.amount)) |
| 68 | + |
| 69 | + return toBN(web3.utils.hexToNumberString(claim.amount)) |
| 70 | + } |
| 71 | + |
| 72 | + it('can claim', async () => { |
| 73 | + const balances = require('../output/migrationBalances.json') |
| 74 | + console.log(`Number of accounts: ${Object.keys(balances).length}`) |
| 75 | + const balancesTotal = Object.keys(balances).reduce((t, user) => t.add(toBN('0x' + balances[user])), toBN(0)) |
| 76 | + logBN('Total account balances', balancesTotal) |
| 77 | + logBN('Total Mekle tree ', toBN(merkleTree.tokenTotal)) |
| 78 | + |
| 79 | + let i = 0 |
| 80 | + let total = toBN(0) |
| 81 | + for (const user in balances) { |
| 82 | + //console.log(i++, user) |
| 83 | + const amount = await claim(user) |
| 84 | + total = total.add(amount) |
| 85 | + //logBN('Claimed so far', total) |
| 86 | + } |
| 87 | + logBN('Total claimed', total) |
| 88 | + }) |
| 89 | +}) |
0 commit comments