Skip to content

Commit

Permalink
contracts: migration: Add Curve Gauge math and reward progress
Browse files Browse the repository at this point in the history
  • Loading branch information
bingen committed Apr 29, 2021
1 parent 590826c commit c6190c8
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 36 deletions.
3 changes: 3 additions & 0 deletions packages/contracts/migration/abi/LiquidityGaugeV2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"abi": [{"name":"Deposit","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"Withdraw","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"UpdateLiquidityLimit","inputs":[{"type":"address","name":"user","indexed":false},{"type":"uint256","name":"original_balance","indexed":false},{"type":"uint256","name":"original_supply","indexed":false},{"type":"uint256","name":"working_balance","indexed":false},{"type":"uint256","name":"working_supply","indexed":false}],"anonymous":false,"type":"event"},{"name":"CommitOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"name":"ApplyOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"name":"Transfer","inputs":[{"type":"address","name":"_from","indexed":true},{"type":"address","name":"_to","indexed":true},{"type":"uint256","name":"_value","indexed":false}],"anonymous":false,"type":"event"},{"name":"Approval","inputs":[{"type":"address","name":"_owner","indexed":true},{"type":"address","name":"_spender","indexed":true},{"type":"uint256","name":"_value","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address","name":"_lp_token"},{"type":"address","name":"_minter"},{"type":"address","name":"_admin"}],"stateMutability":"nonpayable","type":"constructor"},{"name":"decimals","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":261},{"name":"integrate_checkpoint","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1997},{"name":"user_checkpoint","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":2069525},{"name":"claimable_tokens","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":1989830},{"name":"claimable_reward","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_addr"},{"type":"address","name":"_token"}],"stateMutability":"view","type":"function","gas":1017930},{"name":"claim_rewards","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function"},{"name":"claim_rewards","outputs":[],"inputs":[{"type":"address","name":"_addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"claim_historic_rewards","outputs":[],"inputs":[{"type":"address[8]","name":"_reward_tokens"}],"stateMutability":"nonpayable","type":"function"},{"name":"claim_historic_rewards","outputs":[],"inputs":[{"type":"address[8]","name":"_reward_tokens"},{"type":"address","name":"_addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"kick","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":2074713},{"name":"set_approve_deposit","outputs":[],"inputs":[{"type":"address","name":"addr"},{"type":"bool","name":"can_deposit"}],"stateMutability":"nonpayable","type":"function","gas":35981},{"name":"deposit","outputs":[],"inputs":[{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function"},{"name":"deposit","outputs":[],"inputs":[{"type":"uint256","name":"_value"},{"type":"address","name":"_addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"withdraw","outputs":[],"inputs":[{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":3141937},{"name":"allowance","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_owner"},{"type":"address","name":"_spender"}],"stateMutability":"view","type":"function","gas":1911},{"name":"transfer","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":12160044},{"name":"transferFrom","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_from"},{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":12196694},{"name":"approve","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_spender"},{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function","gas":38244},{"name":"increaseAllowance","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_spender"},{"type":"uint256","name":"_added_value"}],"stateMutability":"nonpayable","type":"function","gas":39488},{"name":"decreaseAllowance","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"_spender"},{"type":"uint256","name":"_subtracted_value"}],"stateMutability":"nonpayable","type":"function","gas":39512},{"name":"set_rewards","outputs":[],"inputs":[{"type":"address","name":"_reward_contract"},{"type":"bytes32","name":"_sigs"},{"type":"address[8]","name":"_reward_tokens"}],"stateMutability":"nonpayable","type":"function","gas":2304194},{"name":"set_killed","outputs":[],"inputs":[{"type":"bool","name":"_is_killed"}],"stateMutability":"nonpayable","type":"function","gas":36878},{"name":"commit_transfer_ownership","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":38258},{"name":"accept_transfer_ownership","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":38203},{"name":"minter","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1811},{"name":"crv_token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1841},{"name":"lp_token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1871},{"name":"controller","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1901},{"name":"voting_escrow","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1931},{"name":"future_epoch_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1961},{"name":"balanceOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2206},{"name":"totalSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2021},{"name":"name","outputs":[{"type":"string","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":8453},{"name":"symbol","outputs":[{"type":"string","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":7506},{"name":"approved_to_deposit","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"arg0"},{"type":"address","name":"arg1"}],"stateMutability":"view","type":"function","gas":2541},{"name":"working_balances","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2356},{"name":"working_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2171},{"name":"period","outputs":[{"type":"int128","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2201},{"name":"period_timestamp","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256","name":"arg0"}],"stateMutability":"view","type":"function","gas":2340},{"name":"integrate_inv_supply","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256","name":"arg0"}],"stateMutability":"view","type":"function","gas":2370},{"name":"integrate_inv_supply_of","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2506},{"name":"integrate_checkpoint_of","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2536},{"name":"integrate_fraction","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2566},{"name":"inflation_rate","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2381},{"name":"reward_contract","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2411},{"name":"reward_tokens","outputs":[{"type":"address","name":""}],"inputs":[{"type":"uint256","name":"arg0"}],"stateMutability":"view","type":"function","gas":2550},{"name":"reward_integral","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2686},{"name":"reward_integral_for","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"},{"type":"address","name":"arg1"}],"stateMutability":"view","type":"function","gas":2931},{"name":"admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2531},{"name":"future_admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2561},{"name":"is_killed","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2591}]
}
31 changes: 29 additions & 2 deletions packages/contracts/migration/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@ const PAGINATION = 1000
// https://etherscan.io/tx/0x1aa0a3599fdb5dc33bfe8ee167c78895ca996b9df2f18fecb1235dc34795c46c
// Total issued:
const CI_ALREADY_ISSUED = '1276210897336891840000000'
const BLOCK_NUMBER = 12317707
const MIGRATION_BLOCK_NUMBER = 12317707
// Set Params
// https://etherscan.io/tx/0x8e6670c95a9dc30387440101c595df258149eb9bc6515a880f250dc6b8ce1e86
// const UNIPOOL_BLOCK_NUMBER = 12178669
// First stake, then withdraw, then stake again, periodFinish is updated:
// https://etherscan.io/tx/0x5b03110b1fdc60a5c1f515c30f0304379bed8aeaa1f64ac9da5e6f02ba9df006
// https://etherscan.io/tx/0xb588573670438567a9cc6c8d0784972658dd5da2a8e270d0c310440a6b65a5f6
// https://etherscan.io/tx/0x6b8e1d56f45c86e238787fd27cd131d6dd07ec7335e75886121cc344608f1c8d
const UNIPOOL_BLOCK_NUMBERS = {
FIRST_STAKE: 12178723,
FIRST_WITHDRAW: 12179160,
SECOND_STAKE: 12179571,
}
const UNIPOOL_ALLOCATION = '1' + '3'.repeat(24) // 1.3M
const UNIPOOL_PERIOD = 60 * 60 * 24 * 7 * 6 // 6 weeks
// https://etherscan.io/tx/0x0c3a6358bfd72dd1dac9490a2b5a06cf909597d52ef941590d5e53970d1777f3
const CURVE_UNIPOOL_BLOCK_NUMBER = 12283568
const CURVE_UNIPOOL_ALLOCATION = '180' + '0'.repeat(21) // 180k
const CURVE_UNIPOOL_PERIOD = 60 * 60 * 24 * 7 * 6 // 6 weeks

const BASE_FILE_NAME = './output/migrationBalances'
const OUTPUT_FILE = `${BASE_FILE_NAME}.json`
const OUTPUT_FILE_FULL = `${BASE_FILE_NAME}Full.json`
Expand All @@ -15,6 +34,8 @@ const { addresses: lqtyAddresses } = require('@liquity/lib-ethers/deployments/ma
lqtyAddresses.multisig = '0xb8a9faDA75c6d891fB77a7988Ff9BaD9e485Ca1C'
lqtyAddresses.uniswapLqtyPool = '0xB13201b48B1E61593DF055576964D0b3AaB66eA3'
lqtyAddresses.curveUnipool = '0xEb31DA939878d1d780fDBCc244531c0FB80A2cF3'
lqtyAddresses.curveGauge = '0x9B8519A9a00100720CCdC8a120fBeD319cA47a14'

//console.log(lqtyAddresses)
const LOCKUP_CONTRACTS = [
'0x241aD9DfC7466C5299d622DF7664B71AB60Fe8D6',
Expand Down Expand Up @@ -61,7 +82,7 @@ const BOUNTY_ADDRESS = "0xF06016D822943C42e3Cb7FC3a6A3B1889C1045f8"
module.exports = {
GRAPH_URL,
PAGINATION,
BLOCK_NUMBER,
MIGRATION_BLOCK_NUMBER,
OUTPUT_FILE,
OUTPUT_FILE_FULL,
OUTPUT_FILE_LQTY,
Expand All @@ -70,4 +91,10 @@ module.exports = {
LOCKUP_CONTRACTS,
BOUNTY_ADDRESS,
CI_ALREADY_ISSUED,
UNIPOOL_BLOCK_NUMBERS,
UNIPOOL_ALLOCATION,
UNIPOOL_PERIOD,
CURVE_UNIPOOL_BLOCK_NUMBER,
CURVE_UNIPOOL_ALLOCATION,
CURVE_UNIPOOL_PERIOD,
}
79 changes: 64 additions & 15 deletions packages/contracts/migration/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const {
CI_ALREADY_ISSUED,
} = require('./constants')

const { queryBalances, getLqtyBalances, getLockupBalances } = require('./query')
const {
queryBalances,
getLqtyBalances,
getLockupBalances,
getUnipoolProgress,
getCurveUnipoolProgress,
} = require('./query')

const {
toBigNum,
Expand Down Expand Up @@ -42,7 +48,7 @@ const {
if (!fs.existsSync(outputFile)) {
const usersOutput = {}
Object.keys(users).map(user => (usersOutput[user] = users[user].total.toString()))
fs.writeFileSync(OUTPUT_FILE, JSON.stringify(usersOutput))
fs.writeFileSync(outputFile, JSON.stringify(usersOutput))
}

//logUsers(users)
Expand All @@ -59,12 +65,21 @@ const {
// .add(aggregates.)
)
*/
logBN('Users Total', usersTotal)

// Rewards progress
const unipoolProgress = await getUnipoolProgress()
logBN('rewarded', unipoolProgress.rewarded)
logBN('remaining', unipoolProgress.remaining)
const curveUnipoolProgress = await getCurveUnipoolProgress()
logBN('rewarded', curveUnipoolProgress.rewarded)
logBN('remaining', curveUnipoolProgress.remaining)

logBN('Users Total', usersTotal)
// Merkle distributor
const merkleDistributorAmount =
toBigNum(dec(2, 24)) // 2M bounty
.add(toBigNum(dec(1, 24, '3'))) // 1.3M rewards
.sub(curveUnipoolProgress.remaining)
.add(unipoolProgress.rewarded)
.add(toBigNum(CI_ALREADY_ISSUED))
logBN('Merkle distr. bal.', merkleDistributorAmount)

Expand All @@ -86,14 +101,39 @@ const {
fs.writeFileSync(outputFileLqty, JSON.stringify(lqtyBalancesString))
}

// non-distributed rewards
logBN(
'Users Total + rewards',
usersTotal
.add(lqtyBalances.curveUnipool)
.add(lqtyBalances.unipool)
.sub(aggregates.unipoolEarned)
// TODO remove
// Uniswap Unipool
logBN('p ', lqtyBalances.unipool)
logBN('e ', aggregates.unipoolEarned)
logBN('rem', unipoolProgress.remaining)
logBN('rew', unipoolProgress.rewarded)
logBN('p-e', lqtyBalances.unipool.sub(aggregates.unipoolEarned))
/*
assert(
lqtyBalances.unipool.sub(aggregates.unipoolEarned).toString()
===
unipoolProgress.remaining,
'Remaining Unipool balance doesn’t match'
)
*/
logBN('r+r', curveUnipoolProgress.remaining.add(curveUnipoolProgress.rewarded))

// Curve Unipool
logBN('p ', lqtyBalances.curveUnipool)
logBN('e ', aggregates.curveUnipoolEarned)
logBN('rem', curveUnipoolProgress.remaining)
logBN('rew', curveUnipoolProgress.rewarded)
logBN('p-e', lqtyBalances.curveUnipool.add(lqtyBalances.curveGauge).sub(aggregates.curveUnipoolEarned))
/*
assert(
lqtyBalances.curveUnipool.add(lqtyBalances.curveGauge).sub(aggregates.curveUnipoolEarned).toString()
===
curveUnipoolProgress.remaining,
'Remaining CurveUnipool balance doesn’t match'
)
*/
logBN('r+r', curveUnipoolProgress.remaining.add(curveUnipoolProgress.rewarded))
// TODO - end

logBalances(lqtyBalances, 'LQTY')
logBN('CI already issued', CI_ALREADY_ISSUED)
Expand All @@ -118,12 +158,19 @@ const {
console.log('\n---\n')

// LQTY staking
assert(lqtyBalances.lqtyStaking.toString() === aggregates.stake.toString())
assert(lqtyBalances.lqtyStaking.toString() === aggregates.stake.toString(), 'LQTY staking balance doesn’t match')
// Multisig + lockups
logBN('ms + lockups', lqtyBalances.multisig.add(lockupTotal))
logBN('ms exp', toBigNum('64' + '6'.repeat(23) + '7'))
// TODO
//assert(lqtyBalances.multisig.add(lockupTotal).toString() === '64' + '6'.repeat(23) + '7') // 64.6...M
/*
assert(
lqtyBalances.multisig.add(lockupTotal).toString()
===
'64' + '6'.repeat(23) + '7', // 64.6...M
'Lockup contract balances don’t match'
)
*/
// Community issuance
const initialCI = toBigNum('32' + '0'.repeat(24)) // 32M
logBN('CI', lqtyBalances.communityIssuance.add(toBigNum(CI_ALREADY_ISSUED)))
Expand All @@ -138,7 +185,8 @@ const {
initialCI
.add(aggregates.depositorLQTYGain)
.add(aggregates.frontEndLQTYGain)
.toString()
.toString(),
'Community Issuance balance doesn’t match'
)
*/
// Merkle distributor
Expand All @@ -149,6 +197,7 @@ const {
.add(lqtyBalances.curveUnipool)
.add(lqtyBalances.unipool)
.sub(aggregates.unipoolEarned)
.toString()
.toString(),
'Merkle distributon balance doesn’t match'
)
})();
2 changes: 1 addition & 1 deletion packages/contracts/migration/output/migrationBalances.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit c6190c8

Please sign in to comment.