Skip to content

Commit

Permalink
Retroactive fixes (#124)
Browse files Browse the repository at this point in the history
* Retroactive scaffold for Curve pool

* WIP

* WIP

* WIP

* Remove progress.json

* Fix typo and ignore progress file

* Start handling rebases

* Start adding other sources

* Add more addresses and ABIs

* Remove uniswap

* Cleanup and improvements

* Remove yarn-error.log

* Sample run for OUSD/WOUSD

* Remove unused merge

* Remove debug log

* Cleanup and work on OGN/LM script

* Finish up outputs for OGN

* Add README

* Add announce block

* Update snapshot blocks

* Add generated data up to recent block

* Fix typo

* Cleanup undefined check

* Set OUSD redeploy block

* Comment formatting

* Add separate cumulative and balance rewards scoring functions

* Add OGN staking contract

* Implementation not proxy ABI for OGN staking

* Add OGN staking rewards and prettier

* Regenerate OUSD claim and add some validation

* Remove OGN progress file

* Fixes and add some validation to OGN tree

* Add eslint-config-prettier

* Fix JSON parse on staking ABI

* Add saves when querying complete

* Fix 3crv gauge event values

* Fix formatting

* Fix equivalence check in reward calculation

* Fixes for cumulative reward calculation

* Caching for historical ognStakingRewards queries, and fixes for bn actions

* Regenerate OUSD claims

* Remove debug

* Add commented debug

* Convert to 1e18

* Add excluded contracts to OUSD tree and run prettier

* Move ousd data output path to scripts dir

* Save temporary generated data

* Exclude some contracts

* Regenerate with excluded contracts

* Increase snapshot block

* Filter out OGN staking contract from OGN rewards

* Update data

* Fix output file paths

* Add optional claims file

* Rinkeby deploy

* LFS storage

* Fix amount sum and exclude 0 reward addresses

* Add some debugging statements

* Add staking rewards cache

* Prettier

* Separate OGN staking out, fix rounding errors and bug in summation

* Regenerate data, remove LFS since no longer needed

* Fresh Rinkeby deploy of contracts

* Remove gitattributes
  • Loading branch information
tomlinton authored Jul 4, 2022
1 parent dece3f7 commit 100da49
Show file tree
Hide file tree
Showing 30 changed files with 4,264,315 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions build/deployments/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,39 @@
},
"4": {
"ERC1967Proxy": [
"0x80914B31a29375f67a2C88a69ecb33FAE45DDC7E",
"0x3cfE54eB86220d92FF6dfD4f564FD7c4ffCd13F9",
"0xE9A5C62A39721741136f382FaC92Ca4B7fF282ec",
"0xD64730986C8639Eada7f9d5E4A279e4Ed5a496D8"
],
"Governance": [
"0x634113bE3D58876d09c1D261227FCD934aA732fB",
"0x09f28B46F3c3baFbEc833D09D1C46C653059DB0c",
"0x62C822B5254Af953eB49236e514A269BEEceFD77"
],
"MandatoryLockupDistributor": [
"0x56484d68046d4779604d001A7f5Fd0A823912024",
"0x19EA2B99Cc7a2a4bB5EeaC04a5Fb101A3886dF49"
],
"OgvStaking": [
"0x720A621914BB2e266A1cf191F588E197269ab9FC",
"0x50030D3bD1Ab51ec4a617387DC888671F7CAb25a"
],
"OptionalLockupDistributor": [
"0x2410E7dE5dcCD871619fB885ad705FA810d2fB89",
"0x80bCc28B56589C489c7B97F56EDBed02be27e306"
],
"OriginDollarGovernance": [
"0x9f2E530Dcd2143a8EC71618BAB2C28C18bc7983E",
"0xDCcfFe3357d11A21745135d0CE9b2b2b8c1a9a22",
"0x4c2cd9D017022029C58Bea6901337F2898601C3F"
],
"RewardsSource": [
"0x910A6FAee8d041c4a850a6039Ea3f48612380bEa",
"0x8069B8214b11764924c26363f5a2Bf592144ED78"
],
"Timelock": [
"0xd990de0C132c0a10522dFb811ff9B41F0C396dd6",
"0x29693dE2B62CB447AEe4342155370f43F49b3b9B",
"0xAcDaA603b1E8534AD3ED63De228d3F72D71c7914"
],
Expand Down
14 changes: 7 additions & 7 deletions client/networks/governance.rinkeby.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"OriginDollarGovernance": {
"address": "0x3cfE54eB86220d92FF6dfD4f564FD7c4ffCd13F9",
"address": "0x80914B31a29375f67a2C88a69ecb33FAE45DDC7E",
"abi": [
{
"inputs": [],
Expand Down Expand Up @@ -734,7 +734,7 @@
]
},
"RewardsSource": {
"address": "0x8069B8214b11764924c26363f5a2Bf592144ED78",
"address": "0x910A6FAee8d041c4a850a6039Ea3f48612380bEa",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -997,7 +997,7 @@
]
},
"OgvStaking": {
"address": "0x50030D3bD1Ab51ec4a617387DC888671F7CAb25a",
"address": "0x720A621914BB2e266A1cf191F588E197269ab9FC",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -1964,7 +1964,7 @@
]
},
"TimelockController": {
"address": "0x29693dE2B62CB447AEe4342155370f43F49b3b9B",
"address": "0xd990de0C132c0a10522dFb811ff9B41F0C396dd6",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -2830,7 +2830,7 @@
]
},
"Governance": {
"address": "0x09f28B46F3c3baFbEc833D09D1C46C653059DB0c",
"address": "0x634113bE3D58876d09c1D261227FCD934aA732fB",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -4294,7 +4294,7 @@
]
},
"MandatoryDistributor": {
"address": "0x19EA2B99Cc7a2a4bB5EeaC04a5Fb101A3886dF49",
"address": "0x56484d68046d4779604d001A7f5Fd0A823912024",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -4499,7 +4499,7 @@
]
},
"OptionalDistributor": {
"address": "0x80bCc28B56589C489c7B97F56EDBed02be27e306",
"address": "0x2410E7dE5dcCD871619fB885ad705FA810d2fB89",
"abi": [
{
"inputs": [
Expand Down
1 change: 0 additions & 1 deletion generate-merkle-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ for (const prefix of ['mandatory_lockup', 'optional_lockup']) {
`./scripts/${chainId}_data/${prefix}_claims.json`,
JSON.stringify(claims, null, 2), 'utf-8'
);

}
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts-upgradeable
1 change: 1 addition & 0 deletions retroactive/15036444-staking-rewards.json

Large diffs are not rendered by default.

90 changes: 70 additions & 20 deletions retroactive/src/ogn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ ethereumEvents.on(

const csv = Object.entries(claims).map(
([address, data]: [address: string, data: any]) => {
return `${address}, ${["ogn", "ousd3Crv", "ousd3CrvGauge", "convex"]
return `${address}, ${["ogn", "ognStaking", "ousd3Crv", "ousd3CrvGauge", "convex"]
.map((key) =>
data.split[key] === undefined ? 0 : data.split[key].toString()
)
Expand All @@ -209,9 +209,15 @@ ethereumEvents.on(
);

// Write a CSV for for easier verification
fs.writeFileSync("../scripts/1_data/optional_lockup_rewards.csv", csv.join("\n"));
fs.writeFileSync(
"../scripts/1_data/optional_lockup_rewards.csv",
csv.join("\n")
);
// Write merkle tree claims JSON structure
fs.writeFileSync("../scripts/1_data/optional_lockup_accounts.json", JSON.stringify(claims));
fs.writeFileSync(
"../scripts/1_data/optional_lockup_accounts.json",
JSON.stringify(claims)
);
}

done();
Expand All @@ -221,7 +227,19 @@ ethereumEvents.on(
const calculateRewards = async () => {
console.log("\n");
console.log("Calculating OGN rewards");
const ognRewards = balanceRewardScore(Object.fromEntries(Object.entries(ognHolders).filter(([k]) => k !== ognStakingContract.address)));
const ognRewards = balanceRewardScore(
Object.fromEntries(
Object.entries(ognHolders).filter(
([k]) => k !== ognStakingContract.address
)
)
);

const ognInstance = new ethers.Contract(
ognContract.address,
ognContract.abi,
provider
);

const ognStakingContractInstance = new ethers.Contract(
ognStakingContract.address,
Expand Down Expand Up @@ -256,14 +274,22 @@ const calculateRewards = async () => {
console.log("Calculating OUSD3CRV-f rewards");
const ousd3CrvRewards = cumulativeRewardScore(
// Exclude OUSD3CRV Gauge from rewards as it will have the most
Object.fromEntries(Object.entries(ousd3Crv).filter(([k]) => k !== ousd3CrvGaugeContract.address)),
Object.fromEntries(
Object.entries(ousd3Crv).filter(
([k]) => k !== ousd3CrvGaugeContract.address
)
),
SNAPSHOT_BLOCK,
ANNOUNCE_BLOCK
);
console.log("Calculating OUSD3CRV-f-gauge rewards");
const ousd3CrvGaugeRewards = cumulativeRewardScore(
// Exclude Convex finance voter proxy
Object.fromEntries(Object.entries(ousd3CrvGauge).filter(([k]) => k !== "0x989AEb4d175e16225E39E87d0D97A3360524AD80")),
Object.fromEntries(
Object.entries(ousd3CrvGauge).filter(
([k]) => k !== "0x989AEb4d175e16225E39E87d0D97A3360524AD80"
)
),
SNAPSHOT_BLOCK,
ANNOUNCE_BLOCK
);
Expand All @@ -289,7 +315,13 @@ const calculateRewards = async () => {
return total.add(amount);
}, bigNumberify(0));

const totalOgnScore = totalOgnHoldersScore.add(totalOgnStakersScore);
const totalOgnScore = totalOgnHoldersScore.add(
// Account for mistaken transfers to the staking contract by using
// balanceOf rather than summing all the stakes
await ognInstance.balanceOf(ognStakingContract.address, {
blockTag: SNAPSHOT_BLOCK,
})
);

const totalOusd3CrvRewardsScore = Object.values(
ousd3CrvRewards
Expand Down Expand Up @@ -318,6 +350,7 @@ const calculateRewards = async () => {
const addresses = [
...new Set(
Object.keys(ognRewards)
.concat(Object.keys(ognStakingRewards))
.concat(Object.keys(ousd3CrvRewards))
.concat(Object.keys(ousd3CrvGaugeRewards))
.concat(Object.keys(convexRewards))
Expand Down Expand Up @@ -355,19 +388,24 @@ const calculateRewards = async () => {
.div(totalLiquidityMiningScore)
: bigNumberify(0);

acc[address] = {
amount: ognReward
.add(ousd3CrvReward)
.add(ousd3CrvGaugeReward)
.add(convexReward),
split: {
ogn: ognReward,
ognStaking: ognStakingReward,
ousd3Crv: ousd3CrvReward,
ousd3CrvGauge: ousd3CrvGaugeReward,
convex: convexReward,
},
};
const amount = ognReward
.add(ognStakingReward)
.add(ousd3CrvReward)
.add(ousd3CrvGaugeReward)
.add(convexReward);

if (amount.gt(0)) {
acc[address] = {
amount,
split: {
ogn: ognReward,
ognStaking: ognStakingReward,
ousd3Crv: ousd3CrvReward,
ousd3CrvGauge: ousd3CrvGaugeReward,
convex: convexReward,
},
};
}
return acc;
}, {});

Expand Down Expand Up @@ -400,6 +438,18 @@ const calculateRewards = async () => {
bigNumberify(0)
);

console.log(`Total OGN score`, totalOgnScore.toString());
console.log("Total OGN excluding staked", totalOgnHoldersScore.toString());
console.log("Total OGN staked (sum)", totalOgnStakersScore.toString());
console.log(
"Total OGN staked (balanceOf)",
(
await ognInstance.balanceOf(ognStakingContract.address, {
blockTag: SNAPSHOT_BLOCK,
})
).toString()
);

console.log(
`OGN Holding rewards ${totalOgnHoldersScore.mul(100).div(totalOgnScore)}%`
);
Expand Down
10 changes: 8 additions & 2 deletions retroactive/src/ousd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,15 @@ ethereumEvents.on("block.confirmed", async (blockNumber, events, done) => {
);

// Write a CSV for for easier verification
fs.writeFileSync("../scripts/1_data/mandatory_lockup_rewards.csv", csv.join("\n"));
fs.writeFileSync(
"../scripts/1_data/mandatory_lockup_rewards.csv",
csv.join("\n")
);
// Write merkle tree claims JSON structure
fs.writeFileSync("../scripts/1_data/mandatory_lockup_accounts.json", JSON.stringify(claims));
fs.writeFileSync(
"../scripts/1_data/mandatory_lockup_accounts.json",
JSON.stringify(claims)
);
}

done();
Expand Down
6 changes: 0 additions & 6 deletions scripts/1_data/.gitattributes

This file was deleted.

4 changes: 1 addition & 3 deletions scripts/1_data/mandatory_lockup_accounts.json

Large diffs are not rendered by default.

Loading

0 comments on commit 100da49

Please sign in to comment.