Skip to content

Commit 9f93670

Browse files
committed
contracts: migration: Add claim test
1 parent e62c208 commit 9f93670

File tree

3 files changed

+137
-6
lines changed

3 files changed

+137
-6
lines changed

packages/contracts/hardhat.config.mainnet-fork.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ require("@nomiclabs/hardhat-truffle5");
22
require("@nomiclabs/hardhat-ethers");
33
require("solidity-coverage");
44
require("hardhat-gas-reporter");
5-
const accounts = require("./hardhatAccountsList2k.js");
6-
const accountsList = accounts.accountsList
75

86
const fs = require('fs')
97
const alchemyUrl = () => {
@@ -55,13 +53,12 @@ module.exports = {
5553
},
5654
networks: {
5755
hardhat: {
58-
accounts: accountsList,
5956
gas: 10000000, // tx gas limit
60-
blockGasLimit: 12500000,
61-
gasPrice: 20000000000,
57+
blockGasLimit: 12500000,
58+
gasPrice: process.env.GAS_PRICE ? parseInt(process.env.GAS_PRICE) : 20000000000,
6259
forking: {
6360
url: alchemyUrl(),
64-
blockNumber: 12152522
61+
blockNumber: process.env.BLOCK_NUMBER ? parseInt(process.env.BLOCK_NUMBER) : 12152522
6562
}
6663
}
6764
},
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
})

packages/contracts/utils/deploymentHelpers.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const LQTYStaking = artifacts.require("./LQTYStaking.sol")
1515
const LQTYToken = artifacts.require("./LQTYToken.sol")
1616
const LockupContractFactory = artifacts.require("./LockupContractFactory.sol")
1717
const CommunityIssuance = artifacts.require("./CommunityIssuance.sol")
18+
const LQTYTokenV2 = artifacts.require("LQTYTokenV2.sol")
19+
const CommunityIssuanceV2 = artifacts.require("CommunityIssuanceV2.sol")
20+
const MerkleDistributor = artifacts.require("MerkleDistributor.sol")
1821

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

@@ -187,6 +190,31 @@ class DeploymentHelper {
187190
return LQTYContracts
188191
}
189192

193+
static async deployLQTYContractsHardhatV2(originalDeploymentTime, bountyAddress, multisigAddress, merkleTree) {
194+
const lqtyStaking = await LQTYStaking.new()
195+
const lockupContractFactory = await LockupContractFactory.new()
196+
const communityIssuance = await CommunityIssuanceV2.new(originalDeploymentTime)
197+
198+
// Deploy LQTY Token, passing Community Issuance and Factory addresses to the constructor
199+
const lqtyToken = await LQTYTokenV2.new(
200+
communityIssuance.address,
201+
lqtyStaking.address,
202+
lockupContractFactory.address,
203+
bountyAddress,
204+
multisigAddress
205+
)
206+
207+
const merkleDistributor = await MerkleDistributor.new(lqtyToken.address, merkleTree.merkleRoot)
208+
209+
return {
210+
lqtyStaking,
211+
lockupContractFactory,
212+
communityIssuance,
213+
lqtyToken,
214+
merkleDistributor
215+
}
216+
}
217+
190218
static async deployLQTYTesterContractsHardhat(bountyAddress, lpRewardsAddress, multisigAddress) {
191219
const lqtyStaking = await LQTYStaking.new()
192220
const lockupContractFactory = await LockupContractFactory.new()
@@ -423,6 +451,23 @@ class DeploymentHelper {
423451
)
424452
}
425453

454+
static async connectLQTYContractsToCoreV2(LQTYContracts, coreContracts, migrationTimestamp) {
455+
await LQTYContracts.lqtyStaking.setAddresses(
456+
LQTYContracts.lqtyToken.address,
457+
coreContracts.lusdToken.address,
458+
coreContracts.troveManager.address,
459+
coreContracts.borrowerOperations.address,
460+
coreContracts.activePool.address
461+
)
462+
463+
await LQTYContracts.communityIssuance.setParams(
464+
LQTYContracts.lqtyToken.address,
465+
coreContracts.stabilityPool.address,
466+
LQTYContracts.merkleDistributor.address,
467+
migrationTimestamp
468+
)
469+
}
470+
426471
static async connectUnipool(uniPool, LQTYContracts, uniswapPairAddr, duration) {
427472
await uniPool.setParams(LQTYContracts.lqtyToken.address, uniswapPairAddr, duration)
428473
}

0 commit comments

Comments
 (0)