-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
voters fix for able poke properly #39
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import {ethers} from "hardhat"; | ||
import {Addresses} from "../addresses/addresses"; | ||
import {ControllerV2__factory, TetuVoter__factory} from "../../typechain"; | ||
import {RunHelper} from "../utils/RunHelper"; | ||
import {deployContract, txParams} from "../deploy/DeployContract"; | ||
import {Misc} from "../utils/Misc"; | ||
import {TimeUtils} from "../../test/TimeUtils"; | ||
|
||
// tslint:disable-next-line:no-var-requires | ||
const {request, gql} = require('graphql-request') | ||
|
||
// tslint:disable-next-line:no-var-requires | ||
const hre = require("hardhat"); | ||
|
||
async function main() { | ||
const [signer] = await ethers.getSigners(); | ||
const core = Addresses.getCore(); | ||
|
||
const gov = await Misc.impersonate('0xcc16d636dD05b52FF1D8B9CE09B09BC62b11412B') | ||
const logic = await deployContract(hre, signer, 'TetuVoter'); | ||
await ControllerV2__factory.connect(core.controller, gov).announceProxyUpgrade([core.tetuVoter], [logic.address]); | ||
await TimeUtils.advanceBlocksOnTs(60 * 60 * 24 * 2); | ||
await ControllerV2__factory.connect(core.controller, gov).upgradeProxy([core.tetuVoter]); | ||
|
||
const voter = TetuVoter__factory.connect(core.tetuVoter, signer); | ||
|
||
const data = await request('https://api.thegraph.com/subgraphs/name/tetu-io/tetu-v2', gql` | ||
query tetuVoterUserVotes { | ||
tetuVoterUserVotes { | ||
date | ||
percent | ||
weight | ||
user { | ||
veNFT { | ||
veNFTId | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const votes = data.tetuVoterUserVotes; | ||
|
||
const minDate = new Map<number, number>() | ||
for (const vote of votes) { | ||
// console.log(vote) | ||
const veId = vote.user.veNFT.veNFTId; | ||
console.log(new Date(vote.date * 1000), 'percent: ', vote.percent, 'weight: ', Number(vote.weight).toFixed(), 've: ', veId); | ||
const md = minDate.get(+veId) ?? Date.now(); | ||
if (md > +vote.date && +vote.weight > 10_000) { | ||
minDate.set(+veId, +vote.date); | ||
} | ||
} | ||
|
||
console.log('total ve voted', minDate.size); | ||
|
||
const vePokes: number[] = []; | ||
for (const [veId, md] of minDate.entries()) { | ||
console.log('ve: ', veId, 'min date: ', new Date(md * 1000)); | ||
const time = Date.now() - 60 * 60 * 24 * 21 * 1000; | ||
if (md * 1000 < time) { | ||
vePokes.push(veId); | ||
} | ||
} | ||
|
||
console.log('total ve pokes', vePokes.length); | ||
|
||
const skipVe = new Set<number>([]); | ||
|
||
for (const veId of vePokes) { | ||
console.log('poke ve: ', veId); | ||
if (skipVe.has(veId)) { | ||
continue; | ||
} | ||
const params = await txParams(hre, ethers.provider); | ||
await RunHelper.runAndWait(() => voter.poke(veId, {...params})); | ||
} | ||
|
||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import {PlatformVoter, PlatformVoter__factory, VeTetu__factory} from "../../typechain"; | ||
import {Misc} from "../utils/Misc"; | ||
import {Addresses} from "../addresses/addresses"; | ||
import {TimeUtils} from "../../test/TimeUtils"; | ||
import {BigNumber} from "ethers"; | ||
|
||
// tslint:disable-next-line:no-var-requires | ||
const {request, gql} = require('graphql-request') | ||
|
||
// tslint:disable-next-line:no-var-requires | ||
const hre = require("hardhat"); | ||
|
||
async function main() { | ||
const signer = await Misc.impersonate('0xcc16d636dD05b52FF1D8B9CE09B09BC62b11412B') | ||
const core = Addresses.getCore(); | ||
|
||
const voter = PlatformVoter__factory.connect(core.platformVoter, signer); | ||
|
||
const data = await request('https://api.thegraph.com/subgraphs/name/tetu-io/tetu-v2', gql` | ||
query { | ||
platformVoterEntities { | ||
votes(first: 1000) { | ||
desiredValue | ||
date | ||
newValue | ||
percent | ||
target | ||
voteType | ||
veWeightedValue | ||
vePower | ||
veNFT { | ||
veNFTId | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
const votes = data.platformVoterEntities[0].votes; | ||
|
||
// before total: 2 0x0000000000000000000000000000000000000000 22309135493267960537693747 2041902115655696862561336030000 | ||
// total: 2 0x0000000000000000000000000000000000000000 5113545723033076067993240 435594938160431577170782625000 | ||
const newTotalWeight = BigNumber.from('22309135493267960537693747').sub('5113545723033076067993240'); | ||
const newTotalValues = BigNumber.from('2041902115655696862561336030000').sub('435594938160431577170782625000'); | ||
console.log('set new values', newTotalWeight.toString(), newTotalValues.toString(), 'value: ', newTotalValues.div(newTotalWeight).toString()); | ||
// await voter.emergencyAdjustWeights(2, Misc.ZERO_ADDRESS, newTotalWeight, newTotalValues) | ||
|
||
// total: 3 0xa14dea6e48b3187c5e637c88b84d5dfc701edeb7 8330810085607459913799050 416540504280372995689952500000 | ||
// total: 3 0xa14dea6e48b3187c5e637c88b84d5dfc701edeb7 8330810085607459913799050 416540504280372995689952500000 | ||
// await voter.emergencyAdjustWeights(3, '0xa14dea6e48b3187c5e637c88b84d5dfc701edeb7', 0, 0); | ||
|
||
await TimeUtils.advanceBlocksOnTs(60 * 60 * 24 * 14); | ||
|
||
const targets = new Set<string>(); | ||
const veIds = new Set<number>(); | ||
|
||
for (const vote of votes) { | ||
const veId = vote.veNFT.veNFTId; | ||
// console.log(vote) | ||
// console.log(new Date(vote.date * 1000), 'value: ', vote.newValue, 'power: ', Number(vote.vePower).toFixed(), 've: ', veId); | ||
targets.add(vote.target); | ||
veIds.add(+veId); | ||
} | ||
|
||
console.log('---------------------------------------------'); | ||
|
||
for (const _type of [1, 2, 3]) { | ||
if (_type === 3) { | ||
for (const t of targets) { | ||
await checkW(_type, t, voter); | ||
} | ||
} else { | ||
await checkW(_type, Misc.ZERO_ADDRESS, voter); | ||
} | ||
} | ||
|
||
console.log('---------------------------------------------'); | ||
|
||
for (const vote of votes) { | ||
const veId = vote.veNFT.veNFTId; | ||
const ownerAdr = await VeTetu__factory.connect(core.ve, signer).ownerOf(veId); | ||
const owner = await Misc.impersonate(ownerAdr) | ||
await voter.connect(owner).reset(veId, [vote.voteType], [vote.target]); | ||
} | ||
|
||
for (const veId of veIds) { | ||
const voted = await voter.veVotesLength(veId); | ||
if (voted.gt(0)) { | ||
|
||
const vote = await voter.votes(veId, 0); | ||
console.log('voted, try to reset vote', veId, vote); | ||
|
||
const ownerAdr = await VeTetu__factory.connect(core.ve, signer).ownerOf(veId); | ||
const owner = await Misc.impersonate(ownerAdr) | ||
try { | ||
await voter.connect(owner).reset(veId, [vote._type], [vote.target]); | ||
} catch (e) { | ||
console.log('vote can not be removed!', veId, voted.toNumber()); | ||
|
||
await voter.emergencyResetVote(veId, 0, false); | ||
} | ||
} | ||
} | ||
|
||
for (const _type of [1, 2, 3]) { | ||
if (_type === 3) { | ||
for (const t of targets) { | ||
await checkW(_type, t, voter); | ||
} | ||
} else { | ||
await checkW(_type, Misc.ZERO_ADDRESS, voter); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
async function checkW(_type: number, target: string, voter: PlatformVoter) { | ||
const totalWeight = (await voter.attributeWeights(_type, target)).toString(); | ||
const totalValues = (await voter.attributeValues(_type, target)).toString(); | ||
console.log('total: ', _type, target, totalWeight, totalValues); | ||
|
||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no restrictions to call poke. Probably it worth to make a comment why the restrictions are not required.